-
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 #7 from MaksimRozov/module9-task1
- Loading branch information
Showing
15 changed files
with
276 additions
and
24 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
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,31 @@ | ||
const scaleControlSmaller = document.querySelector('.scale__control--smaller'); | ||
const scaleControlBigger = document.querySelector('.scale__control--bigger'); | ||
const scaleControlValue = document.querySelector('.scale__control--value'); | ||
const uploaPreviewImage = document.querySelector('.img-upload__preview img'); | ||
|
||
const STEP_SCALE = 25; | ||
const MIN_SCALE = 25; | ||
const MAX_SCALE = 100; | ||
|
||
const onIncreaseScale = () => { | ||
const scaleValue = parseInt(scaleControlValue.value, 10); | ||
const scaleCount = scaleValue + STEP_SCALE; | ||
const scaleLimited = scaleValue >= MAX_SCALE ? MAX_SCALE : scaleCount; | ||
scaleControlValue.value = `${scaleLimited}%`; | ||
uploaPreviewImage.style.transform = `scale(${scaleLimited / 100})`; | ||
}; | ||
|
||
const onDecreaseScale = () => { | ||
const scaleValue = parseInt(scaleControlValue.value, 10); | ||
const scaleCount = scaleValue - STEP_SCALE; | ||
const scaleLimited = scaleValue <= MIN_SCALE ? MIN_SCALE : scaleCount; | ||
scaleControlValue.value = `${scaleLimited}%`; | ||
uploaPreviewImage.style.transform = `scale(${scaleLimited / 100})`; | ||
}; | ||
|
||
const scaleListener = () => { | ||
scaleControlBigger.addEventListener('click', onIncreaseScale); | ||
scaleControlSmaller.addEventListener('click', onDecreaseScale); | ||
}; | ||
|
||
export {scaleListener}; |
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import {addPhotoThumbnailsUsers} from './create-thumbnails'; | ||
import {onOpenChangePhotoListener} from './upload-photo'; | ||
import {validateListener} from './validation-form'; | ||
import {scaleListener} from './add-effects'; | ||
import {effectCheckedListener} from './slider-effects'; | ||
|
||
effectCheckedListener(); | ||
scaleListener(); | ||
validateListener(); | ||
onOpenChangePhotoListener(); | ||
addPhotoThumbnailsUsers(); |
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
File renamed without changes.
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,51 @@ | ||
export const DEFAULT_MIN = 0; | ||
export const DEFAULT_MAX = 100; | ||
export const DEFAULT_START = 0; | ||
|
||
export const EFFECTS = [ | ||
{ | ||
name: 'chrome', | ||
style: 'grayscale', | ||
min: 0, | ||
max: 1, | ||
step: 0.1, | ||
start: 1, | ||
unit: ' ', | ||
}, | ||
{ | ||
name: 'sepia', | ||
style: 'sepia', | ||
min: 0, | ||
max: 1, | ||
step: 0.1, | ||
start: 1, | ||
unit: ' ', | ||
}, | ||
{ | ||
name: 'marvin', | ||
style: 'invert', | ||
min: 0, | ||
max: 100, | ||
step: 1, | ||
start: 100, | ||
unit: '%', | ||
}, | ||
{ | ||
name: 'phobos', | ||
style: 'blur', | ||
min: 0, | ||
max: 3, | ||
step: 0.1, | ||
start: 3, | ||
unit: 'px', | ||
}, | ||
{ | ||
name: 'heat', | ||
style: 'brightness', | ||
min: 1, | ||
max: 3, | ||
step: 0.1, | ||
start: 3, | ||
unit: ' ', | ||
}, | ||
]; |
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,49 @@ | ||
import {effectLevelSliderParrent, effectLevelSlider, effectLevelInput, effectChecked, uploaPreviewImage} from './slider-variables'; | ||
import {EFFECTS, DEFAULT_MIN, DEFAULT_MAX, DEFAULT_START } from './effect-data'; | ||
|
||
const sliderVisableToggle = (isShown = true) => { | ||
effectLevelSliderParrent.classList.toggle('hidden', isShown); | ||
}; | ||
|
||
const searhEffect = (value, array) => array.find((element) => element.name === value); | ||
|
||
noUiSlider.create(effectLevelSlider, { | ||
range: { | ||
min: DEFAULT_MIN, | ||
max: DEFAULT_MAX, | ||
}, | ||
start: DEFAULT_START, | ||
connect: 'lower' | ||
}); | ||
|
||
const sliderUpdateOptions = (value) => { | ||
const effect = searhEffect(value, EFFECTS); | ||
if(!effect){ | ||
sliderVisableToggle(); | ||
uploaPreviewImage.style.removeProperty('filter'); | ||
return; | ||
} | ||
const {min, max, start, step, unit} = effect; | ||
sliderVisableToggle(false); | ||
effectLevelSlider.noUiSlider.updateOptions({ | ||
range: { | ||
min: min, | ||
max: max, | ||
}, | ||
start: start, | ||
step: step | ||
}); | ||
effectLevelSlider.noUiSlider.on('update', () => { | ||
const effectLevelInputValue = effectLevelSlider.noUiSlider.get(); | ||
effectLevelInput.value = effectLevelInputValue; | ||
uploaPreviewImage.style.filter = `${effect.style}(${effectLevelInputValue}${unit})`; | ||
}); | ||
}; | ||
|
||
export const effectCheckedListener = () => { | ||
effectChecked.addEventListener('change', (evt) => { | ||
if (evt.target.checked) { | ||
sliderUpdateOptions(evt.target.value); | ||
} | ||
}); | ||
}; |
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,5 @@ | ||
export const effectLevelSliderParrent = document.querySelector('.img-upload__effect-level'); | ||
export const effectLevelSlider = effectLevelSliderParrent.querySelector('.effect-level__slider'); | ||
export const effectLevelInput = document.querySelector('.effect-level__value'); | ||
export const effectChecked = document.querySelector('.effects'); | ||
export const uploaPreviewImage = document.querySelector('.img-upload__preview img'); |
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,64 @@ | ||
import {toggleClass} from '../util'; | ||
import {imgUploadInput, imgUpoadOverlay, imgUploadancel} from './uploadPhotoVariables'; | ||
import {inputTextHashtag, commentForm} from '../validation-form'; | ||
const effectsPreview = document.querySelectorAll('.effects__preview'); | ||
|
||
const effectLevelSliderParrent = document.querySelector('.img-upload__effect-level'); | ||
const uploaPreviewImage = document.querySelector('.img-upload__preview img'); | ||
|
||
const onCloseChangePhoto = () => { | ||
toggleClass(imgUpoadOverlay, false); | ||
imgUploadInput.value = ''; | ||
uploaPreviewImage.style.removeProperty('filter'); | ||
uploaPreviewImage.style.removeProperty('transform'); | ||
document.removeEventListener('keydown', onCloseChangePhotoEsc); | ||
imgUploadancel.removeEventListener('click', onCloseChangePhoto); | ||
|
||
}; | ||
|
||
function onCloseChangePhotoEsc(evt){ | ||
if (evt.key === 'Escape' && !(document.activeElement === inputTextHashtag || document.activeElement === commentForm)) { | ||
onCloseChangePhoto(); | ||
} else { | ||
evt.stopPropagation(); | ||
} | ||
} | ||
|
||
const selectImage = (evt) => { | ||
const files = evt.target.files; | ||
const countFiles = files.length; | ||
const selectedFile = files[0]; | ||
const reader = new FileReader(); | ||
|
||
if (!countFiles) { | ||
return; | ||
} | ||
|
||
if (!/^image/.test(selectedFile.type)) { | ||
return; | ||
} | ||
|
||
reader.readAsDataURL(selectedFile); | ||
|
||
reader.addEventListener('load', (e) => { | ||
uploaPreviewImage.src = e.target.result; | ||
effectsPreview.forEach((element) => { | ||
element.style.backgroundImage = `url(${e.target.result})`; | ||
}); | ||
}); | ||
}; | ||
|
||
const onOpenChangePhoto = (evt) => { | ||
toggleClass(imgUpoadOverlay); | ||
selectImage(evt); | ||
effectLevelSliderParrent.classList.add('hidden'); | ||
document.addEventListener('keydown', onCloseChangePhotoEsc); | ||
imgUploadancel.addEventListener('click', onCloseChangePhoto); | ||
|
||
}; | ||
|
||
const onOpenChangePhotoListener = () => { | ||
imgUploadInput.addEventListener('change', onOpenChangePhoto); | ||
}; | ||
|
||
export {onOpenChangePhotoListener}; |
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,3 @@ | ||
export const imgUploadInput = document.querySelector('.img-upload__input'); | ||
export const imgUpoadOverlay = document.querySelector('.img-upload__overlay'); | ||
export const imgUploadancel = imgUpoadOverlay.querySelector('.img-upload__cancel'); |
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
Oops, something went wrong.