Skip to content

Commit

Permalink
Внес небольшие изменения
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimRozov committed Mar 17, 2024
1 parent c48d5f0 commit 55e67a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions js/create-thumbnails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const addPhotoThumbnailsUsers = () => {

pictureList.addEventListener('click', (evt) => {
const target = evt.target;
if (target.classList.contains('picture__img')) {
const elementPhoto = createPhotoUsers.find((photo) => photo.id === +target.dataset.id);
if (target.closest('.picture')) {
evt.preventDefault();
const elementPhoto = createPhotoUsers.find((photo) => photo.id === Number(target.dataset.id));
onOpenBigPicture(elementPhoto);
}
});
Expand Down
11 changes: 7 additions & 4 deletions js/showLargePicture/createComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const createComment = (comments) => {
const socialText = document.createElement('p');
socialText.classList.add('social__text');
socialText.textContent = comments.message;

socialComment.append(socialPicture, socialText);
return socialComment;
};
Expand All @@ -34,20 +33,24 @@ const onShowMoreComments = () =>{
commentShownCount.textContent = socialCommentChild.length;
});

if(socialCommentChild.length === arrayComments.length){
if(socialCommentChild.length === arrayComments.length || arrayComments.length === 0){
buttonShowMore.classList.add('hidden');
}

if(arrayComments.length === 0){
commentShownCount.textContent = 0;
}
};

buttonShowMore.addEventListener('click', onShowMoreComments);

const renderComments = (element) => {
arrayComments.splice(0, arrayComments.length) ;
arrayComments.push(...element);
socialCommentsList.innerHTML = '';

buttonShowMore.addEventListener('click', onShowMoreComments);
onShowMoreComments();
};


export {renderComments};
export {renderComments, onShowMoreComments};
10 changes: 7 additions & 3 deletions js/showLargePicture/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bigPictureBlock, bigPictureCancel, bigPictureImg, likesCount, commentTotalCount, socialCaption, socialCommentsList, buttonShowMore} from './elementVariables';
import {renderComments} from './createComments';
import {renderComments, onShowMoreComments} from './createComments';


const toggleClass = (isOpened = true) =>{
Expand All @@ -12,7 +12,9 @@ const onCloseBigPicture = () => {
socialCommentsList.innerHTML = '';
buttonShowMore.classList.remove('hidden');

buttonShowMore.removeEventListener('click', onShowMoreComments);
bigPictureCancel.removeEventListener('click', onCloseBigPicture);
document.removeEventListener('keydown', onCloseBigPictureEsc);
};


Expand All @@ -29,15 +31,17 @@ const onOpenBigPicture = (element) => {
toggleClass();
renderComments(element.comments);

document.addEventListener('keydown', onCloseBigPictureEsc);
bigPictureCancel.addEventListener('click', onCloseBigPicture);
};

document.addEventListener('keydown', (evt) =>{
function onCloseBigPictureEsc(evt){
if(evt.key === 'Escape'){
evt.preventDefault();
onCloseBigPicture();
}
});
}


export {onOpenBigPicture};

0 comments on commit 55e67a0

Please sign in to comment.