Skip to content

Commit

Permalink
Помощь друга(нейминг, setAttribute, повторное открытие модального окна)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenapokrovskaya committed Jan 12, 2025
1 parent da38e13 commit 81de87f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions js/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const renderComment = ({avatar, name, message}) => {
const clonedCommentElement = socialCommentElement.cloneNode(true);
const commentPictureElement = clonedCommentElement.querySelector('.social__picture');
const commentTextElement = clonedCommentElement.querySelector('.social__text');
commentPictureElement.src = avatar;
commentPictureElement.alt = name;
commentPictureElement.setAttribute('src', avatar);
commentPictureElement.setAttribute('alt', name);
commentTextElement.textContent = message;
return clonedCommentElement;
};
Expand Down
6 changes: 3 additions & 3 deletions js/form-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const MAX_COMMENT_LENGTH = 140;
const imgUploadFormElement = document.querySelector('.img-upload__form');
const hashtagsInputElement = imgUploadFormElement.querySelector('.text__hashtags');
const descriptionInutElement = imgUploadFormElement.querySelector('.text__description');
const hashtagRegex = /^#[a-zа-яё0-9]{1,19}$/;
const hashtagRegex = /^#[a-zа-яё0-9]{1,19}$/i;

//Создали объект и передали конфиг
const pristine = new Pristine(imgUploadFormElement, {
Expand All @@ -16,13 +16,13 @@ const pristine = new Pristine(imgUploadFormElement, {
//Проверка длины комментария
const validatesCommentLength = (value) => value.length >= 0 && value.length <= MAX_COMMENT_LENGTH;

const getValues = (value) => value.toLowerCase().trim().split(' ');
const getValues = (value) => value.trim().split(' ');

//Проверка валиден ли хэштег
const validatesHashtagWithRegex = (value) => {
const values = getValues(value);
const isValid = values.every((item) => hashtagRegex.test(item));
return isValid || value.toLowerCase().trim().length === 0;
return isValid || value.trim().length === 0;
};

//Проверка на ввод не более 5 хэштегов
Expand Down
4 changes: 2 additions & 2 deletions js/full-size-picture.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const descriptionElement = bigPictureElement.querySelector('.social__caption');
const commentTotalCountElement = bigPictureElement.querySelector('.social__comment-total-count');


//Функция отрисовки поста в молаьном окне
//Функция отрисовки поста в модальном окне
const renderBigPicture = ({url, likes, comments, description}) => {
imageElement.src = url;
imageElement.setAttribute('src', url);
likesElement.textContent = likes;
commentTotalCountElement.textContent = comments.length;
descriptionElement.textContent = description;
Expand Down
3 changes: 1 addition & 2 deletions js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const renderModal = (posts) => {
bigPictureElement.classList.add('hidden');
//Удаляем обработчик закрытия превью ESC
document.removeEventListener('keydown', onModalEscKeyDown);
picturesParentElement.removeEventListener('click', onThumbnailClick);
//Удаляем класс, чтобы контейнер с фото прокручивался
document.body.classList.remove('modal-open');
}
Expand Down Expand Up @@ -52,7 +51,7 @@ const renderModal = (posts) => {
if (currentPictureElement) {
evt.preventDefault();
//Находим элемент из массива постов с таким же id как у текущего элемента
const foundedPictureByIdElement = posts.find((picture) => picture.id === Number(currentPictureElement.dataset.pictureId));
const foundedPictureByIdElement = posts.find((picture) => picture.id === Number(currentPictureElement.getAttribute('pictureId')));
renderBigPicture(foundedPictureByIdElement);
openModal();
}
Expand Down
21 changes: 11 additions & 10 deletions js/photo-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const scaleControlInputElement = previewElement.querySelector('.scale__control--

const imageElement = previewElement.querySelector('.img-upload__preview img');
const sliderContainerElement = previewElement.querySelector('.img-upload__effect-level');
const effectValue = previewElement.querySelector('.effect-level__value');
const effectValueElement = previewElement.querySelector('.effect-level__value');
const sliderElement = previewElement.querySelector('.effect-level__slider');
const effectsButtons = document.querySelectorAll('.effects__radio');
const effectsButtonElements = document.querySelectorAll('.effects__radio');

const effectsOptions = {
chrome: {
Expand Down Expand Up @@ -61,9 +61,9 @@ let currentScale = Number(scaleControlInputElement.value.slice(0, -1));
const updateCurrentScale = () => {
scaleControlInputElement.value = `${currentScale}%`;
if (currentScale === MAX_SCALE) {
imageElement.style.transform = 'scale(1)';
imageElement.style.setProperty('transform', 'scale(1)');
} else {
imageElement.style.transform = `scale(0.${currentScale})`;
imageElement.style.setProperty('transform', `scale(0.${currentScale})`);
}
};

Expand Down Expand Up @@ -119,7 +119,8 @@ const updateSliderOptions = (effectOptions) => {

//Функция обновления стилей эффекта
const updateSliderValue = (cssProperty, cssUnit) => {
imageElement.style.filter = `${cssProperty}(${effectValue.value}${cssUnit})`;
imageElement.style.setProperty('filter', `${cssProperty}(${effectValueElement.value}${cssUnit})`);

};

//Функция применения настроек эффекта
Expand All @@ -130,14 +131,14 @@ const onSliderEffectsChange = (evt) => {
updateSliderOptions(effectsOptions[checkedEffectButton.value]);
} else {
sliderContainerElement.classList.add('hidden');
imageElement.style.filter = '';
imageElement.style.setProperty('filter', '');
}
};

//Обновение значений при перестаскивании ползунка
sliderElement.noUiSlider.on('update', () => {
effectValue.value = sliderElement.noUiSlider.get();
effectsButtons.forEach((button) => {
effectValueElement.value = sliderElement.noUiSlider.get();
effectsButtonElements.forEach((button) => {
if (button.checked) {
if (button.value !== 'none') {
updateSliderValue(effectsOptions[button.value].property, effectsOptions[button.value].unit);
Expand All @@ -149,10 +150,10 @@ sliderElement.noUiSlider.on('update', () => {
//Функция сброса фоторедактора
const resetPhotoEditor = () => {
currentScale = MAX_SCALE;
imageElement.style.transform = 'scale(1)';
imageElement.style.setProperty('transform', 'scale(1)');
sliderElement.noUiSlider.reset();
sliderContainerElement.classList.add('hidden');
imageElement.style.filter = '';
imageElement.style.setProperty('filter', '');
};

scaleControlBiggerElement.addEventListener('click', onBiggerControlClick);
Expand Down
8 changes: 4 additions & 4 deletions js/thumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const fragmentElement = document.createDocumentFragment();
const createThumbnail = ({id, url, description, likes, comments}) => {
const thumbnailElement = templateElement.cloneNode(true);
const imageElement = thumbnailElement.querySelector('.picture__img');
thumbnailElement.href = '#';
thumbnailElement.dataset.pictureId = id;//Записываем id из данных в data-атрибут
imageElement.src = url;
imageElement.alt = description;
thumbnailElement.setAttribute('href','');
thumbnailElement.setAttribute('pictureId', id);
imageElement.setAttribute('src', url);
imageElement.setAttribute('alt', description);
thumbnailElement.querySelector('.picture__likes').textContent = likes;
thumbnailElement.querySelector('.picture__comments').textContent = comments.length;
return thumbnailElement;
Expand Down

0 comments on commit 81de87f

Please sign in to comment.