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: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ <h2 class="img-upload__title visually-hidden">Загрузка фотограф
</div>
</form>
</div>
</section class ="pictures">
</section>

<!-- Здесь будут изображения других пользователей -->

Expand Down
7 changes: 3 additions & 4 deletions js/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const pictureTemplate = document.querySelector('#picture').content.querySelector('.picture');

export const renderPictures = (photos) => {
console.log('Всего фоток:', photos.length);

Check failure on line 7 in js/cards.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected console statement
const fragment = document.createDocumentFragment();

photos.forEach((photo) => {
Expand All @@ -18,15 +18,14 @@
likes.textContent = photo.likes;
comments.textContent = photo.comments.length;

picture.addEventListener('click', (evt) => {

picture.addEventListener('click', (evt) => {

Check failure on line 22 in js/cards.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 4 spaces but found 3
evt.preventDefault();
console.log('!!!')
openModal(photo);
});
});

Check failure on line 25 in js/cards.js

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 4 spaces but found 2

fragment.appendChild(picture);
});

picturesContainerNode.appendChild(fragment);
};

1 change: 0 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ import { getPhotos } from './photos.js';

const photos = getPhotos(PHOTOS_COUNT);
renderPictures(photos);

73 changes: 70 additions & 3 deletions js/modal.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,75 @@


const modalNode = document.querySelector('.big-picture');
const imgContainer = modalNode.querySelector('.big-picture__img');
const bigPictureImg = imgContainer.querySelector('img');
const likesCount = modalNode.querySelector('.likes-count');
const commentsShownCount = modalNode.querySelector('.social__comment-shown-count');
const commentsTotalCount = modalNode.querySelector('.social__comment-total-count');
const commentsList = modalNode.querySelector('.social__comments');
const caption = modalNode.querySelector('.social__caption');
const commentCount = modalNode.querySelector('.social__comment-count');
const commentsLoader = modalNode.querySelector('.comments-loader');
const closeButton = modalNode.querySelector('.big-picture__cancel');

export const openModal = (picture) => {
console.log(picture);

modalNode.classList.remove('hidden');
const closeBigPicture = () => {
modalNode.classList.add('hidden');
document.body.classList.remove('modal-open');
document.removeEventListener('keydown', onDocumentKeydown);
closeButton.removeEventListener('click', onCloseButtonClick);
};

const onDocumentKeydown = (evt) => {
if (evt.key === 'Escape') {
evt.preventDefault();
closeBigPicture();
}
}

const onCloseButtonClick = () => {
closeBigPicture();
};

const renderComments = (comments) => {
commentsList.textContent = '';
comments.forEach((comment) => {
const commentElement = document.createElement('li');
commentElement.classList.add('social__comment');

const img = document.createElement('img');
img.classList.add('social__picture');
img.src = comment.avatar;
img.alt = comment.name;
img.width = 35;
img.height = 35;

const text = document.createElement('p');
text.classList.add('social__text');
text.textContent = comment.message;

commentElement.append(img);
commentElement.append(text);
commentsList.append(commentElement);
});
};


export const openModal = (photo) => {
modalNode.classList.remove('hidden');
document.body.classList.add('modal-open');

bigPictureImg.src = photo.url;
likesCount.textContent = photo.likes;
commentsShownCount.textContent = photo.comments.length;
commentsTotalCount.textContent = photo.comments.length;
caption.textContent = photo.description;

renderComments(photo.comments);
commentCount.classList.add('hidden');
commentsLoader.classList.add('hidden');

closeButton.addEventListener('click', onCloseButtonClick);
document.addEventListener('keydown', onDocumentKeydown);
};

Loading