parent
d102578b54
commit
4e8f72fb87
1 changed files with 16 additions and 1 deletions
|
@ -19,7 +19,8 @@ class FileDropperControl extends events.EventTarget {
|
||||||
lock: options.lock,
|
lock: options.lock,
|
||||||
id: "file-" + Math.random().toString(36).substring(7),
|
id: "file-" + Math.random().toString(36).substring(7),
|
||||||
urlPlaceholder:
|
urlPlaceholder:
|
||||||
options.urlPlaceholder || "Alternatively, paste an URL here.",
|
options.urlPlaceholder ||
|
||||||
|
"Alternatively, paste an image or URL here.",
|
||||||
});
|
});
|
||||||
|
|
||||||
this._dropperNode = source.querySelector(".file-dropper");
|
this._dropperNode = source.querySelector(".file-dropper");
|
||||||
|
@ -48,6 +49,9 @@ class FileDropperControl extends events.EventTarget {
|
||||||
this._urlInputNode.addEventListener("keydown", (e) =>
|
this._urlInputNode.addEventListener("keydown", (e) =>
|
||||||
this._evtUrlInputKeyDown(e)
|
this._evtUrlInputKeyDown(e)
|
||||||
);
|
);
|
||||||
|
this._urlInputNode.addEventListener("paste", (e) =>
|
||||||
|
this._evtPaste(e)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (this._urlConfirmButtonNode) {
|
if (this._urlConfirmButtonNode) {
|
||||||
this._urlConfirmButtonNode.addEventListener("click", (e) =>
|
this._urlConfirmButtonNode.addEventListener("click", (e) =>
|
||||||
|
@ -129,6 +133,17 @@ class FileDropperControl extends events.EventTarget {
|
||||||
this._emitFiles(e.dataTransfer.files);
|
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) {
|
_evtUrlInputKeyDown(e) {
|
||||||
if (e.which !== KEY_RETURN) {
|
if (e.which !== KEY_RETURN) {
|
||||||
return;
|
return;
|
||||||
|
|
Reference in a new issue