-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Помощь друга #10
Merged
keksobot
merged 11 commits into
htmlacademy-univer-javascript-1:master
from
PavelUd:module9-task2
Dec 17, 2023
Merged
Помощь друга #10
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f68fbfa
add image scale
PavelUd 741c780
add image-effects
PavelUd 8546ffd
merge
PavelUd bb2a61c
update
PavelUd da4422c
Merge branch 'master' into module9-task2
PavelUd c99c9e6
FIX
PavelUd 5736a46
fix
PavelUd f798263
опаньки
PavelUd 52b1c3e
3000 переименование одной и той же переменной
PavelUd 70b4e1d
пон
PavelUd 9345326
gg
PavelUd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,71 @@ | ||
const Effect = { | ||
NONE: { name: 'none', filter: '', unit: '', | ||
options: {range: {min: 0, max: 100}, step: 1, start: 100}, | ||
}, | ||
CHROME: {name: 'chrome', filter: 'grayscale', unit: '%', | ||
options: { range: {min: 0, max: 100}, step: 1, start: 100}, | ||
}, | ||
SEPIA: { name: 'sepia', filter: 'sepia', unit: '%', | ||
options: { range: {min: 0, max: 100}, step: 1, start: 100}, | ||
}, | ||
MARVIN: { name: 'marvin', filter: 'invert', unit: '%', | ||
options: {range: {min: 0, max: 100}, step: 1, start: 100}, | ||
}, | ||
PHOBOS: {name: 'phobos', filter: 'blur', unit: 'px', | ||
options: {range: {min: 1, max: 10}, step: 0.1, start: 10}, | ||
}, | ||
HEAT: {name: 'heat', filter: 'brightness', unit: '', | ||
options: {range: {min: 1, max: 4}, step: 0.1, start: 4}, | ||
} | ||
}; | ||
const DefaultSliderParam = { | ||
range: {min: 0, max: 100}, start: 100, step: 0.1 | ||
}; | ||
|
||
const DEFAULT_FILTER = 'NONE'; | ||
const image = document.querySelector('.img-upload__preview').querySelector('img'); | ||
const sliderValue = document.querySelector('.effect-level__value'); | ||
const sliderWrapper = document.querySelector('.img-upload__effect-level'); | ||
const slider = document.querySelector('.effect-level__slider'); | ||
|
||
|
||
export const createEffectSlider = () =>{ | ||
sliderWrapper.classList.add('hidden'); | ||
noUiSlider.create(slider, DefaultSliderParam); | ||
}; | ||
|
||
export const resetFilters = () => { | ||
image.style.filter = Effect[DEFAULT_FILTER].name; | ||
sliderWrapper.classList.add('hidden'); | ||
}; | ||
|
||
const updateImagePreview = (effect) => { | ||
image.removeAttribute('class'); | ||
image.classList.add(`effects__preview--${effect}`); | ||
|
||
slider.noUiSlider.updateOptions(Effect[effect].options); | ||
slider.noUiSlider.on('update', () => { | ||
sliderValue.value = slider.noUiSlider.get(); | ||
image.style.filter = `${Effect[effect].filter}(${sliderValue.value}${Effect[effect].unit})`; | ||
}); | ||
}; | ||
|
||
const updateSliderOptions = (effect) => { | ||
slider.noUiSlider.updateOptions(Effect[effect].options); | ||
}; | ||
|
||
const showFilterPreview = (effect) => { | ||
sliderWrapper.classList.remove('hidden'); | ||
updateImagePreview(effect); | ||
updateSliderOptions(effect); | ||
}; | ||
|
||
export const onEffectsFilterChange = (evt) => { | ||
const effect = evt.target.value.toUpperCase(); | ||
|
||
if (effect === Effect[DEFAULT_FILTER].name.toUpperCase()) { | ||
resetFilters(); | ||
} else { | ||
showFilterPreview(effect); | ||
} | ||
}; |
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,40 @@ | ||
const STEP = 25; | ||
const DEFEALT_SCALE = 'scale(1)'; | ||
const MAX_PERCENT = 100; | ||
const ScaleInterval = { | ||
MIN: 25, | ||
MAX: 100, | ||
}; | ||
|
||
const scaleSmaller = document.querySelector('.scale__control--smaller'); | ||
const scaleBigger = document.querySelector('.scale__control--bigger'); | ||
const scaleValue = document.querySelector('.scale__control--value'); | ||
const image = document.querySelector('.img-upload__preview').querySelector('img'); | ||
|
||
const isValueInScaleInterval = (value) => | ||
value >= ScaleInterval.MIN && value <= ScaleInterval.MAX; | ||
|
||
const updateScale = (evt) => { | ||
const val = +scaleValue.value.replace('%', '') + STEP * +evt.target.dataset.value; | ||
if(isValueInScaleInterval(val)){ | ||
image.style.transform = `scale(${val / MAX_PERCENT})`; | ||
scaleValue.value = `${val}%`; | ||
} | ||
}; | ||
|
||
const onScaleBiggerClick = (evt) => updateScale(evt.target.dataset.value);; | ||
|
||
const onScaleSmallerClick =(evt) => updateScale(evt.target.dataset.value);; | ||
|
||
|
||
export const renderScaleButtons = () => { | ||
scaleBigger.addEventListener('click', onScaleBiggerClick); | ||
scaleSmaller.addEventListener('click', onScaleSmallerClick); | ||
}; | ||
|
||
export const destroyScaleButtons = () => { | ||
image.style.transform = DEFEALT_SCALE; | ||
scaleBigger.removeEventListener('click', onScaleBiggerClick); | ||
scaleSmaller.removeEventListener('click', onScaleSmallerClick); | ||
}; | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DefaultSliderParam = {
RANGE: {min: 0, max: 100}, START: 100, STEP: 0.1
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
к сожалению, noUiSlider не поддерживает критерии html академии