-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
62 lines (58 loc) · 2.02 KB
/
index.html
File metadata and controls
62 lines (58 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery.js@1.2.0/src/css/lightgallery.css" />
<script src="https://cdn.jsdelivr.net/npm/lightgallery.js@1.2.0/dist/js/lightgallery.min.js"></script>
<div>
<label id="label" for="file" style="color: white; background-color: deepskyblue; border-radius: 3px;">
Upload images
<input type="file" id="file" multiple="true" style="display:none;" accept="image/png,image/jpeg">
</div>
<div id="status"></div>
<div id="lightgallery"></div>
<script>
function showImages(urls) {
if (urls.length == 0) return;
const lightgallery = document.getElementById("lightgallery");
lightgallery.innerHTML = "";
urls.forEach(url => {
const a = document.createElement("a");
a.setAttribute("href", url);
const img = document.createElement("img");
img.setAttribute("src", url);
img.setAttribute("width", 200);
a.appendChild(img);
lightgallery.appendChild(a);
});
lightGallery(document.getElementById('lightgallery'), {download: false});
}
const f = document.getElementById('file');
f.addEventListener("change", () => {
if (f.files.length > 0) {
const status = document.getElementById("status");
status.innerHTML = "Now uploading...";
Promise.all([...f.files].map((file, i) => {
const fr = new FileReader();
return new Promise(r => {
fr.onload = e => {
const data = e.target.result.split(",");
r({fileName: file.name, mimeType: data[0].match(/:(\w.+);/)[1], data: data[1]});
}
fr.readAsDataURL(file);
});
}))
.then(images => {
google.script.run
.withFailureHandler(err => {
console.log(err);
status.innerHTML = "";
})
.withSuccessHandler(() => {
main();
status.innerHTML = "";
}).appendImages(images);
});
}
});
function main() {
google.script.run.withFailureHandler(err => console.log(err)).withSuccessHandler(showImages).getImages();
}
main();
</script>