-
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 #7 from KateSolodchuk/module8-task1
- Loading branch information
Showing
7 changed files
with
151 additions
and
27 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,5 +1,12 @@ | ||
import './util.js'; | ||
import {CreatePhotoList} from './data.js'; | ||
import './thumbnails.js'; | ||
import {createPhotoList} from './data.js'; | ||
import {renderThumbnails, picturesContainer} from './render-thumbnails.js'; | ||
import {initClickListener} from './open-full-picture.js'; | ||
|
||
const data = createPhotoList(); | ||
|
||
renderThumbnails(data); | ||
initClickListener(data); | ||
|
||
|
||
|
||
console.log(CreatePhotoList()); |
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 {isEscapeKey} from './util.js'; | ||
import {picturesContainer} from './render-thumbnails.js'; | ||
import { clearComments, renderComments } from './render-comments.js'; | ||
|
||
const fullPicture = document.querySelector('.big-picture'); | ||
const closeButton = document.querySelector('.big-picture__cancel'); | ||
|
||
const onDocumentKeydown = (evt) => { | ||
if (isEscapeKey(evt)) { | ||
evt.preventDefault(); | ||
closeFullPicture(); | ||
} | ||
}; | ||
|
||
const onClickButtonClose = (evt) => { | ||
evt.preventDefault(); | ||
closeFullPicture(); | ||
}; | ||
|
||
|
||
const openFullPicture = (pictureId, data) => { | ||
const currentPhoto = data.find((photo) => photo.id === Number(pictureId)); | ||
|
||
document.querySelector('body').classList.add('modal-open'); | ||
fullPicture.classList.remove('hidden'); | ||
|
||
document.querySelector('.big-picture .big-picture__img img').src = currentPhoto.url; | ||
document.querySelector('.likes-count').textContent = currentPhoto.likes; | ||
document.querySelector('.social__comment-shown-count').textContent = currentPhoto.comments.length; | ||
document.querySelector('.social__caption').textContent = currentPhoto.description; | ||
|
||
renderComments(currentPhoto.comments); | ||
|
||
document.addEventListener('keydown', onDocumentKeydown); | ||
closeButton.addEventListener('click', onClickButtonClose); | ||
}; | ||
|
||
function closeFullPicture() { | ||
clearComments(); | ||
fullPicture.classList.add('hidden'); | ||
document.querySelector('body').classList.remove('modal-open'); | ||
document.removeEventListener('keydown', onDocumentKeydown); | ||
} | ||
|
||
const initClickListener = (data) => { | ||
picturesContainer.addEventListener('click', (evt) => { | ||
const currentPicture = evt.target.closest('.picture'); | ||
|
||
if (currentPicture) { | ||
openFullPicture(currentPicture.dataset.pictureId, data); | ||
} | ||
}); | ||
}; | ||
|
||
export {openFullPicture, closeFullPicture, initClickListener}; | ||
|
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,53 @@ | ||
const commentsList = document.querySelector('.social__comments'); | ||
const commentTemplate = commentsList.querySelector('.social__comment'); | ||
const commentCount = document.querySelector('.social__comment-count'); | ||
const commentsLoader = document.querySelector('.social__comment-loader'); | ||
|
||
const VISIBLE_COMMENTS = 5; | ||
let shownComments = 0; | ||
let comments = []; | ||
|
||
commentsList.innerHTML = ''; | ||
|
||
const renderNextComments = () => { | ||
const commentsFragment = document.createDocumentFragment(); | ||
const renderedComments = comments.slice(shownComments, shownComments + VISIBLE_COMMENTS); | ||
const renderedCommentsLength = renderedComments.length + shownComments; | ||
|
||
renderedComments.forEach ((comment) => { | ||
const pictureComment = commentTemplate.cloneNode(true); | ||
|
||
pictureComment.querySelector('.social__picture').src = comment.avatar; | ||
pictureComment.querySelector('.social__picture').alt = comment.name; | ||
pictureComment.querySelector('.social__text').textContent = comment.message; | ||
|
||
commentsFragment.appendChild(pictureComment); | ||
}); | ||
|
||
commentsList.appendChild(commentsFragment); | ||
|
||
commentCount.firstChild.textContent = `${renderedCommentsLength} из `; | ||
commentCount.querySelector('.comments-count').textContent = comments.length; | ||
|
||
if (renderedCommentsLength >= comments.length) { | ||
commentsLoader.classList.add('hidden'); | ||
} | ||
|
||
shownComments += VISIBLE_COMMENTS; | ||
}; | ||
|
||
const clearComments = () => { | ||
shownComments = 0; | ||
commentsList.innerHTML = ''; | ||
commentsLoader.classList.remove('hidden'); | ||
commentsLoader.removeEventListener('click', renderNextComments); | ||
}; | ||
|
||
const renderComments = (currentPhotoComments) => { | ||
comments = currentPhotoComments; | ||
renderNextComments(); | ||
|
||
commentsLoader.addEventListener('click', renderNextComments); | ||
}; | ||
|
||
export {clearComments, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {createPhotoList} from './data.js'; | ||
|
||
const picturesContainer = document.querySelector('.pictures'); | ||
const thumbnailTemplate = document.querySelector('#picture') | ||
.content | ||
.querySelector('.picture'); | ||
|
||
const usersThumbnails = createPhotoList (); | ||
|
||
const renderThumbnails = () => { | ||
const usersThumbnailsFragment = document.createDocumentFragment(); | ||
|
||
usersThumbnails.forEach((photo) => { | ||
const usersElement = thumbnailTemplate.cloneNode(true); | ||
usersElement.dataset.pictureId = photo.id; | ||
usersElement.querySelector('.picture__img').src = photo.url; | ||
usersElement.querySelector('.picture__img').alt = photo.description; | ||
usersElement.querySelector('.picture__likes').textContent = photo.likes; | ||
usersElement.querySelector('.picture__comments').textContent = photo.comments.length; | ||
usersThumbnailsFragment.appendChild(usersElement); | ||
}); | ||
|
||
picturesContainer.appendChild(usersThumbnailsFragment); | ||
|
||
}; | ||
|
||
export {renderThumbnails, picturesContainer}; |
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