Merge pull request #3226 from SwayUser/paste-image

Add paste file functionality
This commit is contained in:
Pavel Djundik 2019-05-21 20:24:27 +03:00 committed by GitHub
commit 39d8a6a7de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,7 @@ class Uploader {
document.addEventListener("dragover", (e) => this.dragOver(e));
document.addEventListener("dragleave", (e) => this.dragLeave(e));
document.addEventListener("drop", (e) => this.drop(e));
document.addEventListener("paste", (e) => this.paste(e));
}
dragOver(event) {
@ -60,6 +61,24 @@ class Uploader {
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() {
const files = Array.from(this.uploadInput.files);
this.triggerUpload(files);