-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from brazilets/module11-task1
Надо подкачаться
- Loading branch information
Showing
5 changed files
with
205 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const API_URL_BASE = 'https://31.javascript.htmlacademy.pro/kekstagram/data'; | ||
const API_URL_SEND = 'https://31.javascript.htmlacademy.pro/kekstagram/'; | ||
|
||
const getData = () => | ||
fetch(API_URL_BASE) | ||
.then((response) => { | ||
if (response.ok) { | ||
return response.json(); | ||
} else { | ||
throw new Error('Не удалось загрузить данные'); | ||
} | ||
}); | ||
|
||
const sendData = (data) => | ||
fetch(API_URL_SEND, { | ||
method: 'POST', | ||
body: data, | ||
}) | ||
.then((response) => { | ||
if (response.ok) { | ||
return response.json(); | ||
} else { | ||
throw new Error('Не удалось отправить данные'); | ||
} | ||
}); | ||
|
||
export { getData, sendData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { renderUsersPictures } from './thumbnails.js'; | ||
import { fetchDataAndRender } from './thumbnails.js'; | ||
import './api.js'; | ||
import './uploadForm.js'; | ||
import './slider.js'; | ||
|
||
renderUsersPictures(); | ||
fetchDataAndRender(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { imgPreview } from './uploadForm.js'; | ||
|
||
const effectLevelSlider = document.querySelector('.img-upload__effect-level'); | ||
const slider = document.querySelector('.effect-level__slider'); | ||
if (slider) { | ||
noUiSlider.create(slider, { | ||
start: [100], | ||
step: 0.1, | ||
range: { | ||
'min': [0], | ||
'max': [100] | ||
}, | ||
format: { | ||
to: function (value) { | ||
return Number(value).toFixed(1); | ||
}, | ||
from: function (value) { | ||
return Number(value); | ||
} | ||
} | ||
}); | ||
|
||
slider.noUiSlider.on('update', (values, handle) => { | ||
const value = Number(values[handle]); | ||
const effectLevelValue = document.querySelector('.effect-level__value'); | ||
effectLevelValue.value = value.toFixed(1); | ||
|
||
const currentEffect = document.querySelector('input[name="effect"]:checked').value; | ||
|
||
switch (currentEffect) { | ||
case 'chrome': | ||
imgPreview.style.filter = `grayscale(${(value / 100).toFixed(1)})`; | ||
break; | ||
case 'sepia': | ||
imgPreview.style.filter = `sepia(${(value / 100).toFixed(1)})`; | ||
break; | ||
case 'marvin': | ||
imgPreview.style.filter = `invert(${value.toFixed(1)}%)`; | ||
break; | ||
case 'phobos': | ||
imgPreview.style.filter = `blur(${(value * 0.03).toFixed(1)}px)`; | ||
break; | ||
case 'heat': | ||
imgPreview.style.filter = `brightness(${(1 + (value * 0.02)).toFixed(1)})`; | ||
break; | ||
default: | ||
imgPreview.style.filter = 'none'; | ||
} | ||
}); | ||
|
||
document.querySelector('.effects__list').addEventListener('change', (evt) => { | ||
if (evt.target.value === 'none') { | ||
effectLevelSlider.classList.add('hidden'); | ||
} else { | ||
effectLevelSlider.classList.remove('hidden'); | ||
slider.noUiSlider.set(100); | ||
} | ||
}); | ||
|
||
window.addEventListener('load', () => { | ||
const currentEffect = document.querySelector('input[name="effect"]:checked').value; | ||
if (currentEffect === 'none') { | ||
effectLevelSlider.classList.add('hidden'); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters