From b95643e1a6f4283e3ae4aa86b92741b4329b0b6b Mon Sep 17 00:00:00 2001 From: Nachtalb Date: Thu, 6 May 2021 02:48:07 +0200 Subject: [PATCH] Allow text drag & drop into text fields We only have to stop the defualt behaviour in case we drag & drop a file (for uploading) --- client/js/upload.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/client/js/upload.js b/client/js/upload.js index faec57e6..e5e3e6f9 100644 --- a/client/js/upload.js +++ b/client/js/upload.js @@ -26,31 +26,36 @@ class Uploader { } dragOver(event) { - // Prevent dragover event completely and do nothing with it - // This stops the browser from trying to guess which cursor to show - event.preventDefault(); + if (event.dataTransfer.types.includes("Files")) { + // Prevent dragover event completely and do nothing with it + // This stops the browser from trying to guess which cursor to show + event.preventDefault(); + } } dragEnter(event) { - event.preventDefault(); - // relatedTarget is the target where we entered the drag from // when dragging from another window, the target is null, otherwise its a DOM element if (!event.relatedTarget && event.dataTransfer.types.includes("Files")) { + event.preventDefault(); + this.overlay.classList.add("is-dragover"); } } dragLeave(event) { - event.preventDefault(); - // If relatedTarget is null, that means we are no longer dragging over the page if (!event.relatedTarget) { + event.preventDefault(); this.overlay.classList.remove("is-dragover"); } } drop(event) { + if (!event.dataTransfer.types.includes("Files")) { + return; + } + event.preventDefault(); this.overlay.classList.remove("is-dragover");