From b5b673f93cb5a778526cfb19765668de1fedb328 Mon Sep 17 00:00:00 2001 From: Kate Date: Sun, 8 Dec 2024 17:52:35 +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=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D1=81=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=D0=BC=20=D0=BC=D0=B8=D0=BD=D0=B8=D0=B0=D1=82=D1=8E?= =?UTF-8?q?=D1=80=20=D0=B8=20=D0=BE=D1=82=D0=BA=D1=80=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BF=D0=BE=D0=BB=D0=BD=D0=BE=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/main.js | 13 ++++++------- js/open-full-picture.js | 16 +++++++++++++--- js/render-thumbnails.js | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/js/main.js b/js/main.js index 4ca3a9c..911129c 100644 --- a/js/main.js +++ b/js/main.js @@ -1,13 +1,12 @@ import './util.js'; import {createPhotoList} from './data.js'; import {renderThumbnails, pictures} from './render-thumbnails.js'; -import {openFullPicture} from './open-full-picture.js'; +import {initClickListener} from './open-full-picture.js'; + +const data = createPhotoList(); + +renderThumbnails(data); +initClickListener(data); -pictures.addEventListener('click', (evt) => { - const currentPicture = evt.target.closest('picture'); - if (currentPicture) { - openFullPicture(currentPicture.dataset.pictureId); - } -}); diff --git a/js/open-full-picture.js b/js/open-full-picture.js index 9201e0d..604de72 100644 --- a/js/open-full-picture.js +++ b/js/open-full-picture.js @@ -18,8 +18,8 @@ const onClickButtonClose = (evt) => { }; -const openFullPicture = (pictureId) => { - const currentPhoto = pictures.find((photo) => photo.id === Number(pictureId)); +const openFullPicture = (pictureId, data) => { + const currentPhoto = data.find((photo) => photo.id === Number(pictureId)); document.querySelector('body').classList.add('modal-open'); document.querySelector('.big-picture').classList.remove('hidden'); @@ -40,5 +40,15 @@ function closeFullPicture() { document.removeEventListener('keydown', onDocumentKeydown); } -export {openFullPicture, closeFullPicture}; +const initClickListener = (data) => { + pictures.addEventListener('click', (evt) => { + const currentPicture = evt.target.closest('.picture'); + + if (currentPicture) { + openFullPicture(currentPicture.dataset.pictureId, data); + } + }); +}; + +export {openFullPicture, closeFullPicture, initClickListener}; diff --git a/js/render-thumbnails.js b/js/render-thumbnails.js index 07921f8..d49e65b 100644 --- a/js/render-thumbnails.js +++ b/js/render-thumbnails.js @@ -16,7 +16,7 @@ const renderThumbnails = () => { usersElement.querySelector('.picture__img').src = photo.url; usersElement.querySelector('.picture__img').alt = photo.description; usersElement.querySelector('.picture__likes').textContent = photo.likes; - usersElement.querySelector('.picture__comments').textContent = photo.comments; + usersElement.querySelector('.picture__comments').textContent = photo.comments.length; usersThumbnailsFragment.appendChild(usersElement); });