forked from htmlacademy-javascript/144485-kekstagram-31
-
Notifications
You must be signed in to change notification settings - Fork 0
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 htmlacademy-javascript#6 from MaksimRozov/module8-…
…task1
- Loading branch information
Showing
5 changed files
with
132 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
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,3 @@ | ||
import {addPhotoThumbnailsUsers} from './create-thumbnails'; | ||
import './showLargePicture'; | ||
|
||
addPhotoThumbnailsUsers(); |
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 {buttonShowMore, socialCommentsList, commentShownCount, socialCommentChild} from './elementVariables'; | ||
const LIMITED_DISPLAY_COMMENTS = 5; | ||
const arrayComments = []; | ||
|
||
|
||
const createComment = (comments) => { | ||
const socialComment = document.createElement('li'); | ||
socialComment.classList.add('social__comment'); | ||
|
||
const socialPicture = document.createElement('img'); | ||
socialPicture.classList.add('social__picture'); | ||
socialPicture.src = comments.avatar; | ||
socialPicture.alt = comments.name; | ||
socialPicture.width = '35'; | ||
socialPicture.height = '35'; | ||
|
||
const socialText = document.createElement('p'); | ||
socialText.classList.add('social__text'); | ||
socialText.textContent = comments.message; | ||
socialComment.append(socialPicture, socialText); | ||
return socialComment; | ||
}; | ||
|
||
const onShowMoreComments = () =>{ | ||
const currentShowedComments = socialCommentsList.childElementCount; | ||
const commentsCount = currentShowedComments + LIMITED_DISPLAY_COMMENTS; | ||
const commentsLimited = arrayComments.length >= commentsCount ? commentsCount : arrayComments.length; | ||
const commentsList = arrayComments.slice(currentShowedComments, commentsLimited); | ||
|
||
commentsList.forEach((item) =>{ | ||
const commentElement = createComment(item); | ||
socialCommentsList.append(commentElement); | ||
commentShownCount.textContent = socialCommentChild.length; | ||
}); | ||
|
||
if(socialCommentChild.length === arrayComments.length || arrayComments.length === 0){ | ||
buttonShowMore.classList.add('hidden'); | ||
} | ||
|
||
if(arrayComments.length === 0){ | ||
commentShownCount.textContent = 0; | ||
} | ||
}; | ||
|
||
|
||
const renderComments = (element) => { | ||
arrayComments.splice(0, arrayComments.length) ; | ||
arrayComments.push(...element); | ||
socialCommentsList.innerHTML = ''; | ||
|
||
buttonShowMore.addEventListener('click', onShowMoreComments); | ||
onShowMoreComments(); | ||
}; | ||
|
||
|
||
export {renderComments, onShowMoreComments}; |
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,11 @@ | ||
export const bigPictureBlock = document.querySelector('.big-picture'); | ||
export const bigPictureCancel = document.querySelector('.big-picture__cancel'); | ||
export const bigPictureImg = bigPictureBlock.querySelector('.big-picture__img img'); | ||
export const likesCount = bigPictureBlock.querySelector('.likes-count'); | ||
export const commentTotalCount = bigPictureBlock.querySelector('.social__comment-total-count'); | ||
export const commentShownCount = bigPictureBlock.querySelector('.social__comment-shown-count'); | ||
export const socialCaption = bigPictureBlock.querySelector('.social__caption'); | ||
export const socialCommentsList = bigPictureBlock.querySelector('.social__comments'); | ||
export const buttonShowMore = bigPictureBlock.querySelector('.social__comments-loader'); | ||
export const socialCommentChild = socialCommentsList.children; | ||
|
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,47 @@ | ||
import { bigPictureBlock, bigPictureCancel, bigPictureImg, likesCount, commentTotalCount, socialCaption, socialCommentsList, buttonShowMore} from './elementVariables'; | ||
import {renderComments, onShowMoreComments} from './createComments'; | ||
|
||
|
||
const toggleClass = (isOpened = true) =>{ | ||
document.body.classList.toggle('modal-open'); | ||
bigPictureBlock.classList.toggle('hidden', !isOpened); | ||
}; | ||
|
||
const onCloseBigPicture = () => { | ||
toggleClass(false); | ||
socialCommentsList.innerHTML = ''; | ||
buttonShowMore.classList.remove('hidden'); | ||
|
||
buttonShowMore.removeEventListener('click', onShowMoreComments); | ||
bigPictureCancel.removeEventListener('click', onCloseBigPicture); | ||
document.removeEventListener('keydown', onCloseBigPictureEsc); | ||
}; | ||
|
||
|
||
const addInformation = ({url, description, likes, comments}) =>{ | ||
bigPictureImg.src = url; | ||
bigPictureImg.alt = description; | ||
socialCaption.textContent = description; | ||
likesCount.textContent = likes; | ||
commentTotalCount.textContent = comments.length; | ||
}; | ||
|
||
const onOpenBigPicture = (element) => { | ||
addInformation(element); | ||
toggleClass(); | ||
renderComments(element.comments); | ||
|
||
document.addEventListener('keydown', onCloseBigPictureEsc); | ||
bigPictureCancel.addEventListener('click', onCloseBigPicture); | ||
}; | ||
|
||
function onCloseBigPictureEsc(evt){ | ||
if(evt.key === 'Escape'){ | ||
evt.preventDefault(); | ||
onCloseBigPicture(); | ||
} | ||
} | ||
|
||
|
||
export {onOpenBigPicture}; | ||
|