From a4592af5b1f673f639dad3678787ef8f2b4ef4ee Mon Sep 17 00:00:00 2001 From: iapyang Date: Fri, 12 Nov 2021 17:39:02 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-56417=20feat:=20=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E9=80=9A=E8=BF=87dataTransfer=E5=AF=B9=E8=B1=A1=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/single/editor/editor.multifile.js | 6 ++++++ src/base/single/input/file.js | 10 ++++++++++ src/polyfill/event.js | 15 +++++++++++++++ typescript/widget/editor/editor.multifile.ts | 2 ++ 4 files changed, 33 insertions(+) create mode 100644 src/polyfill/event.js diff --git a/src/base/single/editor/editor.multifile.js b/src/base/single/editor/editor.multifile.js index 68b5bcc2e..1175d01c7 100644 --- a/src/base/single/editor/editor.multifile.js +++ b/src/base/single/editor/editor.multifile.js @@ -91,6 +91,12 @@ BI.MultifileEditor = BI.inherit(BI.Widget, { this.file.upload(); }, + sendFiles: function (files) { + this._reset(); + + this.file.sendFiles(files); + }, + reset: function () { this._reset(); } diff --git a/src/base/single/input/file.js b/src/base/single/input/file.js index fa589681b..904fbfcf5 100644 --- a/src/base/single/input/file.js +++ b/src/base/single/input/file.js @@ -683,6 +683,16 @@ } }, + sendFiles: function (files) { + if (!this.wrap) return; + + this.wrap.dom.input.files = files; + + var event = new CustomEvent("change"); + + this.wrap.dom.input.dispatchEvent(event); + }, + _setEnable: function (enable) { BI.File.superclass._setEnable.apply(this, arguments); if (enable === true) { diff --git a/src/polyfill/event.js b/src/polyfill/event.js new file mode 100644 index 000000000..346ec16c8 --- /dev/null +++ b/src/polyfill/event.js @@ -0,0 +1,15 @@ +(function () { + if (typeof window.CustomEvent === "function") return false; // If not IE + + function CustomEvent (event, params) { + params = params || { bubbles: false, cancelable: false, detail: undefined }; + var evt = document.createEvent("CustomEvent"); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); + + return evt; + } + + CustomEvent.prototype = window.Event.prototype; + + window.CustomEvent = CustomEvent; +}()); diff --git a/typescript/widget/editor/editor.multifile.ts b/typescript/widget/editor/editor.multifile.ts index 3a29e0960..905d423e6 100644 --- a/typescript/widget/editor/editor.multifile.ts +++ b/typescript/widget/editor/editor.multifile.ts @@ -30,4 +30,6 @@ export declare class MultifileEditor extends Widget { size: number; type: string; }[]; + + sendFiles(files: FileList): void; }