Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const COMMENTS = [
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!',
];


const DESCRIPTIONS = [
'Отличный день!',
'Прекрасный вид',
Expand All @@ -21,5 +20,4 @@ const DESCRIPTIONS = [
'Городские джунгли',
];


export { NAMES, COMMENTS, DESCRIPTIONS };
6 changes: 5 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* eslint-disable no-console */

import { getArrayMiniatures } from './createArrayMiniatures.js';
console.log(getArrayMiniatures());
import { renderPictures } from './pictures.js';

const pictures = getArrayMiniatures();
renderPictures(pictures);

43 changes: 43 additions & 0 deletions js/pictures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const picturesContainer = document.querySelector('.pictures');
const pictureTemplate = document.querySelector('#picture').content.querySelector('.picture');

/**
* Создает DOM-элемент миниатюры на основе шаблона #picture
* @param {Object} data - Объект с данными фотографии
* @param {string} data.url - Адрес изображения
* @param {string} data.description - Описание изображения
* @param {number} data.likes - Количество лайков
* @param {Array} data.comments - Массив комментариев
* @returns {HTMLElement} - DOM-элемент миниатюры
*/

const createPictureElement = ({ url, description, likes, comments }) => {
const pictureElement = pictureTemplate.cloneNode(true);

const pictureImg = pictureElement.querySelector('.picture__img');
pictureImg.src = url;
pictureImg.alt = description;

pictureElement.querySelector('.picture__likes').textContent = likes;
pictureElement.querySelector('.picture__comments').textContent = comments.length;

return pictureElement;
};

/**
* Отрисовывает миниатюры фотографий в блок .pictures
* @param {Array} pictures - Массив объектов с данными фотографий
*/
const renderPictures = (pictures) => {
const fragment = document.createDocumentFragment();

pictures.forEach((picture) => {
const pictureElement = createPictureElement(picture);
fragment.appendChild(pictureElement);
});

picturesContainer.innerHTML = '';
picturesContainer.appendChild(fragment);
};

export { renderPictures };
Loading