From c2bfc782a43298f48468f4042d9cd73f8475963e Mon Sep 17 00:00:00 2001 From: Kate Date: Sat, 14 Dec 2024 22:47:29 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D1=8D=D0=BA=D1=81=D0=BF=D0=BE=D1=80=D1=82?= =?UTF-8?q?,=20=D1=83=D0=B1=D0=B8=D1=80=D0=B0=D0=B5=D1=82=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=88=D0=BD=D0=B5=D0=B5=20=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B1?= =?UTF-8?q?=D1=83=D0=B5=D1=82=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/main.js | 8 ++++---- js/open-full-picture.js | 9 ++++----- js/render-comments.js | 18 +++++++++--------- js/util.js | 3 +-- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/js/main.js b/js/main.js index db70755..4583ec4 100644 --- a/js/main.js +++ b/js/main.js @@ -1,12 +1,12 @@ import './util.js'; import {createPhotoList} from './data.js'; -import {renderThumbnails, picturesContainer} from './render-thumbnails.js'; +import {renderThumbnails} from './render-thumbnails.js'; import {initClickListener} from './open-full-picture.js'; -const data = createPhotoList(); +const picturesDataList = createPhotoList(); -renderThumbnails(data); -initClickListener(data); +renderThumbnails(picturesDataList); +initClickListener(picturesDataList); diff --git a/js/open-full-picture.js b/js/open-full-picture.js index 928c1a8..e937e62 100644 --- a/js/open-full-picture.js +++ b/js/open-full-picture.js @@ -17,9 +17,8 @@ const onClickButtonClose = (evt) => { closeFullPicture(); }; - -const openFullPicture = (pictureId, data) => { - const currentPhoto = data.find((photo) => photo.id === Number(pictureId)); +const openFullPicture = (pictureId, picturesDataList) => { + const currentPhoto = picturesDataList.find((photo) => photo.id === Number(pictureId)); document.querySelector('body').classList.add('modal-open'); fullPicture.classList.remove('hidden'); @@ -42,12 +41,12 @@ function closeFullPicture() { document.removeEventListener('keydown', onDocumentKeydown); } -const initClickListener = (data) => { +const initClickListener = (picturesDataList) => { picturesContainer.addEventListener('click', (evt) => { const currentPicture = evt.target.closest('.picture'); if (currentPicture) { - openFullPicture(currentPicture.dataset.pictureId, data); + openFullPicture(currentPicture.dataset.pictureId, picturesDataList); } }); }; diff --git a/js/render-comments.js b/js/render-comments.js index 40f1d54..8dee42a 100644 --- a/js/render-comments.js +++ b/js/render-comments.js @@ -27,22 +27,15 @@ const renderNextComments = () => { commentsList.appendChild(commentsFragment); commentCount.firstChild.textContent = `${renderedCommentsLength} из `; - commentCount.querySelector('.comments-count').textContent = comments.length; + document.querySelector('.social__comment-total-count').textContent = comments.length; if (renderedCommentsLength >= comments.length) { - commentsLoader.classList.add('hidden'); + commentsLoader.classList.add('.hidden'); } shownComments += VISIBLE_COMMENTS; }; -const clearComments = () => { - shownComments = 0; - commentsList.innerHTML = ''; - commentsLoader.classList.remove('hidden'); - commentsLoader.removeEventListener('click', renderNextComments); -}; - const renderComments = (currentPhotoComments) => { comments = currentPhotoComments; renderNextComments(); @@ -50,4 +43,11 @@ const renderComments = (currentPhotoComments) => { commentsLoader.addEventListener('click', renderNextComments); }; +const clearComments = () => { + shownComments = 0; + commentsList.innerHTML = ''; + commentsLoader.classList.remove('hidden'); + commentsLoader.removeEventListener('click', renderNextComments); +}; + export {clearComments, renderComments}; diff --git a/js/util.js b/js/util.js index fb60e19..e50a71d 100644 --- a/js/util.js +++ b/js/util.js @@ -14,5 +14,4 @@ const getRandomInteger = (a, b) => { const isEscapeKey = (evt) => evt.key === 'Escape'; -export {getRandomInteger}; -export {isEscapeKey}; +export {getRandomInteger, isEscapeKey};