From 216b4d7a1a0d303b42a50b3c2bd3b8516aeb4ad1 Mon Sep 17 00:00:00 2001 From: "rit1992@mail.ru" <158091165+margarita0206@users.noreply.github.com> Date: Sun, 4 Aug 2024 20:17:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=BE=D1=82=D0=BE=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=BC=D1=8F=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/load-pictures.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/js/load-pictures.js b/js/load-pictures.js index 8b13789..fb27366 100644 --- a/js/load-pictures.js +++ b/js/load-pictures.js @@ -1 +1,19 @@ +import { FILE_TYPES } from './constant.js'; +const imgUploadPreview = document.querySelector('.img-upload__preview img'); +const fileChooser = document.querySelector('.img-upload__start input[type=file]'); + +const loadingPicture = () => { + fileChooser.addEventListener('change', () => { + const file = fileChooser.files[0]; + const fileName = file.name.toLowerCase(); + + const matches = FILE_TYPES.some((it) => fileName.endsWith(it)); + + if (matches) { + imgUploadPreview.src = URL.createObjectURL(file); + } + }); +}; + +export { loadingPicture };