Add paste file functionality
This commit is contained in:
parent
3ebc4db256
commit
4555cf7dcf
@ -16,6 +16,7 @@ class Uploader {
|
|||||||
document.addEventListener("dragover", (e) => this.dragOver(e));
|
document.addEventListener("dragover", (e) => this.dragOver(e));
|
||||||
document.addEventListener("dragleave", (e) => this.dragLeave(e));
|
document.addEventListener("dragleave", (e) => this.dragLeave(e));
|
||||||
document.addEventListener("drop", (e) => this.drop(e));
|
document.addEventListener("drop", (e) => this.drop(e));
|
||||||
|
document.addEventListener("paste", (e) => this.paste(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
dragOver(event) {
|
dragOver(event) {
|
||||||
@ -60,6 +61,24 @@ class Uploader {
|
|||||||
this.triggerUpload(files);
|
this.triggerUpload(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paste(event) {
|
||||||
|
const items = event.clipboardData.items;
|
||||||
|
const files = [];
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.kind === "file") {
|
||||||
|
files.push(item.getAsFile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
this.triggerUpload(files);
|
||||||
|
}
|
||||||
|
|
||||||
filesChanged() {
|
filesChanged() {
|
||||||
const files = Array.from(this.uploadInput.files);
|
const files = Array.from(this.uploadInput.files);
|
||||||
this.triggerUpload(files);
|
this.triggerUpload(files);
|
||||||
|
Loading…
Reference in New Issue
Block a user