-
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
8 changed files
with
119 additions
and
71 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {fillCommentsList} from './comments-viewer.js'; | ||
|
||
const picturesContainerElement = document.querySelector('.pictures'); | ||
const bigPhotoElement = document.querySelector('.big-picture'); | ||
|
||
const bodyElement = document.body; | ||
let photoData = []; | ||
|
||
picturesContainerElement.addEventListener('click', (evt) => { | ||
const targetPhotoId = evt.target.closest('.picture'); | ||
const targetPhoto = photoData.find((photo) => photo.photoId === Number(targetPhotoId.dataset.photoId)); | ||
const {url, description, likes, comments} = targetPhoto; | ||
|
||
bigPhotoElement.querySelector('.social__comment-count').classList.add('hidden'); | ||
bigPhotoElement.querySelector('.comments-loader').classList.add('hidden'); | ||
|
||
bigPhotoElement.querySelector('img').setAttribute('src', url); | ||
bigPhotoElement.querySelector('.likes-count').textContent = likes; | ||
bigPhotoElement.querySelector('.social__comment-total-count').textContent = comments.length; | ||
bigPhotoElement.querySelector('.social__caption').textContent = description; | ||
|
||
bigPhotoElement.classList.remove('hidden'); | ||
bodyElement.classList.add('modal-open'); | ||
|
||
fillCommentsList(targetPhoto.comments); | ||
|
||
bigPhotoElement.querySelector('.social__comment-shown-count').textContent = comments.length; | ||
|
||
bigPhotoElement.setAttribute('tabindex', '0'); | ||
bigPhotoElement.focus(); | ||
}); | ||
|
||
bigPhotoElement.addEventListener('click', (evt) => { | ||
if(evt.target.closest('.big-picture__cancel')) { | ||
closeBigPhoto(); | ||
} | ||
}); | ||
|
||
bigPhotoElement.addEventListener('keydown', (evt) => { | ||
if (evt.key === 'Escape') { | ||
closeBigPhoto(); | ||
} | ||
}); | ||
|
||
function closeBigPhoto() { | ||
bigPhotoElement.classList.add('hidden'); | ||
bodyElement.classList.remove('modal-open'); | ||
} | ||
|
||
function setPhotoData(data) { | ||
photoData = data; | ||
} | ||
|
||
export {setPhotoData}; | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ const AVATARS_COUNT = { | |
}; | ||
|
||
const SENTENCES_COUNT = { | ||
MIN: 0, | ||
MIN: 1, | ||
MAX: 2 | ||
}; | ||
|
||
|
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,17 @@ | ||
const socialCommentsElement = document.querySelector('.social__comments'); | ||
const commentTemplateElement = socialCommentsElement.querySelector('.social__comment'); | ||
|
||
function fillCommentsList(comments) { | ||
socialCommentsElement.innerHTML = ''; | ||
comments.forEach((comment) => { | ||
const newCommentElement = commentTemplateElement.cloneNode(true); | ||
const commentPictureElement = newCommentElement.querySelector('.social__picture'); | ||
|
||
commentPictureElement.setAttribute('src', comment.avatar); | ||
commentPictureElement.setAttribute('alt', comment.name); | ||
newCommentElement.querySelector('.social__text').textContent = comment.commentsList; | ||
socialCommentsElement.appendChild(newCommentElement); | ||
}); | ||
} | ||
|
||
export {fillCommentsList}; |
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,5 +1,8 @@ | ||
import './data.js'; | ||
import {photoData, generateMockData} from './data.js'; | ||
import {showThumbnail} from './thumbnails.js'; | ||
import './bigPhotoViewer.js'; | ||
import {setPhotoData} from './big-photo-viewer.js'; | ||
|
||
generateMockData(26); | ||
showThumbnail(photoData); | ||
setPhotoData(photoData); | ||
|
||
showThumbnail(); |
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