-
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
1 parent
500a158
commit 6d06647
Showing
7 changed files
with
128 additions
and
6 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,18 @@ | ||
import {renderComments} from './comments'; | ||
const bigPictureElement = document.body.querySelector('.big-picture'); | ||
const imageElement = bigPictureElement.querySelector('img'); | ||
const likesElement = bigPictureElement.querySelector('.likes-count'); | ||
const descriptionElement = bigPictureElement.querySelector('.social__caption'); | ||
const commentTotalCountElement = bigPictureElement.querySelector('.social__comment-total-count'); | ||
|
||
|
||
//Функция отрисовки поста в молаьном окне | ||
const renderBigPicture = (picture) => { | ||
imageElement.src = picture.url; | ||
likesElement.textContent = picture.likes; | ||
commentTotalCountElement.textContent = picture.comments.length; | ||
descriptionElement.textContent = picture.description; | ||
renderComments(picture); | ||
}; | ||
|
||
export {renderBigPicture}; |
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,30 @@ | ||
const сommentsListElement = document.querySelector('.social__comments'); | ||
const socialCommentElement = сommentsListElement.querySelector('.social__comment'); | ||
const fragmentElement = document.createDocumentFragment(); | ||
|
||
//Функция создания комментария | ||
const renderComment = (comment) => { | ||
const clonedCommentElement = socialCommentElement.cloneNode(true); | ||
const socialPicture = clonedCommentElement.querySelector('.social__picture'); | ||
const socialText = clonedCommentElement.querySelector('.social__text'); | ||
socialPicture.src = comment.avatar; | ||
socialPicture.alt = comment.name; | ||
socialText.textContent = comment.message; | ||
return clonedCommentElement; | ||
}; | ||
|
||
//Отрисуем массив комментариев для каждого поста | ||
const renderComments = (picture) => { | ||
const postСomments = picture.comments; | ||
postСomments.forEach((comment) => { | ||
const commentElement = renderComment(comment); | ||
сommentsListElement.appendChild(commentElement); | ||
fragmentElement.appendChild(commentElement); | ||
}); | ||
|
||
сommentsListElement.innerHTML = ''; | ||
сommentsListElement.appendChild(fragmentElement); | ||
}; | ||
|
||
|
||
export {renderComments}; |
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,9 @@ | ||
import {createPosts} from './data.js'; | ||
import {createFragment} from './thumbnails.js'; | ||
import {renderModal} from './modal.js'; | ||
|
||
|
||
const posts = createPosts(); | ||
createFragment(posts); | ||
renderModal(posts); | ||
|
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,66 @@ | ||
import {isEscapeKey} from './util.js'; | ||
import {renderBigPicture} from './ full-size-picture.js'; | ||
|
||
const renderModal = (posts) => { | ||
const bigPictureElement = document.body.querySelector('.big-picture'); | ||
const picturesParentElement = document.querySelector('.pictures'); | ||
const pictureCloseButton = bigPictureElement.querySelector('.big-picture__cancel'); | ||
const socialCommentCount = bigPictureElement.querySelector('.social__comment-count'); | ||
const commentsLoader = bigPictureElement.querySelector('.comments-loader'); | ||
|
||
//Функция-обработчик закрытия модалки ESC | ||
const onModalEscKeyDown = (evt) => { | ||
if (isEscapeKey(evt)) { | ||
evt.preventDefault(); | ||
closeMоdal(); | ||
} | ||
}; | ||
|
||
//Функция закрытия модалки | ||
function closeMоdal () { | ||
bigPictureElement.classList.add('hidden'); | ||
//Удаляем обработчик закрытия превью ESC | ||
document.removeEventListener('keydown', onModalEscKeyDown); | ||
//Удаляем класс, чтобы контейнер с фото прокручивался | ||
document.body.classList.remove('modal-open'); | ||
} | ||
|
||
//Функция закрытия модалки по нажатию на кнопку | ||
const onCloseButtonClick = (button) => { | ||
button.addEventListener('click', (evt) => { | ||
evt.preventDefault(); | ||
closeMоdal(); | ||
}); | ||
}; | ||
|
||
onCloseButtonClick(pictureCloseButton); | ||
|
||
//Функция открытия модалки | ||
const openModal = () => { | ||
bigPictureElement.classList.remove('hidden'); | ||
//Добавляем обработчик закрытия превью ESC | ||
document.addEventListener('keydown', onModalEscKeyDown); | ||
//Добавляем класс, чтобы контейнер с фото не прокручивался | ||
document.body.classList.add('modal-open'); | ||
}; | ||
|
||
//Функция обработчика клика, показывает модалку | ||
const onThumbnailClick = (evt) => { | ||
const currentPictureElement = evt.target.closest('.picture'); | ||
if (currentPictureElement) { | ||
evt.preventDefault(); | ||
//Находим элемент из массива постов с таким же id как у текущего элемента | ||
const foundedPictureByIdElement = posts.find((picture) => picture.id === Number(currentPictureElement.dataset.pictureId)); | ||
renderBigPicture(foundedPictureByIdElement); | ||
openModal(); | ||
// Скрываем блоки счетчика комментариев и загрузки новых комментариев | ||
socialCommentCount.classList.add('hidden'); | ||
commentsLoader.classList.add('hidden'); | ||
} | ||
}; | ||
|
||
picturesParentElement.addEventListener('click', onThumbnailClick); | ||
}; | ||
|
||
export {renderModal}; | ||
|
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