From 9f296ce1c46d7fd69096fe48e77f288b7c4896fb Mon Sep 17 00:00:00 2001 From: jdev082 Date: Wed, 16 Aug 2023 18:36:24 -0500 Subject: [PATCH] feat: make dropping a file on UI open the file in current tab --- src/dropHandler.js | 24 ++++++++++++++++++++++++ src/index.html | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/dropHandler.js diff --git a/src/dropHandler.js b/src/dropHandler.js new file mode 100644 index 00000000..96b62302 --- /dev/null +++ b/src/dropHandler.js @@ -0,0 +1,24 @@ +function dropHandler(ev) { + console.log("File(s) dropped"); + + ev.preventDefault(); + + if (ev.dataTransfer.items) { + [...ev.dataTransfer.items].forEach((item, i) => { + if (item.kind === "file") { + const file = item.getAsFile(); + document.querySelector('.current').src = file.path; + } + }); + } else { + alert('File type unsupported.') + } + } + + + function dragOverHandler(ev) { + console.log("File(s) in drop zone"); + + ev.preventDefault(); + } + \ No newline at end of file diff --git a/src/index.html b/src/index.html index 6ece6c7b..6c105569 100644 --- a/src/index.html +++ b/src/index.html @@ -6,11 +6,12 @@ + - +
loading...