From bc038a10557fe6422c497b6de7817c103597d3e1 Mon Sep 17 00:00:00 2001 From: PavelUd Date: Thu, 21 Dec 2023 00:00:54 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=BF=D0=BE=D0=BF=20=D1=8B=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- js/form.js | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 221d67f..38aa5c3 100644 --- a/index.html +++ b/index.html @@ -35,7 +35,7 @@

Загрузка фотограф
- +
diff --git a/js/form.js b/js/form.js index 190270c..2292948 100644 --- a/js/form.js +++ b/js/form.js @@ -17,6 +17,8 @@ const ErrorMessage = { const uploadButton = document.querySelector('#upload-file'); const form = document.querySelector('.img-upload__form'); const overlay = document.querySelector('.img-upload__overlay'); +const mainImage = overlay.querySelector('.img-upload__preview img'); +const effectsPreviews = overlay.querySelectorAll('.effects__item .effects__preview'); const cancelButton = document.querySelector('#upload-cancel'); const hashtags = document.querySelector('.text__hashtags'); const comments = document.querySelector('.text__description'); @@ -63,12 +65,6 @@ const onCancelButtonClick = () => { closeOverlay(); }; -const isPicture = () => { - const fileType = uploadButton.files[0].type; - - return VALID_IMAGE_TYPES.some((type) => type === fileType); -}; - const blockSubmitButton = () => { submitButton.disabled = true; submitButton.textContent = SubmitButtonText.SENDING; @@ -118,8 +114,16 @@ function closeOverlay () { form.reset(); } +const uploadFile = () => { + const file = uploadButton.files[0]; + mainImage.src = mainImage.src = URL.createObjectURL(file); + effectsPreviews.forEach((picture) => { + picture.style.backgroundImage = `url('${mainImage.src}')`; + }); +}; + const onUploadButtonChange = () => { - if(!isPicture()) {return;} + uploadFile(); overlay.classList.remove('hidden'); document.body.classList.add('modal-open'); form.addEventListener('submit', onFormSubmit); From fa2327cce5800b6adfd75954ffb65fd2fb4f8fbf Mon Sep 17 00:00:00 2001 From: PavelUd Date: Fri, 22 Dec 2023 16:35:10 +0500 Subject: [PATCH 2/2] fix --- js/form.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/form.js b/js/form.js index 2292948..2bd9497 100644 --- a/js/form.js +++ b/js/form.js @@ -7,7 +7,6 @@ import{createEffectSlider, onEffectsFilterChange, resetFilters} from './image-ef const MAX_HASHTAG_LENGTH = 20; const MAX_COMMENT_LENGTH = 140; const MAX_HASHTAG_COUNT = 5; -const VALID_IMAGE_TYPES = ['image/gif', 'image/jpeg', 'image/png']; const HASHTAG_RULE = /^#[А-яа-яA-za-zёЁ]{1,19}$/; const ErrorMessage = { BAD_HASHTAG: 'Уникальные хештеги, каждый не более 20 символов, должны быть разделены пробелом',