diff --git a/js/api/get-data-variables.js b/js/api/get-data-variables.js index 873ce75..719fc9a 100644 --- a/js/api/get-data-variables.js +++ b/js/api/get-data-variables.js @@ -2,7 +2,7 @@ export const dataErrorTemplate = document.querySelector('#data-error').content.q export const sendErrorTemplate = document.querySelector('#error').content.querySelector('.error'); export const sendFormErrorTemplate = document.querySelector('#success').content.querySelector('.success'); export const SHOW_ERROR_TIME = 5000; -export const BASE_URL = 'https://31.javascript.htmlacademy.pro/kekstagram'; +export const BASE_URL = 'https://31.javascript.htmlacademy.pro/kekstagra'; export const Route = { GET_DATA: '/data', SEND_DATA: '/', diff --git a/js/api/secondary-functions.js b/js/api/secondary-functions.js index 5498e9f..ca8954e 100644 --- a/js/api/secondary-functions.js +++ b/js/api/secondary-functions.js @@ -1,5 +1,6 @@ import {onCloseChangePhotoEsc} from '../upload-photo'; import {dataErrorTemplate, sendErrorTemplate, sendFormErrorTemplate, SHOW_ERROR_TIME, submitButtonText} from './get-data-variables'; +import {isEscapeKey} from '../util'; const submitButton = document.querySelector('.img-upload__submit'); @@ -7,6 +8,7 @@ function onSendSuccessClose() { const successMessage = document.querySelector('.success'); successMessage.remove(); document.removeEventListener('click', onClickOutModalSuccess); + document.removeEventListener('keydown', onSendSuccessMessageCloseEsc); } const onSendErrorMessageClose = () => { @@ -31,14 +33,14 @@ function onClickOutModalError (evt) { onSendErrorMessageClose(); } -function onSendErrorMessageCloseEsc (evt) { - if (evt.key === 'Escape') { +function onSendErrorMessageCloseEsc () { + if (isEscapeKey) { onSendErrorMessageClose(); } } -function onSendSuccessMessageCloseEsc (evt) { - if (evt.key === 'Escape') { +function onSendSuccessMessageCloseEsc () { + if (isEscapeKey) { onSendSuccessClose(); } } diff --git a/js/filters/index.js b/js/filters/index.js index 5d0fb78..82b8244 100644 --- a/js/filters/index.js +++ b/js/filters/index.js @@ -11,7 +11,7 @@ const showFilterPanel = () => { const debounceRender = debounce(addPhotoThumbnailsUsers); -const setActiveFilter = (evt) => { +const onSetActiveFilter = (evt) => { const target = evt.target; const activeButton = document.querySelector('.img-filters__button--active'); @@ -44,7 +44,7 @@ function filterChange () { } const listenerButtonsFilter = (photos) => { - filtersControlPanel.addEventListener('click', setActiveFilter); + filtersControlPanel.addEventListener('click', onSetActiveFilter); showFilterPanel(); puctures = photos; }; diff --git a/js/show-large-picture/elementVariables.js b/js/show-large-picture/elementVariables.js index 8270a5a..9792cfe 100644 --- a/js/show-large-picture/elementVariables.js +++ b/js/show-large-picture/elementVariables.js @@ -1,5 +1,5 @@ export const bigPictureBlock = document.querySelector('.big-picture'); -export const bigPictureCancel = document.querySelector('.big-picture__cancel'); +export const bigPictureCancel = bigPictureBlock.querySelector('.big-picture__cancel'); export const bigPictureImg = bigPictureBlock.querySelector('.big-picture__img img'); export const likesCount = bigPictureBlock.querySelector('.likes-count'); export const commentTotalCount = bigPictureBlock.querySelector('.social__comment-total-count'); diff --git a/js/show-large-picture/index.js b/js/show-large-picture/index.js index c178a5a..0d9675c 100644 --- a/js/show-large-picture/index.js +++ b/js/show-large-picture/index.js @@ -1,6 +1,6 @@ import { bigPictureBlock, bigPictureCancel, bigPictureImg, likesCount, commentTotalCount, socialCaption, socialCommentsList, buttonShowMore} from './elementVariables'; import {renderComments, onShowMoreComments} from './createComments'; -import {toggleClass} from '../util'; +import {toggleClass, isEscapeKey} from '../util'; const onCloseBigPicture = () => { toggleClass(bigPictureBlock, false); @@ -28,7 +28,7 @@ const onOpenBigPicture = (element) => { }; function onCloseBigPictureEsc(evt){ - if(evt.key === 'Escape'){ + if(isEscapeKey){ evt.preventDefault(); onCloseBigPicture(); } diff --git a/js/upload-photo/index.js b/js/upload-photo/index.js index d2a3803..2ef72be 100644 --- a/js/upload-photo/index.js +++ b/js/upload-photo/index.js @@ -1,4 +1,4 @@ -import {toggleClass} from '../util'; +import {toggleClass, isEscapeKey} from '../util'; import {pristine} from '../validation-form'; import {imgUploadInput, imgUpoadOverlay, imgUploadancel, effectsPreview, effectLevelSliderParrent, uploadPreviewImage, FILE_TYPES} from './uploadPhotoVariables'; import {inputTextHashtag, commentForm, imgUploadForm} from '../validation-form'; @@ -15,7 +15,7 @@ const onCloseChangePhoto = () => { }; function onCloseChangePhotoEsc(evt){ - if (evt.key === 'Escape' && !(document.activeElement === inputTextHashtag || document.activeElement === commentForm)) { + if (isEscapeKey && !(document.activeElement === inputTextHashtag || document.activeElement === commentForm)) { onCloseChangePhoto(); } else { evt.stopPropagation(); diff --git a/js/util/index.js b/js/util/index.js index 7f6a3cd..7b59e54 100644 --- a/js/util/index.js +++ b/js/util/index.js @@ -30,4 +30,6 @@ const debounce = (callback, timeoutDelay = TIMEOUT_DELAY_DEBOUNCE) => { }; }; -export {getRandomInteger, createId, getRandomArrayElement, toggleClass, debounce}; +const isEscapeKey = (evt) => evt.key === 'Escape'; + +export {getRandomInteger, createId, getRandomArrayElement, toggleClass, debounce, isEscapeKey};