|
1 | | -function setInpPrev(event) { |
| 1 | +function setInpPrev(files) { |
2 | 2 | var img = document.getElementById('inpImgPreview'); |
3 | | - if (event.target.files.length == 0) { |
| 3 | + if (files.length == 0) { |
4 | 4 | img.src = "#"; |
5 | 5 | } else { |
6 | 6 | var reader = new FileReader(); |
7 | 7 | reader.onload = function() { |
8 | 8 | img.src = reader.result; |
9 | 9 | }; |
10 | | - reader.readAsDataURL(event.target.files[0]); |
| 10 | + reader.readAsDataURL(files[0]); |
11 | 11 | } |
12 | 12 | } |
| 13 | +function importFiles() { |
| 14 | + webxdc.importFiles({mimeTypes: ['image/*']}).then((files) => { |
| 15 | + setInpPrev(files); |
| 16 | + }); |
| 17 | +} |
13 | 18 |
|
14 | 19 | window.addEventListener("load", () => { |
15 | 20 | document.getElementById("uploads-output").append( |
16 | 21 | createHeader("Uploads/Import"), |
17 | 22 | h("div", {class: "container"}, |
18 | | - h('input', {id: "imgInp", type: "file", accept: "image/*", onchange: "setInpPrev(event)"}), |
| 23 | + h("button", {onclick: "importFiles()"}, "webxdc.importFiles(...)"), |
| 24 | + " or ", |
| 25 | + h('input', {id: "imgInp", type: "file", accept: "image/*", onchange: "setInpPrev(event.target.files)"}), |
19 | 26 | h("br"), h("br"), |
20 | 27 | h("img", {id: "inpImgPreview", style: "max-height: 200px; max-width: 90%; width: auto; display:block", alt: "Image preview will appear here"}), |
21 | 28 | ), |
|
0 commit comments