From 41aaf5006fd2016fe4e816058863f18f0b28bdf3 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Thu, 12 Nov 2026 21:35:54 -0500 Subject: [PATCH] add drag and drop --- static/css/main.css | 45 +++++++++++++++++++++++++------------ static/js/dnd.js | 54 +++++++++++++++++++++++++++++++++++++++++++++ templates/home.html | 9 ++++---- 3 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 static/js/dnd.js diff --git a/static/css/main.css b/static/css/main.css index c78b90d..d52957b 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -159,24 +159,41 @@ option { cursor: pointer; } +.btn:hover { + background-color: var(--text-muted); +} + .link-btn { - border: none; - background: none; - padding: 0; - text-decoration: underline; - color: var(--text); - cursor: pointer; - font: inherit; + border: none; + background: none; + padding: 0; + text-decoration: underline; + color: var(--text); + cursor: pointer; + font: inherit; } .upload-links { - margin-top: 12px; - display: flex; - flex-direction: row; - gap: 12px; - align-items: baseline; + margin-top: 12px; + display: flex; + flex-direction: row; + gap: 12px; + align-items: baseline; } .upload-links form { - margin: 0; -} \ No newline at end of file + margin: 0; +} + +body.dragging::after { + content: "drop file to select"; + position: fixed; + inset: 0; + z-index: 100; + display: grid; + place-items: center; + background: rgb(0 0 0 / 30%); + color: var(--text); + font-size: 1.5rem; + pointer-events: none; +} diff --git a/static/js/dnd.js b/static/js/dnd.js new file mode 100644 index 0000000..71a3eab --- /dev/null +++ b/static/js/dnd.js @@ -0,0 +1,54 @@ +const fileInput = document.getElementById("upload-file"); + +let dragDepth = 0; + +function isFile(event) { + return event.dataTransfer.types.includes("Files"); +} + +function resetDrag() { + dragDepth = 0; + document.body.classList.remove("dragging"); +} + +document.addEventListener("dragenter", (event) => { + if (!isFile(event)) return; + + event.preventDefault(); + dragDepth++; + document.body.classList.add("dragging"); +}); + +document.addEventListener("dragover", (event) => { + if (!isFile(event)) return; + + event.preventDefault(); + event.dataTransfer.dropEffect = "copy"; +}); + +document.addEventListener("dragleave", () => { + dragDepth = Math.max(0, dragDepth - 1); + + if (dragDepth === 0) { + document.body.classList.remove("dragging"); + } +}); + +document.addEventListener("drop", (event) => { + resetDrag(); + if (!isFile(event)) return; + + event.preventDefault(); + + const file = event.dataTransfer.files[0]; + if (!file) return; + + const transfer = new DataTransfer(); + transfer.items.add(file); + fileInput.files = transfer.files; + + document.getElementById("type-file").checked = true; + fileInput.dispatchEvent(new Event("change", { bubbles: true })); +}); + +document.addEventListener("dragend", resetDrag); diff --git a/templates/home.html b/templates/home.html index 1bc573c..c633bf8 100644 --- a/templates/home.html +++ b/templates/home.html @@ -5,8 +5,10 @@ minibin + - + + {{template "site-header"}}

simple file and paste hosting service

@@ -18,19 +20,18 @@
- {{range .Expiries}} {{end}} - +
-