From 1e6f2aeb11ac292ab9f612ddde225730d0d9a688 Mon Sep 17 00:00:00 2001 From: blek Date: Sat, 30 Sep 2023 01:45:12 +1000 Subject: [PATCH] drop file functionality --- filed/static/delay.js | 1 + filed/static/dragndrop-form.js | 46 +++++++++++++++++++++++++++++++++- filed/static/paint.css | 8 ++++++ filed/templates/base.html | 1 + filed/templates/index.html | 12 +++++---- 5 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 filed/static/delay.js diff --git a/filed/static/delay.js b/filed/static/delay.js new file mode 100644 index 0000000..73918a1 --- /dev/null +++ b/filed/static/delay.js @@ -0,0 +1 @@ +const delay=async m=>{return new Promise(r=>setTimeout(r,m))} diff --git a/filed/static/dragndrop-form.js b/filed/static/dragndrop-form.js index 27033f4..9bb2d98 100644 --- a/filed/static/dragndrop-form.js +++ b/filed/static/dragndrop-form.js @@ -1,11 +1,55 @@ ( () => { // display the js only text - document.getElementById('drag-n-drop-jsonly').style.display = 'initial'; + const text = document.getElementById('drag-n-drop-jsonly'); + text.style.display = 'initial'; + /** @type {HTMLElement} */ + const root_drag_rop = document.getElementsByClassName('file-drag-n-drop')[0]; + /** @type {HTMLElement} */ const drag_rop = document.getElementsByClassName('file-drag-n-drop-inside')[0]; const dr_rop_t = document.getElementsByClassName('file-drag-n-drop-inside-text')[0]; + function drag_end() { + root_drag_rop.style.background = 'var(--header-sec-color)' + drag_rop.style.borderColor = '#656565'; + } + + async function fill_bg() { + for (let i = 100; i != 0; i--) { + await delay(Math.random()); + root_drag_rop.style.background = `linear-gradient(#353535 ${i}%, var(--header-sec-color) ${i + 0.01}%)`; + } + root_drag_rop.style.background = `var(--header-sec-color)`; + } + + let drdrop_enabled = true; + + drag_rop.addEventListener('drop', async e => { + e.preventDefault(); + + if (!drdrop_enabled) return; + + if (e.dataTransfer.items) { + for (let i = 0; i != e.dataTransfer.items.length; i++) { + let file = e.dataTransfer.items[i].getAsFile(); + text.innerText = 'Processing...'; + drdrop_enabled = false; + await fill_bg(); + drdrop_enabled = true; + text.innerText = `Selected file: ${file.name.substring(0,16)}${file.name.length > 16 ? '...' : ''}\nYou can drop another file to replace this one`; + } + } + }); + drag_rop.addEventListener('dragover', e => { + e.preventDefault(); + if (!drdrop_enabled) return; + + root_drag_rop.style.background = '#393939' + drag_rop.style.borderColor = '#959595'; + }); + drag_rop.addEventListener('mouseleave', drag_end); + drag_rop.addEventListener('dragend', drag_end) } )() \ No newline at end of file diff --git a/filed/static/paint.css b/filed/static/paint.css index f0ed3d6..2a16dc3 100644 --- a/filed/static/paint.css +++ b/filed/static/paint.css @@ -136,6 +136,7 @@ p { background: var(--header-sec-color); border-radius: 16px; padding: var(--header-padding-x); + transition: 250ms ease; } .file-drag-n-drop * { display: block } .file-drag-n-drop object { display: initial } @@ -144,6 +145,7 @@ p { border: 4px dotted #656565; height: calc(100% - 32px - 8px); border-radius: 16px; + transition: 250ms ease; } .file-drag-n-drop .file-drag-n-drop-inside .file-drag-n-drop-inside-text { margin: 0; @@ -152,4 +154,10 @@ p { transform: translateY(-50%); text-align: center; line-height: 32px; +} + +@media (max-width:513px) { + .file-drag-n-drop { + width: calc(100% - 32px); + } } \ No newline at end of file diff --git a/filed/templates/base.html b/filed/templates/base.html index a865527..9aed411 100644 --- a/filed/templates/base.html +++ b/filed/templates/base.html @@ -7,6 +7,7 @@ + blek! File {% block head %}{% endblock %} diff --git a/filed/templates/index.html b/filed/templates/index.html index 2308213..e8119a3 100644 --- a/filed/templates/index.html +++ b/filed/templates/index.html @@ -34,12 +34,14 @@
-