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
13 changes: 7 additions & 6 deletions js/check-hashtag-validity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ const hasValidHashtagCount = (value) =>
const hasValidHashtagLength = (value) =>
normalizeHashtags(value).every((hashtag) => hashtag.length <= MAX_HASHTAG_LENGTH);

const hasValidHashtagFormat = (value) =>
normalizeHashtags(value).every((hashtag) =>
hashtag.startsWith('#') &&
hashtag.length > 1 &&
HASHTAG_REGEXP.test(hashtag)
);
const hasValidHashtagFormat = (value) => {
const hashtags = normalizeHashtags(value);
if (hashtags.length === 0) {
return true;
}
return hashtags.every((hashtag) => HASHTAG_REGEXP.test(hashtag));
};

const hasUniqueHashtags = (value) => {
const hashtags = normalizeHashtags(value);
Expand Down
75 changes: 0 additions & 75 deletions js/create-array-photos.js

This file was deleted.

48 changes: 0 additions & 48 deletions js/data.js

This file was deleted.

42 changes: 23 additions & 19 deletions js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,41 @@ const FilterId = {
DISCUSSED: 'filter-discussed',
};

const filtersSection = document.querySelector('.img-filters');
const filtersForm = document.querySelector('.img-filters__form');
const filtersSectionNode = document.querySelector('.img-filters');
const filtersFormNode = document.querySelector('.img-filters__form');

let currentFilter = FilterId.DEFAULT;
let photos = [];
let loadedPhotos = [];

const getRandomPhotos = (photosArray) => {
const shuffled = [...photosArray].sort(() => Math.random() - 0.5);
const getRandomPhotos = (photos) => {
const shuffled = [...photos];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled.slice(0, RANDOM_PHOTOS_COUNT);
};

const getDiscussedPhotos = (photosArray) =>
[...photosArray].sort((a, b) => b.comments.length - a.comments.length);
const getDiscussedPhotos = (photos) =>
[...photos].sort((a, b) => b.comments.length - a.comments.length);

const filterPhotos = () => {
switch (currentFilter) {
case FilterId.RANDOM:
return getRandomPhotos(photos);
return getRandomPhotos(loadedPhotos);
case FilterId.DISCUSSED:
return getDiscussedPhotos(photos);
return getDiscussedPhotos(loadedPhotos);
default:
return [...photos];
return [...loadedPhotos];
}
};

const updateActiveButton = (clickedButton) => {
const activeButton = filtersForm.querySelector(`.${ACTIVE_BUTTON_CLASS}`);
if (activeButton) {
activeButton.classList.remove(ACTIVE_BUTTON_CLASS);
const updateActiveButton = (clickedButtonNode) => {
const activeButtonNode = filtersFormNode.querySelector(`.${ACTIVE_BUTTON_CLASS}`);
if (activeButtonNode) {
activeButtonNode.classList.remove(ACTIVE_BUTTON_CLASS);
}
clickedButton.classList.add(ACTIVE_BUTTON_CLASS);
clickedButtonNode.classList.add(ACTIVE_BUTTON_CLASS);
};

const debouncedRenderThumbnails = debounce(
Expand All @@ -66,13 +70,13 @@ const onFilterButtonClick = (evt) => {
};

const showFilters = () => {
filtersSection.classList.remove('img-filters--inactive');
filtersSectionNode.classList.remove('img-filters--inactive');
};

const initFilters = (loadedPhotos) => {
photos = loadedPhotos;
const initFilters = (photos) => {
loadedPhotos = photos;
showFilters();
filtersForm.addEventListener('click', onFilterButtonClick);
filtersFormNode.addEventListener('click', onFilterButtonClick);
};

export { initFilters };
18 changes: 9 additions & 9 deletions js/full-size-picture.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ const likesCountNode = bigPictureNode.querySelector('.likes-count');
const commentsCaptionNode = bigPictureNode.querySelector('.social__caption');
const bigPictureCancelNode = bigPictureNode.querySelector('.big-picture__cancel');

const onEscKeydown = (evt) => {
const handlers = {};

handlers.onEscKeydown = (evt) => {
if (evt.key === 'Escape') {
evt.preventDefault();
clearComments();
bigPictureNode.classList.add('hidden');
document.body.classList.remove('modal-open');
document.removeEventListener('keydown', onEscKeydown);
handlers.closeBigPicture();
}
};

const closeBigPicture = () => {
handlers.closeBigPicture = () => {
clearComments();
bigPictureNode.classList.add('hidden');
document.body.classList.remove('modal-open');
document.removeEventListener('keydown', onEscKeydown);
document.removeEventListener('keydown', handlers.onEscKeydown);
};


const onBigPictureCancelClick = (evt) => {
evt.preventDefault();
closeBigPicture();
handlers.closeBigPicture();
};

const openBigPicture = (pictureId) => {
Expand All @@ -51,7 +51,7 @@ const openBigPicture = (pictureId) => {

bigPictureNode.classList.remove('hidden');
document.body.classList.add('modal-open');
document.addEventListener('keydown', onEscKeydown);
document.addEventListener('keydown', handlers.onEscKeydown);
};

bigPictureCancelNode.addEventListener('click', onBigPictureCancelClick);
Expand Down
68 changes: 0 additions & 68 deletions js/functions.js

This file was deleted.

4 changes: 3 additions & 1 deletion js/image-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ const onEffectsListChange = (evt) => {
return;
}

updateSliderOptions(evt.target.value);
const effectName = evt.target.value;
updateSliderOptions(effectName);
applyEffect(effectName, effectsConfig[effectName].start);
};

const onEffectLevelSliderUpdate = () => {
Expand Down
Loading
Loading