Skip to content

Commit

Permalink
Merge pull request #6 from SergeyMedved/module7-task1
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Dec 6, 2024
2 parents 03cbb7a + e8ec4b8 commit eeab96d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 82 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ <h2 class="success__title">Изображение успешно загруже
<h2 class="data-error__title">Не удалось загрузить данные</h2>
</section>
</template>
<script src="js/functions.js"></script>
<script src="js/main.js" type="module"></script>
</body>
</html>
78 changes: 0 additions & 78 deletions js/functions.js

This file was deleted.

5 changes: 2 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createPhotos } from './data.js';
import { appendPhotos } from './preview.js';

const result = createPhotos(25);

console.log(result);
appendPhotos(createPhotos(25));
24 changes: 24 additions & 0 deletions js/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const appendPhotos = (data) => {

const picturesElement = document.querySelector('.pictures');
const pictureTemplate = document.querySelector('#picture').content;
const photosFragment = new DocumentFragment();

data.forEach(({id, url, description, likes, comments}) => {
const clonedPicture = pictureTemplate.cloneNode(true);
const imgElement = clonedPicture.querySelector('.picture__img');
const likesElement = clonedPicture.querySelector('.picture__likes');
const commentsElement = clonedPicture.querySelector('.picture__comments');
imgElement.dataset.id = id;
imgElement.src = url;
imgElement.alt = description;
likesElement.textContent = likes;
commentsElement.textContent = comments.length;
photosFragment.appendChild(clonedPicture);
});

picturesElement.appendChild(photosFragment);

};

export { appendPhotos };

0 comments on commit eeab96d

Please sign in to comment.