-
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.
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const bigPicture = document.querySelector('.big-picture'); | ||
const commentsCount = bigPicture.querySelector('.comments-count'); | ||
const likesCount = bigPicture.querySelector('.likes-count'); | ||
const bigImage = bigPicture.querySelector('.big-picture__img img'); | ||
const description = bigPicture.querySelector('.social__caption'); | ||
|
||
const createComment = (avatar, name, text) => `<li class="social__comment"> | ||
<img | ||
class="social__picture" | ||
src="${avatar}" | ||
alt="${name}" | ||
width="35" height="35"> | ||
<p class="social__text">${text}</p> | ||
</li>`; | ||
|
||
|
||
const createCommentsBlock = (comments) =>{ | ||
const commentsBlock = bigPicture.querySelector('.social__comments'); | ||
commentsBlock.innerHTML = ''; | ||
commentsBlock.insertAdjacentHTML('afterbegin', comments.map((comment) => createComment(comment.avatar, comment.name, comment.message)).join('')); // Array(comments).map | ||
}; | ||
|
||
|
||
const constructBigPicture = (picture, photos) =>{ | ||
const likes = picture.querySelector('.picture__likes'); | ||
const comments = picture.querySelector('.picture__comments'); | ||
const image = picture.querySelector('.picture__img'); | ||
const photoInfo = photos.find((photo) => `/${photo.url}` === new URL(image.src).pathname); | ||
description.textContent = photoInfo.description; | ||
likesCount.textContent = likes.textContent; | ||
bigImage.src = image.src; | ||
commentsCount.textContent = comments.textContent; | ||
createCommentsBlock(photoInfo.comments, bigPicture); | ||
}; | ||
|
||
|
||
export const showBigPicture = (photos) => { | ||
const pictures = document.querySelectorAll('.picture'); | ||
for (const picture of pictures){ | ||
picture.onclick = () =>{ | ||
constructBigPicture(picture, photos); | ||
bigPicture.classList.remove('hidden'); | ||
bigPicture.querySelector('.social__comment-count').hidden = true; | ||
bigPicture.querySelector('.comments-loader').hidden = true; | ||
document.body.classList.add('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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import {getPhotoDescriptions} from './data.js'; | ||
import {thumbnailsRender} from './thumbnails.js'; | ||
import {showBigPicture} from './full-size-images.js'; | ||
|
||
const PHOTOS_COUNT = 25; | ||
|
||
const photos = getPhotoDescriptions(PHOTOS_COUNT); | ||
thumbnailsRender(photos); | ||
showBigPicture(photos); |