Skip to content

Commit

Permalink
client/upload: upload from clipboard
Browse files Browse the repository at this point in the history
Closes #320
  • Loading branch information
neobooru committed Jun 4, 2021
1 parent 3cabe79 commit ca7b70a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion client/js/controls/file_dropper_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class FileDropperControl extends events.EventTarget {
lock: options.lock,
id: "file-" + Math.random().toString(36).substring(7),
urlPlaceholder:
options.urlPlaceholder || "Alternatively, paste an URL here.",
options.urlPlaceholder ||
"Alternatively, paste an image or URL here.",
});

this._dropperNode = source.querySelector(".file-dropper");
Expand Down Expand Up @@ -48,6 +49,9 @@ class FileDropperControl extends events.EventTarget {
this._urlInputNode.addEventListener("keydown", (e) =>
this._evtUrlInputKeyDown(e)
);
this._urlInputNode.addEventListener("paste", (e) =>
this._evtPaste(e)
);
}
if (this._urlConfirmButtonNode) {
this._urlConfirmButtonNode.addEventListener("click", (e) =>
Expand Down Expand Up @@ -129,6 +133,17 @@ class FileDropperControl extends events.EventTarget {
this._emitFiles(e.dataTransfer.files);
}

_evtPaste(e) {
const items = (e.clipboardData || e.originalEvent.clipboardData).items;
const fileList = Array.from(items).map((x) => x.getAsFile());

if (!this._options.allowMultiple && fileList.length > 1) {
window.alert("Cannot select multiple files.");
} else {
this._emitFiles(fileList);
}
}

_evtUrlInputKeyDown(e) {
if (e.which !== KEY_RETURN) {
return;
Expand Down

0 comments on commit ca7b70a

Please sign in to comment.