From aa1a1f30469c3ad4c98cfdc0fe1c569fc6bb04c0 Mon Sep 17 00:00:00 2001 From: agatemosu Date: Wed, 24 Jul 2024 12:09:52 +0200 Subject: [PATCH] Add images via drop --- script.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/script.js b/script.js index 470eeb0..f04ac97 100644 --- a/script.js +++ b/script.js @@ -39,6 +39,15 @@ document.addEventListener( }, ); +document.addEventListener("drop", (e) => { + e.preventDefault(); + uploadImages(e.dataTransfer.files); +}); + +document.addEventListener("dragover", (e) => { + e.preventDefault(); +}); + function createColorPicker(colorPicker, tierLabel, defaultColor) { const pickr = Pickr.create({ el: colorPicker, @@ -187,6 +196,10 @@ function selectImages() { function uploadImages(files) { for (const file of files) { + if (file.type.split("/")[0] !== "image") { + continue; + } + const image = new Image(); image.src = URL.createObjectURL(file);