-
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 #12 from aLesya66/module8-task1
- Loading branch information
Showing
7 changed files
with
119 additions
and
41 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const template = document.querySelector('#picture').content.querySelector('.picture'); | ||
const container = document.querySelector('.pictures'); | ||
|
||
const fragment = document.createDocumentFragment(); | ||
const renderThumbs = (dataThumbs) => { | ||
dataThumbs.forEach(({id, url, description, comments, likes}) => { | ||
const copy = template.cloneNode(true); | ||
copy.querySelector('.picture__img').src = url; | ||
copy.querySelector('.picture__img').alt = description; | ||
copy.querySelector('.picture__comments').textContent = comments.length; | ||
copy.querySelector('.picture__likes').textContent = likes; | ||
copy.dataset.id = id; | ||
container.append(copy); | ||
}); | ||
}; | ||
|
||
container.appendChild(fragment); | ||
|
||
export{renderThumbs}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {isEscapeKey, isEnterKey} from './rand.js'; | ||
import {dataThumbs} from './main.js'; | ||
import {createSocialComment} from './mas.js'; | ||
|
||
const bigPicture = document.querySelector('.big-picture'); | ||
const closePicture = document.querySelector('.big-picture__cancel'); | ||
const container = document.querySelector('.pictures'); | ||
const bigPictureImg = document.querySelector('.big-picture__img').querySelector('img'); | ||
const likesCount = document.querySelector('.likes-count'); | ||
const commentsContainer = bigPicture.querySelector('.social__comments'); | ||
const socialCommentTotalCount = document.querySelector('.social__comment-total-count'); | ||
const photoCaption = bigPicture.querySelector('.social__caption'); | ||
const loadCommentsButton = bigPicture.querySelector('.comments-loader'); | ||
|
||
const onDocumentKeydown = (evt) => { | ||
if (isEscapeKey(evt)) { | ||
evt.preventDefault(); | ||
closePictureModal(); | ||
loadCommentsButton.classList.add('hidden'); | ||
} | ||
}; | ||
|
||
function openPictureModal() { | ||
bigPicture.classList.remove('hidden'); | ||
document.addEventListener('keydown', onDocumentKeydown); | ||
} | ||
|
||
container.addEventListener('click', (evt) => { | ||
if (evt.target.closest('.picture')) { | ||
const actualDescription = dataThumbs.find((element) => element.id === parseInt(evt.target.closest('.picture').dataset.id, 10)); | ||
openPictureModal(); | ||
bigPictureImg.src = actualDescription.url; | ||
likesCount.textContent = actualDescription.likes; | ||
socialCommentTotalCount.textContent = actualDescription.comments.length; | ||
photoCaption.textContent = actualDescription.description; | ||
document.body.classList.add('modal-open'); | ||
createSocialComment(actualDescription.comments, commentsContainer); | ||
} | ||
}); | ||
|
||
container.addEventListener('keydown', (evt) => { | ||
if (isEnterKey(evt)) { | ||
openPictureModal(); | ||
} | ||
}); | ||
|
||
|
||
function closePictureModal() { | ||
bigPicture.classList.add('hidden'); | ||
document.removeEventListener('keydown', onDocumentKeydown); | ||
} | ||
|
||
closePicture.addEventListener('click', () => { | ||
closePictureModal(); | ||
}); | ||
|
||
closePicture.addEventListener('keydown', (evt) => { | ||
if (isEnterKey(evt)) { | ||
closePictureModal(); | ||
} | ||
}); | ||
|
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,2 +1,7 @@ | ||
import {similarFinalMas} from './createMiniature.js'; | ||
similarFinalMas(); | ||
import './full-picture.js'; | ||
import {renderThumbs} from './create-miniature.js'; | ||
import { finalMas } from './mas.js'; | ||
|
||
const dataThumbs = finalMas();renderThumbs(dataThumbs); | ||
export {dataThumbs}; | ||
|
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