From 61a30f8b2b295cd57e814b8864e0e5b238dfffaf Mon Sep 17 00:00:00 2001 From: Elvira Solovyova Date: Mon, 13 Feb 2023 10:48:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/api.js | 4 ++-- js/form.js | 26 +++++++++++++------------- js/picture-editing.js | 3 +-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/js/api.js b/js/api.js index de2cb1b..f204654 100644 --- a/js/api.js +++ b/js/api.js @@ -1,5 +1,5 @@ const getData = (onSuccess) => { - fetch('https://25.javascript.pages.academy/kekstagram/data') + fetch('https://25.javascript.pages.academy/kekstagram/data') .then((response) => response.json()) .then((posts) => { onSuccess(posts); @@ -21,7 +21,7 @@ const sendData = (onSuccess, onFail, body) => { }) .catch((err) => { onFail(err.message); - }); + }); }; export { getData, sendData }; diff --git a/js/form.js b/js/form.js index bad3bfb..c4bb56d 100644 --- a/js/form.js +++ b/js/form.js @@ -16,6 +16,18 @@ const MIN_HASHTAG_LENGTH = 2; const MAX_HASHTAG_LENGTH = 20; const UNVALID_SYMBOLS = /[^a-zA-Z0-9а-яА-ЯёЁ]/g; +const closeUploadOverlay = () => { + form.reset(); + pristine.reset(); + uploadOverlay.classList.add('hidden'); + body.classList.remove('modal-open'); + document.removeEventListener('keydown', onEscKeydown); +}; + +const isTextFieldFocused = () => + document.activeElement === hashtags || + document.activeElement === comment; + const onEscKeydown = (evt) => { if (isEscapeKey(evt) && !isTextFieldFocused()) { evt.preventDefault(); @@ -23,7 +35,7 @@ const onEscKeydown = (evt) => { } }; -let pristine = new Pristine(form, { +const pristine = new Pristine(form, { classTo: 'img-upload__element', errorTextParent: 'img-upload__element', errorTextClass: 'img-upload__error' @@ -35,18 +47,6 @@ const openUploadOverlay = () => { document.addEventListener('keydown', onEscKeydown); }; -const closeUploadOverlay = () => { - form.reset(); - pristine.reset(); - uploadOverlay.classList.add('hidden'); - body.classList.remove('modal-open'); - document.removeEventListener('keydown', onEscKeydown); -}; - -const isTextFieldFocused = () => - document.activeElement === hashtags || - document.activeElement === comment; - const startsWithHash = (string) => string[0] === '#'; const hasValidLength = (string) => diff --git a/js/picture-editing.js b/js/picture-editing.js index ce6bd78..48de76c 100644 --- a/js/picture-editing.js +++ b/js/picture-editing.js @@ -63,6 +63,7 @@ const EFFECTS = [ const DEFAULT_EFFECT = EFFECTS[0]; let chosenEffect = DEFAULT_EFFECT; +const isDefault = () => chosenEffect === DEFAULT_EFFECT; noUiSlider.create(slider, { range: { @@ -98,8 +99,6 @@ const onFormChange = (evt) => { updateSlider(chosenEffect); }; -const isDefault = () => chosenEffect === DEFAULT_EFFECT; - const onSliderUpdate = () => { image.style.filter = 'none'; image.className = '';