Skip to content

Commit

Permalink
Merge pull request #7 from harl-i/module7-task1
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Dec 19, 2024
2 parents 9d720aa + 6d02f53 commit caa4afd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,6 @@ <h2 class="data-error__title">Не удалось загрузить данны
</template>

<script src="js/main.js" type="module"></script>
<script src="js/functions.js"></script>
<script src="js/thumbnails.js" type="module"></script>
</body>
</html>
24 changes: 0 additions & 24 deletions js/functions.js

This file was deleted.

6 changes: 4 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {getRandomPhotoObjects} from './photos.js';
import {showThumbnail} from './thumbnails.js';

const OBJECTS_COUNT = 26;

const generatedObjects = getRandomPhotoObjects(OBJECTS_COUNT);
console.log(generatedObjects);
const randomPhotoObjects = getRandomPhotoObjects(OBJECTS_COUNT);

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

function showThumbnail(randomPhotoObjects) {
const fragment = document.createDocumentFragment();

randomPhotoObjects.forEach(({url, description, likes, comments }) => {
const pictureElement = pictureTemplateElement.cloneNode(true);

pictureElement.querySelector('img').src = url;
pictureElement.querySelector('img').alt = description;
pictureElement.querySelector('.picture__comments').textContent = comments.length;
pictureElement.querySelector('.picture__likes').textContent = likes;

fragment.appendChild(pictureElement);
});

picturesContainer.appendChild(fragment);
}

export {showThumbnail};

0 comments on commit caa4afd

Please sign in to comment.