-
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 #5 from vikkont79/module7-task1
- Loading branch information
Showing
5 changed files
with
66 additions
and
93 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 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,3 +1,6 @@ | ||
import { createGallery } from './data.js'; | ||
import { renderGallery } from './view.js'; | ||
|
||
createGallery(); | ||
const photosPreview = createGallery(25); | ||
|
||
renderGallery(photosPreview); |
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,35 @@ | ||
// Проверка на максимальную длину строки | ||
|
||
const checkStringLength = (string, maxLength) => string.length <= maxLength; | ||
|
||
// Определяем рандомное значение | ||
|
||
const getRandomInteger = (min, max) => | ||
Math.floor(Math.random() * (max - min + 1) + min); | ||
|
||
// Проверяем его на уникальность (возвращаем рандомное значение, ранее не использованое в блоке) | ||
|
||
const getRandomUniqueInteger = (min, max) => { | ||
const uniqueIntArr = []; | ||
return () => { | ||
while (uniqueIntArr.length < max - min + 1) { | ||
const randomInt = getRandomInteger(min, max); | ||
if (!uniqueIntArr.includes(randomInt)) { | ||
uniqueIntArr.push(randomInt); | ||
return randomInt; | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
// Получаем рандомный элемент любого массива | ||
|
||
const getRandomArrayElement = (elements) => | ||
elements[getRandomInteger(0, elements.length - 1)]; | ||
|
||
export { | ||
getRandomInteger, | ||
checkStringLength, | ||
getRandomUniqueInteger, | ||
getRandomArrayElement, | ||
}; |
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,25 @@ | ||
const renderGallery = (gallery) => { | ||
const picturesContainerElement = document.querySelector('.pictures'); | ||
const pictureTemplateElement = document | ||
.querySelector('#picture') | ||
.content.querySelector('.picture'); | ||
const pictureFragment = document.createDocumentFragment(); | ||
|
||
gallery.forEach(({ id, url, description, likes, comments }) => { | ||
const pictureElement = pictureTemplateElement.cloneNode(true); | ||
const imgElement = pictureElement.querySelector('.picture__img'); | ||
const likesElement = pictureElement.querySelector('.picture__likes'); | ||
const commentsElement = pictureElement.querySelector('.picture__comments'); | ||
pictureElement.href = url; | ||
pictureElement.dataset.id = id; | ||
imgElement.src = url; | ||
imgElement.alt = description; | ||
likesElement.textContent = likes; | ||
commentsElement.textContent = comments.length; | ||
pictureFragment.appendChild(pictureElement); | ||
}); | ||
|
||
picturesContainerElement.appendChild(pictureFragment); | ||
}; | ||
|
||
export { renderGallery }; |