Skip to content

Commit

Permalink
Добавляет решение задания "Открывается и закрывается Ч.1"
Browse files Browse the repository at this point in the history
  • Loading branch information
harl-i committed Jan 12, 2025
1 parent cc96486 commit 63e8bd9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<title>Кекстаграм</title>
<title>Кексограм</title>
</head>

<body>
Expand Down
47 changes: 37 additions & 10 deletions js/bigPhotoViewer.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,57 @@
import {photoData} from './data.js';

const picturesContainer = document.querySelector('.pictures');
const bigPicture = document.querySelector('.big-picture');
const bigPhoto = document.querySelector('.big-picture');
const socialComments = document.querySelector('.social__comments');
const commentTemplate = socialComments.querySelector('.social__comment');
const body = document.body;

socialComments.innerHTML = '';

picturesContainer.addEventListener('click', (evt) => {
const targetPhotoId = evt.target.closest('.picture');
const targetPhoto = photoData.find((photo) => photo.photoId === Number(targetPhotoId.dataset.photoId));

const targetPhoto = photoData.find((picture) => picture.photoId === Number(targetPhotoId.dataset.photoId));
bigPhoto.querySelector('.social__comment-count').classList.add('hidden');
bigPhoto.querySelector('.comments-loader').classList.add('hidden');

bigPicture.querySelector('img').src = targetPhoto.url;
bigPicture.querySelector('.likes-count').textContent = targetPhoto.likes;
bigPicture.querySelector('.social__comment-total-count').textContent = targetPhoto.comments.length;
bigPhoto.querySelector('img').src = targetPhoto.url;
bigPhoto.querySelector('.likes-count').textContent = targetPhoto.likes;
bigPhoto.querySelector('.social__comment-total-count').textContent = targetPhoto.comments.length;
bigPhoto.querySelector('.social__caption').textContent = targetPhoto.description;

bigPicture.classList.remove('hidden');
bigPhoto.classList.remove('hidden');
body.classList.add('modal-open');

targetPhoto.comments.forEach((comment) => {
const newComment = commentTemplate.cloneNode(true);
newComment.querySelector('.social__picture').src = comment.avatar;
newComment.querySelector('.social__text').textContent = comment.commentsList;
newComment.querySelector('.social__picture').alt = comment.name;
socialComments.appendChild(newComment);
});

bigPhoto.querySelector('.social__comment-shown-count').textContent = targetPhoto.comments.length;

bigPhoto.setAttribute('tabindex', '0');
bigPhoto.focus();
});

bigPicture.addEventListener('click', (evt) => {
bigPhoto.addEventListener('click', (evt) => {
if(evt.target.closest('.big-picture__cancel')) {
bigPicture.classList.add('hidden');
body.classList.remove('modal-open');
closeBigPhoto();
}
});

function createCommentTemplate() {
bigPhoto.addEventListener('keydown', (evt) => {
if (evt.key === 'Escape') {
closeBigPhoto();
}
});

function closeBigPhoto() {
bigPhoto.classList.add('hidden');
body.classList.remove('modal-open');
}


4 changes: 2 additions & 2 deletions js/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const COMMENTS_COUNT = {
};

const AVATARS_COUNT = {
MIN: 0,
MIN: 1,
MAX: 6
};

const SENTENCES_COUNT = {
MIN: 0,
MAX: 4
MAX: 2
};

const RANDOM_RANGE = {
Expand Down
6 changes: 0 additions & 6 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@ import {showThumbnail} from './thumbnails.js';
import './bigPhotoViewer.js';

showThumbnail();
// const OBJECTS_COUNT = 26;
//
// const randomPhotoObjects = getPhotoData(OBJECTS_COUNT);
// photoObjects = randomPhotoObjects;
//
// showThumbnail(randomPhotoObjects);
3 changes: 0 additions & 3 deletions js/thumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {photoData} from './data.js';

const pictureTemplateElement = document.querySelector('#picture').content.querySelector('.picture');
const picturesContainer = document.querySelector('.pictures');
// const thumbnailsReadyEvent = new Event('thumbnailsIsReady');

function showThumbnail() {
const fragment = document.createDocumentFragment();
Expand All @@ -20,8 +19,6 @@ function showThumbnail() {
});

picturesContainer.appendChild(fragment);

// picturesContainer.dispatchEvent(thumbnailsReadyEvent);
}

export {showThumbnail};

0 comments on commit 63e8bd9

Please sign in to comment.