-
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.
Отрисуй меня полностью (правки неймига, стрелочные функции)
- Loading branch information
1 parent
d3914af
commit 26b8275
Showing
6 changed files
with
31 additions
and
83 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import {createPosts} from './data.js'; | ||
import {createFragmentElement} from './thumbnails.js'; | ||
import {createFragment} from './thumbnails.js'; | ||
|
||
createFragmentElement(createPosts()); | ||
const posts = createPosts(); | ||
createFragment(posts); |
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,28 +1,28 @@ | ||
const pictureTemplateElement = document.querySelector('#picture').content.querySelector('.picture'); | ||
const pictureContainerElement = document.querySelector('.pictures'); | ||
const pictureFragmentElement = document.createDocumentFragment(); | ||
const templateElement = document.querySelector('#picture').content.querySelector('.picture'); | ||
const containerElement = document.querySelector('.pictures'); | ||
const fragmentElement = document.createDocumentFragment(); | ||
|
||
//Функция создания перевью | ||
const createThumbnailElement = function (picture) { | ||
const pictureThumbnailElement = pictureTemplateElement.cloneNode(true); | ||
const pictureImageElement = pictureThumbnailElement.querySelector('.picture__img'); | ||
pictureThumbnailElement.href = picture.url; | ||
pictureThumbnailElement.dataset.id = picture.id; | ||
pictureImageElement.src = picture.url; | ||
pictureImageElement.alt = picture.description; | ||
pictureThumbnailElement.querySelector('.picture__likes').textContent = picture.likes; | ||
pictureThumbnailElement.querySelector('.picture__comments').textContent = picture.comments.length; | ||
return pictureThumbnailElement; | ||
const createThumbnail = (picture) => { | ||
const thumbnailElement = templateElement.cloneNode(true); | ||
const imageElement = thumbnailElement.querySelector('.picture__img'); | ||
thumbnailElement.href = picture.url; | ||
thumbnailElement.dataset.id = picture.id; | ||
imageElement.src = picture.url; | ||
imageElement.alt = picture.description; | ||
thumbnailElement.querySelector('.picture__likes').textContent = picture.likes; | ||
thumbnailElement.querySelector('.picture__comments').textContent = picture.comments.length; | ||
return thumbnailElement; | ||
}; | ||
|
||
//Проходимся по массиву данных и создадим первью для каждого элемента функцией | ||
const createFragmentElement = function (data) { | ||
const createFragment = (data) => { | ||
data.forEach((picture) => { | ||
const pictureThumbnailElement = createThumbnailElement(picture); | ||
pictureFragmentElement.appendChild(pictureThumbnailElement); | ||
const thumbnailElement = createThumbnail(picture); | ||
fragmentElement.appendChild(thumbnailElement); | ||
}); | ||
|
||
pictureContainerElement.appendChild(pictureFragmentElement); | ||
containerElement.appendChild(fragmentElement); | ||
}; | ||
|
||
export {createFragmentElement}; | ||
export {createFragment}; |
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