Skip to content

Commit bf8de5d

Browse files
authored
Merge pull request #15 from Musa-Ismailov/master
2 parents 6f00672 + 6af004e commit bf8de5d

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ <h2 class="big-picture__title visually-hidden">Просмотр фотогра
209209

210210
<!-- Сообщение с ошибкой загрузки изображения -->
211211
<template id="error">
212-
<section class="error">
212+
<section class="error" data-dialog>
213213
<div class="error__inner" data-dialog-content>
214214
<h2 class="error__title">Ошибка загрузки файла</h2>
215215
<button type="button" class="error__button" data-dialog-close>Попробовать ещё раз</button>
@@ -219,7 +219,7 @@ <h2 class="error__title">Ошибка загрузки файла</h2>
219219

220220
<!-- Сообщение об успешной загрузке изображения -->
221221
<template id="success">
222-
<section class="success">
222+
<section class="success" data-dialog-container>
223223
<div class="success__inner" data-dialog-content>
224224
<h2 class="success__title">Изображение успешно загружено</h2>
225225
<button type="button" class="success__button" data-dialog-close>Круто!</button>

js/dialogs.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const errorTemplate = document.querySelector('#error');
88
const successTemplate = document.querySelector('#success');
99
const dataErrorTemplate = document.querySelector('#data-error');
1010

11-
const onCloseKeydown = (evt) => {
11+
const onDocumentKeydown = (evt) => {
1212
if (isEscapeKey(evt.key) && currentDialog) {
1313
evt.preventDefault();
1414
closeDialog();
@@ -21,27 +21,27 @@ function closeDialog () {
2121
currentDialog.remove();
2222
currentDialog = null;
2323

24-
document.removeEventListener('keydown', onCloseKeydown, true);
24+
document.removeEventListener('keydown', onDocumentKeydown, true);
2525
}
2626
}
2727

28-
const onCloseClick = (evt) => {
28+
const onDocumentClick = (evt) => {
2929
if (evt.target.closest('[data-dialog-close]') || !evt.target.closest('[data-dialog-content]')) {
3030
closeDialog();
3131
}
3232
};
3333

3434
const openDialog = (template) => {
35-
const dialogElement = template.content.firstElementChild.cloneNode(true);
35+
const dialogElement = template.content.querySelector('[data-dialog-container]').cloneNode(true);
3636

3737
document.body.appendChild(dialogElement);
3838

3939
currentDialog = dialogElement;
4040

41-
document.addEventListener('keydown', onCloseKeydown, true);
41+
document.addEventListener('keydown', onDocumentKeydown, true);
4242
};
4343

44-
document.addEventListener('click', onCloseClick);
44+
document.addEventListener('click', onDocumentClick);
4545

4646
export const showError = () => {
4747
openDialog(errorTemplate);
@@ -52,7 +52,7 @@ export const showSuccess = () => {
5252
};
5353

5454
export const showDataError = () => {
55-
const errorElement = dataErrorTemplate.content.firstElementChild.cloneNode(true);
55+
const errorElement = dataErrorTemplate.content.querySelector('.data-error').cloneNode(true);
5656

5757
document.body.appendChild(errorElement);
5858

js/filters.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,33 @@ const getFilteredData = (filterId) => {
2828
case filterName.FILTER_DISCUSSED:
2929
return sortByCommentsCount(galleryData);
3030

31-
case filterName.FILTER_DEFAULT:
3231
default:
3332
return galleryData;
3433
}
3534
};
3635

37-
const handleFilterClick = (evt) => {
36+
const debouncedRenderGallery = debounce((filterId) => {
37+
const filteredData = getFilteredData(filterId);
38+
clearGallery();
39+
renderGallery(filteredData);
40+
}, RERENDER_DELAY);
41+
42+
const onFilterClick = (evt) => {
3843
const button = evt.target.closest('.img-filters__button');
3944

4045
if (!button) {
4146
return;
4247
}
4348

44-
if (activeFilterButton) {
45-
activeFilterButton.classList.remove('img-filters__button--active');
46-
}
49+
activeFilterButton?.classList.remove('img-filters__button--active');
4750

4851
button.classList.add('img-filters__button--active');
4952
activeFilterButton = button;
5053

51-
const filteredData = getFilteredData(button.id);
52-
53-
clearGallery();
54-
55-
debounce(() => renderGallery(filteredData), RERENDER_DELAY)();
54+
debouncedRenderGallery(button.id);
5655
};
5756

5857
export const initFilters = () => {
5958
filtersContainer.classList.remove('img-filters--inactive');
60-
filtersContainer.addEventListener('click', handleFilterClick);
59+
filtersContainer.addEventListener('click', onFilterClick);
6160
};

js/fullscreen-picture.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const bigPictureClosedElement = bigPicture.querySelector('.cancel');
1313
const socialComments = document.querySelector('.social__comments');
1414
const bigPictureCommentsLoader = bigPicture.querySelector('.comments-loader');
1515

16-
let visibleСomments = COMMENTS_SHOWN;
16+
let visibleComments = COMMENTS_SHOWN;
1717
let currentPhotoData = null;
1818

1919
const onDocumentKeydown = (evt) => {
@@ -28,7 +28,7 @@ export function closePhotoModal () {
2828
document.body.classList.remove('modal-open');
2929
document.removeEventListener('keydown', onDocumentKeydown);
3030

31-
visibleСomments = COMMENTS_SHOWN;
31+
visibleComments = COMMENTS_SHOWN;
3232
currentPhotoData = null;
3333
bigPictureShownCount.textContent = DEFAULT_COMMENTS_COUNT;
3434
bigPictureTotalCount.textContent = DEFAULT_COMMENTS_COUNT;
@@ -70,7 +70,7 @@ const updateComments = () => {
7070
socialComments.innerHTML = '';
7171

7272
const totalComments = currentPhotoData.comments.length;
73-
const commentsToShow = Math.min(visibleСomments, totalComments);
73+
const commentsToShow = Math.min(visibleComments, totalComments);
7474
const limitedComments = currentPhotoData.comments.slice(0, commentsToShow);
7575

7676
renderComments(limitedComments);
@@ -79,7 +79,7 @@ const updateComments = () => {
7979

8080
bigPictureCommentsLoader.classList.toggle('hidden', commentsToShow >= totalComments);
8181

82-
visibleСomments += COMMENTS_SHOWN;
82+
visibleComments += COMMENTS_SHOWN;
8383
};
8484

8585
export const openBigPicture = (photoData) => {

0 commit comments

Comments
 (0)