Skip to content

Commit

Permalink
Сделаны фильты для загрузки фотографий
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimRozov committed Mar 21, 2024
1 parent a20ccfc commit 91a692b
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 17 deletions.
1 change: 0 additions & 1 deletion js/create-thumbnails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const addPhotoThumbnailsUsers = () => {
});

return pictureList.appendChild(listFragmentPhoto);

};

pictureList.addEventListener('click', (evt) => {
Expand Down
1 change: 0 additions & 1 deletion js/generate-data/createComments.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {getRandomInteger, createId, getRandomArrayElement} from '../util';
import {NAMES, MESSAGES} from '../data';


const AVATAR_MIN = 1;
const AVATAR_MAX = 6;
const COMMENTS_MIN = 0;
Expand Down
2 changes: 1 addition & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import {addPhotoThumbnailsUsers} from './create-thumbnails';
import './upload-photo';
import './validation-form';
import './add-affects';
import './slider-affects';
import './slider-effects';

addPhotoThumbnailsUsers();
4 changes: 1 addition & 3 deletions js/show-large-picture/createComments.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {buttonShowMore, socialCommentsList, commentShownCount, socialCommentChild} from './elementVariables';

const LIMITED_DISPLAY_COMMENTS = 5;
const arrayComments = [];


const createComment = (comments) => {
const socialComment = document.createElement('li');
socialComment.classList.add('social__comment');
Expand Down Expand Up @@ -46,10 +46,8 @@ const renderComments = (element) => {
arrayComments.splice(0, arrayComments.length) ;
arrayComments.push(...element);
socialCommentsList.innerHTML = '';

buttonShowMore.addEventListener('click', onShowMoreComments);
onShowMoreComments();
};


export {renderComments, onShowMoreComments};
3 changes: 0 additions & 3 deletions js/show-large-picture/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const onCloseBigPicture = () => {
toggleClass(bigPictureBlock, false);
socialCommentsList.innerHTML = '';
buttonShowMore.classList.remove('hidden');

buttonShowMore.removeEventListener('click', onShowMoreComments);
bigPictureCancel.removeEventListener('click', onCloseBigPicture);
document.removeEventListener('keydown', onCloseBigPictureEsc);
Expand All @@ -24,7 +23,6 @@ const onOpenBigPicture = (element) => {
addInformation(element);
toggleClass(bigPictureBlock);
renderComments(element.comments);

document.addEventListener('keydown', onCloseBigPictureEsc);
bigPictureCancel.addEventListener('click', onCloseBigPicture);
};
Expand All @@ -36,6 +34,5 @@ function onCloseBigPictureEsc(evt){
}
}


export {onOpenBigPicture};

Empty file removed js/slider-affects/index.js
Empty file.
66 changes: 66 additions & 0 deletions js/slider-effects/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {effectLevelSliderParrent, effectLevelSlider, effectLevelInput, effectChecked, uploaPreviewImage} from './slider-variables';

const sliderVisableToggle = (isShown = true) => {
effectLevelSliderParrent.classList.toggle('hidden', isShown);
};

noUiSlider.create(effectLevelSlider, {
range: {
min: 0,
max: 100,
},
start: 0,
connect: 'lower'
});

const sliderUpdateOptions = (min, max, start, step, addStyleFunction) => {
effectLevelSlider.noUiSlider.updateOptions({
range: {
min: min,
max: max,
},
start: start,
step: step
});
effectLevelSlider.noUiSlider.on('update', () => {
let effectLevelInputValue = effectLevelInput.value;
effectLevelInputValue = effectLevelSlider.noUiSlider.get();
effectLevelInput.value = effectLevelInputValue;
uploaPreviewImage.style.filter = addStyleFunction(effectLevelInputValue);
});
};

effectChecked.addEventListener('change', (evt) => {
if (evt.target.checked) {
switch (evt.target.value) {
case 'chrome':
sliderVisableToggle(false);
sliderUpdateOptions(0, 1, 0, 0.1, (value) => `grayscale(${value})`);
break;

case 'sepia':
sliderVisableToggle(false);
sliderUpdateOptions(0, 1, 0, 0.1, (value) => `sepia(${value})`);
break;

case 'marvin':
sliderVisableToggle(false);
sliderUpdateOptions(0, 100, 0, 1, (value) => `invert(${value}%)`);
break;

case 'phobos':
sliderVisableToggle(false);
sliderUpdateOptions(0, 3, 0, 0.1, (value) => `blur(${value}px)`);
break;

case 'heat':
sliderVisableToggle(false);
sliderUpdateOptions(0, 3, 1, 0.1, (value) => `brightness(${value})`);
break;

default:
sliderVisableToggle();
uploaPreviewImage.style.removeProperty('filter');
}
}
});
5 changes: 5 additions & 0 deletions js/slider-effects/slider-variables.js
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');
9 changes: 6 additions & 3 deletions js/upload-photo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ import {toggleClass} from '../util';
import {imgUploadInput, imgUpoadOverlay, imgUploadancel} from './uploadPhotoVariables';
import {inputTextHashtag, commentForm} from '../validation-form';

const effectLevelSliderParrent = document.querySelector('.img-upload__effect-level');

const onCloseChangePhoto = () => {
toggleClass(imgUpoadOverlay, false);
imgUploadInput.value = '';
document.removeEventListener('keydown', onCloseChangePhotoEsc);
};

function onCloseChangePhotoEsc(evt){
if (evt.key === 'Escape' && (document.activeElement === inputTextHashtag || document.activeElement === commentForm)) {
evt.stopPropagation();
} else {
if (evt.key === 'Escape' && !(document.activeElement === inputTextHashtag || document.activeElement === commentForm)) {
onCloseChangePhoto();
} else {
evt.stopPropagation();
}
}

const onOpenChangePhoto = () => {
toggleClass(imgUpoadOverlay);
effectLevelSliderParrent.classList.add('hidden');
document.addEventListener('keydown', onCloseChangePhotoEsc);
};

Expand Down
2 changes: 0 additions & 2 deletions js/util/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const getRandomInteger = (a, b) => {
const lower = Math.ceil(Math.min(a, b));
const upper = Math.floor(Math.max(a, b));
Expand All @@ -21,5 +20,4 @@ const toggleClass = (className, isOpened = true) =>{
document.body.classList.toggle('modal-open');
};


export {getRandomInteger, createId, getRandomArrayElement, toggleClass};
4 changes: 1 addition & 3 deletions js/validation-form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ const createHashtagArray = () => inputTextHashtag.value.replace(/\s+/g, ' ').tri

const onValidateHashtagRegex = () => {
const arrayHashtag = createHashtagArray();

if (arrayHashtag.length === 1 && arrayHashtag[0] === '') {
return true;
}

return arrayHashtag.every((item) => hashtagRegex.test(item));
};

Expand All @@ -35,7 +33,7 @@ const pristine = new Pristine(imgUploadForm, {
errorClass: 'img-upload__field-wrapper--error',
successClass: 'img-upload__field-wrapper--valid',
errorTextParent: 'img-upload__field-wrapper',
}, true);
});

pristine.addValidator(inputTextHashtag, onValidateHashtagRegex, 'Введён невалидный хэштег');
pristine.addValidator(inputTextHashtag, onUniqueHashtag, 'Хэштеги повторяются');
Expand Down

0 comments on commit 91a692b

Please sign in to comment.