From c1ef8243a1a6bc83248cef8e0b33c04c5547dca4 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 17 Sep 2018 10:31:27 +0200 Subject: [PATCH] Ability to select multiple files to upload (#275) --- www/common/common-ui-elements.js | 34 +++++++++++++++++--------------- www/drive/inner.js | 17 +++++++++------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index b13432127..5fafd241e 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -631,23 +631,25 @@ define([ if (!data.FM) { return; } var $input = $('', { 'type': 'file', - 'style': 'display: none;' + 'style': 'display: none;', + 'multiple': 'multiple' }).on('change', function (e) { - var file = e.target.files[0]; - var ev = { - target: data.target - }; - if (data.filter && !data.filter(file)) { - return; - } - if (data.transformer) { - data.transformer(file, function (newFile) { - data.FM.handleFile(newFile, ev); - if (callback) { callback(); } - }); - return; - } - data.FM.handleFile(file, ev); + var files = Util.slice(e.target.files); + files.forEach(function (file) { + var ev = { + target: data.target + }; + if (data.filter && !data.filter(file)) { + return; + } + if (data.transformer) { + data.transformer(file, function (newFile) { + data.FM.handleFile(newFile, ev); + }); + return; + } + data.FM.handleFile(file, ev); + }); if (callback) { callback(); } }); if (data.accept) { $input.attr('accept', data.accept); } diff --git a/www/drive/inner.js b/www/drive/inner.js index 9fd9f82e6..9a1a15f8e 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -1805,14 +1805,17 @@ define([ .click(function () { var $input = $('', { 'type': 'file', - 'style': 'display: none;' + 'style': 'display: none;', + 'multiple': 'multiple' }).on('change', function (e) { - var file = e.target.files[0]; - var ev = { - target: $content[0], - path: findDropPath($content[0]) - }; - APP.FM.handleFile(file, ev); + var files = Util.slice(e.target.files); + files.forEach(function (file) { + var ev = { + target: $content[0], + path: findDropPath($content[0]) + }; + APP.FM.handleFile(file, ev); + }); }); $input.click(); });