diff --git a/client/js/controls/file_dropper_control.js b/client/js/controls/file_dropper_control.js index 2dfb4922..8d1fa163 100644 --- a/client/js/controls/file_dropper_control.js +++ b/client/js/controls/file_dropper_control.js @@ -48,6 +48,12 @@ class FileDropperControl extends events.EventTarget { this._urlInputNode.addEventListener("keydown", (e) => this._evtUrlInputKeyDown(e) ); + this._urlInputNode.addEventListener("paste", (e) => { + // document.onpaste is used on the post-upload page. + // And this event is used on the post edit page. + if (document.getElementById("post-upload")) return; + this._evtPaste(e) + }); } if (this._urlConfirmButtonNode) { this._urlConfirmButtonNode.addEventListener("click", (e) => @@ -55,6 +61,11 @@ class FileDropperControl extends events.EventTarget { ); } + document.onpaste = (e) => { + if (!document.getElementById("post-upload")) return; + this._evtPaste(e) + } + this._originalHtml = this._dropperNode.innerHTML; views.replaceContent(target, source); } @@ -129,6 +140,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()).filter(f => f); + + if (!this._options.allowMultiple && fileList.length > 1) { + window.alert("Cannot select multiple files."); + } else if (fileList.length > 0) { + this._emitFiles(fileList); + } + } + _evtUrlInputKeyDown(e) { if (e.which !== KEY_RETURN) { return;