-
-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathui.js
64 lines (49 loc) · 1.57 KB
/
ui.js
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
63
64
var UserInterface = {
selector: 'a[href|="#download"]'
};
UserInterface.setup = function(zipper, downloader) {
var downloadLinks = document.body.querySelectorAll(UserInterface.selector);
var createZip = function(files) {
zipper.createZip(downloader, files);
};
var registerListener = function(link) {
console.log("adding listener to", link);
link.addEventListener("click", function(event) {
event.preventDefault();
// Get the file list on the fly
var files = getFileList(event.target);
console.log('files', files);
console.log('creating zip');
createZip(files);
}, false);
};
var checkIfDownloadLinkExist = function() {
if (downloadLinks) {
foreach(downloadLinks, function() {
registerListener(this);
hideAccessibleFileLinks(this);
});
}
};
var locateAnchorForDownloadLink = function(link) {
var anchorName = link.href.replace(/^[^#]*#/, '');
return document.body.querySelector('a[name="' + anchorName + '"')
}
var hideAccessibleFileLinks = function(link) {
var anchor = locateAnchorForDownloadLink(link);
var next = getNextSiblingInDom(anchor);
addClass(anchor, 'hidden'); // could be made an expander button
addClass(next, 'hidden');
};
var getFileList = function(link) {
var anchor = locateAnchorForDownloadLink(link);
var next = getNextSiblingInDom(anchor);
var fileLinks = next.querySelectorAll('a'),
files = [];
foreach(fileLinks, function() {
files.push(this.href);
});
return files;
}
checkIfDownloadLinkExist();
}