-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.js
32 lines (32 loc) · 1.24 KB
/
common.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
function download_file(nice_name, url, callback) {
var xhr = new XMLHttpRequest();//todo: use jQuery
xhr.open('GET', url, true);
xhr.responseType = "arraybuffer";
xhr.onload = function(e) {
window.webkitRequestFileSystem(TEMPORARY, xhr.response.byteLength, function(fs) {
fs.root.getFile(nice_name, {create: true}, function(file_entry) {
file_entry.createWriter(function(writer) {
var bb = new WebKitBlobBuilder();
bb.append(xhr.response);
writer.onwrite = function(e) {
/*$("<iframe></iframe").attr("src", file_entry.toURL()).appendTo("body");*/
callback();
document.location = file_entry.toURL();
};
writer.write(bb.getBlob());
});
});
});
};
xhr.send();
}
function form_nice_name(authors, title) {
return authors + " - " + title;
}
function process_link_click(authors, title, type, $link) {
var text = $link.text();
$link.text($link.text() + ' (loading)');
download_file(form_nice_name(authors, title) + '.' + type, $link.attr("href"), function() {
$link.text(text);
});
}