Skip to content
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

Отрисуй меня полностью #7

Merged
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
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<title>Кекстаграм</title>
<script head="text/javascript" src="js/functions.js"></script>
<script src="js/main.js" type="module"></script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion js/data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createIdGenerator, getRandomInteger, getRandomArrayElement } from './util';
import { createIdGenerator, getRandomInteger, getRandomArrayElement } from './util.js';

const COMMENT_MESSAGES = [
'Всё отлично!',
Expand Down
56 changes: 0 additions & 56 deletions js/functions.js

This file was deleted.

4 changes: 1 addition & 3 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import { createArrayPhotos } from './data';

createArrayPhotos();
import './miniaturePicture.js';
35 changes: 35 additions & 0 deletions js/miniaturePicture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createArrayPhotos } from './data.js';

const photosData = createArrayPhotos();

const pictureTemplate = document.querySelector('#picture').content.querySelector('.picture');

const picturesFragmetn = document.querySelector('.pictures');

function createMiniPicture(currentPhoto) {
const clonePicture = pictureTemplate.cloneNode(true);
const imgClonePicture = clonePicture.querySelector('.picture__img');

imgClonePicture.src = currentPhoto.url;
imgClonePicture.alt = currentPhoto.description;

const pictureInfo = clonePicture.querySelector('.picture__info');
pictureInfo.querySelector('.picture__likes').textContent = currentPhoto.likes;
pictureInfo.querySelector('.picture__comments').textContent = currentPhoto.comments.length;

return clonePicture;
}

function startCreateMiniPicture(photosArray) {
const pictureListFragment = document.createDocumentFragment();

for (let i = 0; i < photosArray.length; i++) {
const clonePicture = createMiniPicture(photosArray[i]);
pictureListFragment.appendChild(clonePicture);
}

picturesFragmetn.appendChild(pictureListFragment);
}

startCreateMiniPicture(photosData);

2 changes: 1 addition & 1 deletion js/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function createIdGenerator() {
let lastGeneratedId = 0;
let lastGeneratedId = 1; // тут 1, вместо 0, т.к. имена фотографий начинаются с 1, а не с 0

return function() {
return lastGeneratedId++;
Expand Down
Loading