From 7461eb6867420b5742792236cabd5a3be5b36ec5 Mon Sep 17 00:00:00 2001 From: "rit1992@mail.ru" <158091165+margarita0206@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:11:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/modal-pictures.js | 14 ++++++++------ js/scale.js | 8 ++++---- js/success-error.js | 16 ++++++++-------- js/thumbnail.js | 4 ++-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/js/modal-pictures.js b/js/modal-pictures.js index 667add4..2c84968 100644 --- a/js/modal-pictures.js +++ b/js/modal-pictures.js @@ -10,7 +10,7 @@ const commentShowCount = bigPicturesModal.querySelector('.social__comment-shown- const commentsList = bigPicturesModal.querySelector('.social__comments'); const commentTemplate = bigPicturesModal.querySelector('.social__comment'); -const localComment = []; +const localComments = []; let renderedCommentsCount = 0; let total = 0; @@ -29,7 +29,7 @@ const renderStatistic = () => { const renderComments = () => { const commentFragment = document.createDocumentFragment(); - localComment.splice(0, 5).forEach((item) => { + localComments.splice(0, 5).forEach((item) => { const commentElement = commentTemplate.cloneNode(true); commentElement.querySelector('.social__picture').src = item.avatar; commentElement.querySelector('.social__picture').alt = item.name; @@ -43,18 +43,20 @@ const renderComments = () => { renderStatistic(); }; +const onCommentsLoaderClick = () => renderComments(); + const fillDataBigPicture = ({ url, likes, comments, description}) => { bigPicturesModal.querySelector('.big-picture__img img').src = url; bigPicturesModal.querySelector('.likes-count').textContent = likes; bigPicturesModal.querySelector('.social__caption').textContent = description; - localComment.length = 0; - localComment.push(...comments.slice()); + localComments.length = 0; + localComments.push(...comments.slice()); commentsList.innerHTML = ''; renderedCommentsCount = 0; total = comments.length; - renderComments(); + onCommentsLoaderClick(); }; const onDocumentKeydown = (evt) => { @@ -83,6 +85,6 @@ closeBigPicturesButton.addEventListener('click', () => { closeBigPictureWindow(); }); -loadCommentsButton.addEventListener('click', renderComments); +loadCommentsButton.addEventListener('click', onCommentsLoaderClick); export { openBigPictureWindow }; diff --git a/js/scale.js b/js/scale.js index 098f5bb..75042d3 100644 --- a/js/scale.js +++ b/js/scale.js @@ -19,13 +19,13 @@ const scaleImage = (value) => { scaleInput.value = `${value}%`; }; -const onSmallerClickButton = () => { +const onSmallerButtonClick = () => { scaleImage( Math.max(parseInt(scaleInput.value, 10) - SCALE_STEP, MIN_SCALE) ); }; -const onBiggerClickButton = () => { +const onBiggerButtonClick = () => { scaleImage( Math.min(parseInt(scaleInput.value, 10) + SCALE_STEP, MAX_SCALE) ); @@ -33,7 +33,7 @@ const onBiggerClickButton = () => { const resetScale = () => scaleImage(DEFAULT_SCALE); -smallButtonElement.addEventListener('click', onSmallerClickButton); -bigButtonElement.addEventListener('click', onBiggerClickButton); +smallButtonElement.addEventListener('click', onSmallerButtonClick); +bigButtonElement.addEventListener('click', onBiggerButtonClick); export { resetScale }; diff --git a/js/success-error.js b/js/success-error.js index d6267af..8ef6390 100644 --- a/js/success-error.js +++ b/js/success-error.js @@ -7,10 +7,10 @@ const errorFragment = document.createDocumentFragment(); const body = document.querySelector('body'); -const onEscapeKeydownSuccess = (evt) => { +const onEscapeSuccessKeydown = (evt) => { if (isEscapeKey(evt)) { document.querySelector('.success').remove(); - document.removeEventListener('keydown', onEscapeKeydownSuccess); + document.removeEventListener('keydown', onEscapeSuccessKeydown); } }; @@ -20,19 +20,19 @@ const showMessageSuccess = () => { body.appendChild(successFragment); const buttonSuccess = document.querySelector('.success__button'); const sectionSuccess = document.querySelector('.success'); - document.addEventListener('keydown', onEscapeKeydownSuccess); + document.addEventListener('keydown', onEscapeSuccessKeydown); sectionSuccess.addEventListener(('click'), (evt) => { if (evt.target === buttonSuccess || evt.target.classList.contains('success')) { sectionSuccess.remove(); - document.removeEventListener('keydown', onEscapeKeydownSuccess); + document.removeEventListener('keydown', onEscapeSuccessKeydown); } }); }; -const onEscapeKeydownError = (evt) => { +const onEscapeErrorKeydown = (evt) => { if (isEscapeKey(evt)) { document.querySelector('.error').remove(); - document.removeEventListener('keydown', onEscapeKeydownError); + document.removeEventListener('keydown', onEscapeErrorKeydown); } }; @@ -42,11 +42,11 @@ const showMessageError = () => { body.appendChild(errorFragment); const buttonError = document.querySelector('.error__button'); const sectionError = document.querySelector('.error'); - document.addEventListener('keydown', onEscapeKeydownError); + document.addEventListener('keydown', onEscapeErrorKeydown); sectionError.addEventListener(('click'), (evt) => { if (evt.target === buttonError || evt.target.classList.contains('error')) { sectionError.remove(); - document.removeEventListener('keydown', onEscapeKeydownError); + document.removeEventListener('keydown', onEscapeErrorKeydown); } }); }; diff --git a/js/thumbnail.js b/js/thumbnail.js index da12589..b2e1aed 100644 --- a/js/thumbnail.js +++ b/js/thumbnail.js @@ -7,12 +7,12 @@ const pictureTemplate = document.querySelector('#picture') .content .querySelector('.picture'); -const generateThumbnails = (picture) => { +const generateThumbnails = (pictures) => { picturesContainer.querySelectorAll('.picture').forEach((element) => element.remove()); const similarListFragment = document.createDocumentFragment(); - picture.forEach(({ id, url, description, likes, comments }) => { + pictures.forEach(({ id, url, description, likes, comments }) => { const pictureElement = pictureTemplate.cloneNode(true); pictureElement.querySelector('.picture__img').dataset.id = id; pictureElement.querySelector('.picture__img').src = url;