add drag and drop
This commit is contained in:
+31
-14
@@ -159,24 +159,41 @@ option {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn:hover {
|
||||||
|
background-color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
.link-btn {
|
.link-btn {
|
||||||
border: none;
|
border: none;
|
||||||
background: none;
|
background: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font: inherit;
|
font: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-links {
|
.upload-links {
|
||||||
margin-top: 12px;
|
margin-top: 12px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-links form {
|
.upload-links form {
|
||||||
margin: 0;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
+5
-4
@@ -5,8 +5,10 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>minibin</title>
|
<title>minibin</title>
|
||||||
<link rel="stylesheet" href="/css/main.css" />
|
<link rel="stylesheet" href="/css/main.css" />
|
||||||
|
<script defer src="/js/dnd.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
|
||||||
|
<body class="home-page" id="home-page">
|
||||||
{{template "site-header"}}
|
{{template "site-header"}}
|
||||||
<main>
|
<main>
|
||||||
<p>simple file and paste hosting service</p>
|
<p>simple file and paste hosting service</p>
|
||||||
@@ -18,19 +20,18 @@
|
|||||||
<div class="file-panel">
|
<div class="file-panel">
|
||||||
<form action="/upload?return=html" method="post" enctype="multipart/form-data">
|
<form action="/upload?return=html" method="post" enctype="multipart/form-data">
|
||||||
<label for="file-expiry">expiry</label>
|
<label for="file-expiry">expiry</label>
|
||||||
<select id="paste-expiry" name="expiry">
|
<select id="file-expiry" name="expiry">
|
||||||
{{range .Expiries}}
|
{{range .Expiries}}
|
||||||
<option value="{{.Label}}">{{.Label}}</option>
|
<option value="{{.Label}}">{{.Label}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
<input type="file" required name="file" />
|
<input id="upload-file" type="file" required name="file" />
|
||||||
<button type="submit" class="btn">upload file</button>
|
<button type="submit" class="btn">upload file</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="paste-panel">
|
<div class="paste-panel">
|
||||||
<form action="/upload?return=html" method="post">
|
<form action="/upload?return=html" method="post">
|
||||||
<label for="paste-expiry">expiry</label>
|
<label for="paste-expiry">expiry</label>
|
||||||
|
|
||||||
<select id="paste-expiry" name="expiry">
|
<select id="paste-expiry" name="expiry">
|
||||||
{{range .Expiries}}
|
{{range .Expiries}}
|
||||||
<option value="{{.Label}}">{{.Label}}</option>
|
<option value="{{.Label}}">{{.Label}}</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user