-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Открывается и закрывается #12
Merged
keksobot
merged 5 commits into
htmlacademy-javascript:master
from
Daniil888-m:module8-task1
Dec 13, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
80dbebf
editor
Daniil888-m 4ac6e09
fixed the problem with modules
Daniil888-m 57dc1a8
added removing class 'modal-open' when popup is closed
Daniil888-m 8d2da79
added preventDefault
Daniil888-m 2153031
refactored renderComments openBigPhoto
Daniil888-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,71 @@ | ||
import { getPhotos } from './get-photos.js'; | ||
import { hide, show } from './utils.js'; | ||
const photos = getPhotos(); | ||
const bigPhotoPopup = document.querySelector('.big-picture'); | ||
const popupCancelElement = document.querySelector('.big-picture__cancel'); | ||
|
||
function onEscapeKeydown(e) { | ||
if (e.key === 'Escape') { | ||
hidePhotoPopup(); | ||
} | ||
} | ||
|
||
function renderComments(photoId) { | ||
const currentPhoto = photos.find((photo) => photo.id === Number(photoId)); | ||
const commentFragmentList = document.createDocumentFragment(); | ||
currentPhoto.comments.forEach((comment) => { | ||
const commEl = document.createElement('li'); | ||
commEl.className = 'social__comment'; | ||
|
||
const imgEl = document.createElement('img'); | ||
imgEl.className = 'social__picture'; | ||
imgEl.src = comment.avatar; | ||
imgEl.alt = comment.name; | ||
imgEl.width = 35; | ||
imgEl.height = 35; | ||
|
||
const pEl = document.createElement('p'); | ||
pEl.className = 'social__text'; | ||
pEl.textContent = comment.message; | ||
|
||
commEl.append(imgEl); | ||
commEl.append(pEl); | ||
commentFragmentList.append(commEl); | ||
|
||
}); | ||
|
||
return commentFragmentList; | ||
|
||
} | ||
function hidePhotoPopup(e) { | ||
e.preventDefault(); | ||
hide(bigPhotoPopup); | ||
document.removeEventListener('keydown', onEscapeKeydown); | ||
document.body.classList.remove('modal-open'); | ||
} | ||
function showPhotoPopup() { | ||
document.body.classList.add('modal-open'); | ||
show(bigPhotoPopup); | ||
|
||
document.addEventListener('keydown', onEscapeKeydown); | ||
} | ||
function openBigPhotoPopup(photoId) { | ||
showPhotoPopup(); | ||
const currentPhoto = photos.find((photo) => photo.id === Number(photoId)); | ||
if (currentPhoto) { | ||
const comments = renderComments(photoId); | ||
bigPhotoPopup.querySelector('.big-picture__img img').src = currentPhoto.url; | ||
bigPhotoPopup.querySelector('.likes-count').textContent = currentPhoto.likes.length; | ||
bigPhotoPopup.querySelector('.social__comment-shown-count').textContent = currentPhoto.comments.length; | ||
bigPhotoPopup.querySelector('.social__comment-total-count').textContent = currentPhoto.comments.length; | ||
bigPhotoPopup.querySelector('.social__comments').innerHTML = ''; | ||
bigPhotoPopup.querySelector('.social__comments').append(comments); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Чтобы функция renderComments соответствовала своему названию, лучше перенести инструкции на 61, 62 строке внутрь нее |
||
bigPhotoPopup.querySelector('.social__caption').textContent = currentPhoto.description; | ||
hide(bigPhotoPopup.querySelector('.social__comment-shown-count')); | ||
hide(bigPhotoPopup.querySelector('.comments-loader')); | ||
} | ||
} | ||
|
||
popupCancelElement.addEventListener('click', hidePhotoPopup); | ||
|
||
export { openBigPhotoPopup }; |
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,13 @@ | ||
import { renderPictures } from './render-pictures.js'; | ||
import { openBigPhotoPopup } from './big-picture-popup.js'; | ||
|
||
renderPictures(); | ||
|
||
document.addEventListener('click', (e) => { | ||
const currentPicture = e.target.closest('.picture'); | ||
|
||
if (currentPicture) { | ||
e.preventDefault(); | ||
openBigPhotoPopup(currentPicture.dataset.photoId); | ||
} | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так как внутри функции openBigPhotoPopup извлекается объект с данными о фото, в renderComments можно передавать массив с комментариями для того чтобы не запускать цикл .find лишний раз