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;