-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84f607e
commit 5cde21d
Showing
4 changed files
with
147 additions
and
1 deletion.
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
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,143 @@ | ||
const EFFECTS_DATA = { | ||
chrome: | ||
{ | ||
filter: 'grayscale', | ||
values: { | ||
range: { | ||
min: 0, | ||
max: 1 | ||
}, | ||
start: 1, | ||
step: 0.1, | ||
}, | ||
unit: '' | ||
}, | ||
|
||
sepia: | ||
{ | ||
filter: 'sepia', | ||
values: { | ||
range: { | ||
min: 0, | ||
max: 1 | ||
}, | ||
start: 1, | ||
step: 0.1, | ||
}, | ||
unit: '' | ||
}, | ||
|
||
marvin: | ||
{ | ||
filter: 'invert', | ||
values: { | ||
range: { | ||
min: 0, | ||
max: 100 | ||
}, | ||
start: 100, | ||
step: 1, | ||
}, | ||
unit: '%' | ||
}, | ||
|
||
phobos: | ||
{ | ||
filter: 'blur', | ||
values: { | ||
range: { | ||
min: 0, | ||
max: 3 | ||
}, | ||
start: 3, | ||
step: 0.1, | ||
}, | ||
unit: 'px' | ||
}, | ||
|
||
heat: | ||
{ | ||
filter: 'brightness', | ||
values: { | ||
range: { | ||
min: 0, | ||
max: 3 | ||
}, | ||
start: 3, | ||
step: 0.1, | ||
}, | ||
unit: '' | ||
}, | ||
|
||
none: | ||
{ | ||
filter: '', | ||
values: { | ||
range: { | ||
min: 0, | ||
max: 1 | ||
}, | ||
start: 1, | ||
step: 0.1, | ||
}, | ||
unit: '' | ||
} | ||
}; | ||
|
||
const effectLevel = document.querySelector('.img-upload__effect-level'); | ||
const effectLevelValue = effectLevel.querySelector('.effect-level__value'); | ||
const slider = effectLevel.querySelector('.effect-level__slider'); | ||
const imagePreview = document.querySelector('.img-upload__preview img'); | ||
const effectsContainer = document.querySelector('.effects__list'); | ||
|
||
const INITIAL_EFFECT = EFFECTS_DATA.none; | ||
|
||
noUiSlider.create(slider, { | ||
range: { | ||
min: 0, | ||
max: 100 | ||
}, | ||
start: 100, | ||
step: 1, | ||
connect: 'lower' | ||
}); | ||
|
||
effectLevel.classList.add('hidden'); | ||
|
||
const updateSlider = (filterName) => { | ||
slider.noUiSlider.on('update', () => { | ||
const filter = EFFECTS_DATA[filterName].filter; | ||
const unit = EFFECTS_DATA[filterName].unit; | ||
|
||
if (filterName !== INITIAL_EFFECT) { | ||
const value = slider.noUiSlider.get(); | ||
imagePreview.style.filter = `${filter}(${value}${unit})`; | ||
effectLevelValue.value = value; | ||
} | ||
}); | ||
}; | ||
|
||
const onEffectsContainerChange = (evt) => { | ||
const targetElement = evt.target.value; | ||
effectLevel.classList.add('hidden'); | ||
imagePreview.className = ''; | ||
imagePreview.style.filter = ''; | ||
|
||
if (targetElement !== INITIAL_EFFECT) { | ||
effectLevel.classList.remove('hidden'); | ||
imagePreview.classList.add(`effects__preview--${targetElement}`); | ||
slider.noUiSlider.updateOptions(EFFECTS_DATA[targetElement].values); | ||
updateSlider(targetElement); | ||
} | ||
}; | ||
|
||
const resetEffects = () => { | ||
effectsContainer.removeEventListener('click', onEffectsContainerChange); | ||
imagePreview.style.filter = ''; | ||
imagePreview.className = ''; | ||
slider.noUiSlider.updateOptions(INITIAL_EFFECT); | ||
}; | ||
|
||
effectsContainer.addEventListener('change', onEffectsContainerChange); | ||
|
||
export { resetEffects }; |
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