-
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.
Merge pull request #9 from marijachernova/module8-task1
- Loading branch information
Showing
5 changed files
with
97 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { isEscapeKey } from './util.js'; | ||
|
||
const bigPictureElement = document.querySelector('.big-picture'); | ||
const bodyElement = document.querySelector('body'); | ||
const commentCountElement = bigPictureElement.querySelector('.social__comment-count'); | ||
const commentListElement = bigPictureElement.querySelector('.social__comments'); | ||
const commentsLoaderElement = bigPictureElement.querySelector('.comments-loader'); | ||
const cancelButtonElement = bigPictureElement.querySelector('.big-picture__cancel'); | ||
const liElement = commentListElement.querySelector('li'); | ||
|
||
const createComment = ({ avatar, message, name}) => { | ||
const comment = liElement.cloneNode(true); | ||
|
||
comment.querySelector('.social__picture').src = avatar; | ||
comment.querySelector('.social__picture').alt = name; | ||
comment.querySelector('.social__text').textContent = message; | ||
|
||
return comment; | ||
}; | ||
|
||
const showComments = (comments) => { | ||
commentListElement.innerHTML = ''; | ||
|
||
const fragment = document.createDocumentFragment(); | ||
comments.forEach ((item) => { | ||
const comment = createComment(item); | ||
fragment.append(comment); | ||
}); | ||
|
||
commentListElement.append(fragment); | ||
}; | ||
|
||
const onDocumentKeydown = (evt) => { | ||
if (isEscapeKey) { | ||
evt.preventDefault(); | ||
hideBigPicture(); | ||
} | ||
}; | ||
|
||
function hideBigPicture () { | ||
bigPictureElement.classList.add('hidden'); | ||
bodyElement.classList.remove('modal-open'); | ||
document.removeEventListener('keydown', onDocumentKeydown); | ||
} | ||
|
||
const onCancelButtonClick = () => { | ||
hideBigPicture(); | ||
}; | ||
|
||
const showPictureDetails = ({ url, likes, description }) => { | ||
bigPictureElement.querySelector('.big-picture__img img').src = url; | ||
bigPictureElement.querySelector('.likes-count').textContent = likes; | ||
bigPictureElement.querySelector('.social__caption').textContent = description; | ||
}; | ||
|
||
const showBigPicture = (data) => { | ||
bigPictureElement.classList.remove('hidden'); | ||
bodyElement.classList.add('modal-open'); | ||
commentsLoaderElement.classList.add('hidden'); | ||
commentCountElement.classList.add('hidden'); | ||
document.addEventListener('keydown', onDocumentKeydown); | ||
|
||
showPictureDetails(data); | ||
showComments(data.comments); | ||
}; | ||
|
||
cancelButtonElement.addEventListener('click', onCancelButtonClick); | ||
|
||
export { showBigPicture }; |
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,19 @@ | ||
import { showThumbnails } from './thumbnail.js'; | ||
import { showBigPicture } from './big-picture.js'; | ||
|
||
const container = document.querySelector('.pictures'); | ||
|
||
const showGallery = (pictures) => { | ||
container.addEventListener('click', (evt) => { | ||
const thumbnail = evt.target.closest('[data-thumbnail-id]'); | ||
if (thumbnail) { | ||
evt.preventDefault(); | ||
const pictureId = +thumbnail.dataset.thumbnailId; | ||
const picture = pictures.find((item) => item.id === pictureId); | ||
showBigPicture(picture); | ||
} | ||
}); | ||
showThumbnails(pictures, container); | ||
}; | ||
|
||
export { showGallery }; |
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,4 +1,5 @@ | ||
import { getImages } from './data.js'; | ||
import { showThumbnails } from './thumbnail.js'; | ||
import { showGallery } from './gallery.js'; | ||
|
||
showGallery(getImages()); | ||
|
||
showThumbnails(getImages()); |
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