-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathindex.html
More file actions
51 lines (46 loc) · 1.59 KB
/
Copy pathindex.html
File metadata and controls
51 lines (46 loc) · 1.59 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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="Sindre Sorhus">
<meta name="viewport" content="width=device-width">
<title>multi-download example</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
#download-button,
#download-rename-button {
height: 50px;
position: absolute;
left: 50%;
transform: translate(-50%, -50%);
outline: none;
}
#download-button {
top: calc(50% - 50px);
}
#download-rename-button {
top: calc(50% + 50px);
}
</style>
</head>
<body >
<button id="download-button" class="btn btn-primary btn-lg" data-files="fixture/unicorn.jpg.zip fixture/rainbow.jpg.zip fixture/unicorn2.jpg.zip">Download multiple files</button>
<button id="download-rename-button" class="btn btn-primary btn-lg" data-files="fixture/unicorn.jpg.zip fixture/rainbow.jpg.zip fixture/unicorn2.jpg.zip">Download multiple files and rename them</button>
<script type="module">
import multiDownload from './index.js';
document.querySelector('#download-button').addEventListener('click', event => {
const files = event.target.dataset.files.split(' ');
multiDownload(files);
});
document.querySelector('#download-rename-button').addEventListener('click', event => {
const files = event.target.dataset.files.split(' ');
multiDownload(files, {
rename: ({url, index, urls}) => {
const extension = url.slice(url.lastIndexOf('.') + 1);
return `file${index}.${extension}`;
}
});
});
</script>
</body>
</html>