From 772e9ef622a50996a14f8a2c99d8716178b8c38f Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Fri, 7 Jul 2023 17:39:38 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=A7=80?= =?UTF-8?q?=EC=9B=90=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8(upload-support?= =?UTF-8?q?.js)=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/webapp/resources/js/base/base.js | 60 ------------------- .../resources/js/base/upload-support.js | 23 +++++++ 2 files changed, 23 insertions(+), 60 deletions(-) create mode 100644 src/main/webapp/resources/js/base/upload-support.js diff --git a/src/main/webapp/resources/js/base/base.js b/src/main/webapp/resources/js/base/base.js index 8c995542..107370f3 100644 --- a/src/main/webapp/resources/js/base/base.js +++ b/src/main/webapp/resources/js/base/base.js @@ -761,63 +761,3 @@ function inputsInRange(fromSource, toSource) { function ignore() { console.log.apply(console, arguments); } - -function fileInput(conf) { - conf = conf || {}; - var name = conf.name || "upload", - tag = "" - .replace(/{name}/, name) - .replace(/{multiple}/, conf.multiple ? " multiple" : "") - .replace(/{accept}/, conf.accept ? " accept='" + conf.accept + "'" : ""), - obj = { - name:name, - input:null, - files:[], - - select:function(onSelect) { - if (!obj.input) { - var input = obj.input = $(tag); - $("body").append(input); - input.change(function(){ - var files = $(this).get(0).files, - length = files.length, - selected = []; - for (var i = 0; i < length; ++i) { - var file = files[i]; - file.id = name + (obj.files.length); - selected.push(file); - obj.files.push(file); - } - onSelect(selected); - }) - } - obj.input.click(); - }, - - getFiles:function() { - return obj.files; - }, - - remove:function(id){ - if (!id) return; - - var files = obj.files; - for (var i = 0; i < files.length; ++i) { - var file = files[i]; - if (id == file.id) { - files.splice(i, 1); - break; - } - } - }, - - clear:function(){ - if (obj.input) - $(obj.input).remove(); - obj.input = null; - obj.files.forEach(function(file){delete file;}); - obj.files = []; - } - }; - return obj; -} diff --git a/src/main/webapp/resources/js/base/upload-support.js b/src/main/webapp/resources/js/base/upload-support.js new file mode 100644 index 00000000..0340eb87 --- /dev/null +++ b/src/main/webapp/resources/js/base/upload-support.js @@ -0,0 +1,23 @@ +function uploadSupport(selector) { + let input = $(selector); + if (!input) + throw "Element not found: " + selector; + + let fileset = new Dataset({ + keymapper: info => info.id + }); + + input.change(function() { + var files = $(this).get(0).files, + length = files.length, + array = [] + for (var i = 0; i < length; ++i) { + var file = files[i]; + file.id = "file-" + new Date().getTime() + "-" + i; + file.url = (window.URL || window.webkitURL).createObjectURL(file); + array.push(file); + } + fileset.setData(array); + }); + return fileset; +} \ No newline at end of file