Skip to content

Commit

Permalink
пробует выполнить домашнее
Browse files Browse the repository at this point in the history
  • Loading branch information
KateSolodchuk committed Dec 6, 2024
1 parent 32dd26f commit d862989
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
15 changes: 12 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import './util.js';
import {createPhotoList} from './data.js';
import {renderThumbnails} from './render-thumbnails.js';
import {renderThumbnails, pictures} from './render-thumbnails.js';
import {openFullPicture} from './open-full-picture.js';

console.log(createPhotoList());
console.log(renderThumbnails());
pictures.addEventListener('click', (evt) => {
const currentPicture = evt.target.closest('picture');

if (currentPicture) {
openFullPicture(currentPicture.dataset.pictureId);
}
});

console.log(createPhotoList);

Check failure on line 14 in js/main.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
console.log(renderThumbnails);

Check failure on line 15 in js/main.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
44 changes: 44 additions & 0 deletions js/open-full-picture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {isEscapeKey} from './util.js';
import {pictures} from './render-thumbnails.js';
import {createComment} from './data.js';

const closeButton = document.querySelector('.big-picture__cancel');
const commentsList = document.querySelector('.social__comments');

const onDocumentKeydown = (evt) => {
if (isEscapeKey(evt)) {
evt.preventDefault();
closeFullPicture();
}
};

const onClickButtonClose = (evt) => {
evt.preventDefault();
closeFullPicture();
};


const openFullPicture = (pictureId) => {
const currentPhoto = pictures.find((photo)) => photo.id === Number(pictureId);

document.querySelector('body').classList.add('modal-open');
document.querySelector('.big-picture').classList.remove('hidden');
document.querySelector('.big-picture .big-picture__img img').src = photo.url;
document.querySelector('.likes-count').textContent = photo.likes;
document.querySelector('.social__comment-shown-count').textContent = photo.comments.length;
document.querySelector('.social__caption').textContent = photo.description;
document.addEventListener('keydown', onDocumentKeydown);
closeButton.addEventListener('click', onClickButtonClose);
};


function closeFullPicture() {
document.querySelector('.big-picture').classList.add('hidden');
document.querySelector('.social__comment-count').classList.add('hidden');
document.querySelector('.comments-loader').classList.add('hidden');
document.querySelector('body').classList.remove('modal-open');
document.removeEventListener('keydown', onDocumentKeydown);
}

export {openFullPicture, closeFullPicture};

4 changes: 3 additions & 1 deletion js/render-thumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ const renderThumbnails = () => {

usersThumbnails.forEach((photo) => {
const usersElement = thumbnailsTemplate.cloneNode(true);
usersElement.dataset.pictureId = photo.id;
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.length;
usersElement.querySelector('.picture__comments').textContent = photo.comments;
usersThumbnailsFragment.appendChild(usersElement);
});

Expand All @@ -24,3 +25,4 @@ const renderThumbnails = () => {
};

export {renderThumbnails};
export {pictures};
3 changes: 3 additions & 0 deletions js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ const getRandomInteger = (a, b) => {
};
};

const isEscapeKey = (evt) => evt.key === 'Escape';

export {getRandomInteger};
export {isEscapeKey};

0 comments on commit d862989

Please sign in to comment.