-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Добавляет решение задания "Открывается и закрывается Ч.1"
- Loading branch information
Showing
5 changed files
with
40 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters