From 01fb49549b5eaa6254f7809e990e3bf8464e5d71 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Mon, 22 Mar 2021 01:08:42 +0000 Subject: [PATCH] fup: add drag and drop uploads There's no UI indication that this is happening yet, but... --- web/fup/fupstatic/js/base.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/web/fup/fupstatic/js/base.js b/web/fup/fupstatic/js/base.js index a665b41b2f..7bbeeb2994 100644 --- a/web/fup/fupstatic/js/base.js +++ b/web/fup/fupstatic/js/base.js @@ -118,4 +118,32 @@ if (document.body.classList.contains('upload-page')) { uploadFile(file, expiryEl.value); } }); + + document.body.addEventListener('dragenter', (e) => { + e.preventDefault(); + e.stopPropagation(); + document.body.classList.add('dragging-over'); + }, false); + document.body.addEventListener('dragover', (e) => { + e.preventDefault(); + e.stopPropagation(); + document.body.classList.add('dragging-over'); + }, false); + document.body.addEventListener('dragleave', (e) => { + e.preventDefault(); + e.stopPropagation(); + document.body.classList.remove('dragging-over'); + }, false); + document.body.addEventListener('drop', (e) => { + e.preventDefault(); + e.stopPropagation(); + document.body.classList.remove('dragging-over'); + + const dt = e.dataTransfer; + const files = dt.files; + + for (const f of files) { + uploadFile(f, expiryEl.value); + } + }, false); }