Add download functionality to Gallery, as originally intended.
This commit is contained in:
parent
de49f1b78f
commit
efabc68ce0
@ -11126,6 +11126,7 @@
|
||||
cb = Gallery.cb;
|
||||
$.on(nodes.frame, 'click', cb.blank);
|
||||
$.on(nodes.next, 'click', cb.click);
|
||||
$.on(nodes.name, 'click', DownloadLink.download);
|
||||
$.on($('.gal-prev', dialog), 'click', cb.prev);
|
||||
$.on($('.gal-next', dialog), 'click', cb.next);
|
||||
$.on($('.gal-start', dialog), 'click', cb.start);
|
||||
@ -13373,22 +13374,7 @@
|
||||
className: 'download-link',
|
||||
textContent: 'Download file'
|
||||
});
|
||||
$.on(a, 'click', function(e) {
|
||||
if (this.protocol === 'blob:') {
|
||||
return true;
|
||||
}
|
||||
e.preventDefault();
|
||||
return CrossOrigin.file(this.href, (function(_this) {
|
||||
return function(blob) {
|
||||
if (blob) {
|
||||
_this.href = URL.createObjectURL(blob);
|
||||
return _this.click();
|
||||
} else {
|
||||
return new Notice('error', "Could not download " + _this.href, 30);
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
$.on(a, 'click', this.download);
|
||||
return Menu.menu.addEntry({
|
||||
el: a,
|
||||
order: 100,
|
||||
@ -13403,6 +13389,22 @@
|
||||
return true;
|
||||
}
|
||||
});
|
||||
},
|
||||
download: function(e) {
|
||||
if (this.protocol === 'blob:') {
|
||||
return true;
|
||||
}
|
||||
e.preventDefault();
|
||||
return CrossOrigin.file(this.href, (function(_this) {
|
||||
return function(blob) {
|
||||
if (blob) {
|
||||
_this.href = URL.createObjectURL(blob);
|
||||
return _this.click();
|
||||
} else {
|
||||
return new Notice('error', "Could not download " + _this.href, 30);
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -11163,6 +11163,7 @@
|
||||
cb = Gallery.cb;
|
||||
$.on(nodes.frame, 'click', cb.blank);
|
||||
$.on(nodes.next, 'click', cb.click);
|
||||
$.on(nodes.name, 'click', DownloadLink.download);
|
||||
$.on($('.gal-prev', dialog), 'click', cb.prev);
|
||||
$.on($('.gal-next', dialog), 'click', cb.next);
|
||||
$.on($('.gal-start', dialog), 'click', cb.start);
|
||||
@ -13397,22 +13398,7 @@
|
||||
className: 'download-link',
|
||||
textContent: 'Download file'
|
||||
});
|
||||
$.on(a, 'click', function(e) {
|
||||
if (this.protocol === 'blob:') {
|
||||
return true;
|
||||
}
|
||||
e.preventDefault();
|
||||
return CrossOrigin.file(this.href, (function(_this) {
|
||||
return function(blob) {
|
||||
if (blob) {
|
||||
_this.href = URL.createObjectURL(blob);
|
||||
return _this.click();
|
||||
} else {
|
||||
return new Notice('error', "Could not download " + _this.href, 30);
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
$.on(a, 'click', this.download);
|
||||
return Menu.menu.addEntry({
|
||||
el: a,
|
||||
order: 100,
|
||||
@ -13427,6 +13413,22 @@
|
||||
return true;
|
||||
}
|
||||
});
|
||||
},
|
||||
download: function(e) {
|
||||
if (this.protocol === 'blob:') {
|
||||
return true;
|
||||
}
|
||||
e.preventDefault();
|
||||
return CrossOrigin.file(this.href, (function(_this) {
|
||||
return function(blob) {
|
||||
if (blob) {
|
||||
_this.href = URL.createObjectURL(blob);
|
||||
return _this.click();
|
||||
} else {
|
||||
return new Notice('error', "Could not download " + _this.href, 30);
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -57,8 +57,10 @@ Gallery =
|
||||
nodes.menu = new UI.Menu 'gallery'
|
||||
|
||||
{cb} = Gallery
|
||||
$.on nodes.frame, 'click', cb.blank
|
||||
$.on nodes.next, 'click', cb.click
|
||||
$.on nodes.frame, 'click', cb.blank
|
||||
$.on nodes.next, 'click', cb.click
|
||||
$.on nodes.name, 'click', DownloadLink.download
|
||||
|
||||
$.on $('.gal-prev', dialog), 'click', cb.prev
|
||||
$.on $('.gal-next', dialog), 'click', cb.next
|
||||
$.on $('.gal-start', dialog), 'click', cb.start
|
||||
|
||||
@ -7,15 +7,7 @@ DownloadLink =
|
||||
textContent: 'Download file'
|
||||
|
||||
# Specifying the filename with the download attribute only works for same-origin links.
|
||||
$.on a, 'click', (e) ->
|
||||
return true if @protocol is 'blob:'
|
||||
e.preventDefault()
|
||||
CrossOrigin.file @href, (blob) =>
|
||||
if blob
|
||||
@href = URL.createObjectURL blob
|
||||
@click()
|
||||
else
|
||||
new Notice 'error', "Could not download #{@href}", 30
|
||||
$.on a, 'click', @download
|
||||
|
||||
Menu.menu.addEntry
|
||||
el: a
|
||||
@ -25,3 +17,13 @@ DownloadLink =
|
||||
a.href = file.URL
|
||||
a.download = file.name
|
||||
true
|
||||
|
||||
download: (e) ->
|
||||
return true if @protocol is 'blob:'
|
||||
e.preventDefault()
|
||||
CrossOrigin.file @href, (blob) =>
|
||||
if blob
|
||||
@href = URL.createObjectURL blob
|
||||
@click()
|
||||
else
|
||||
new Notice 'error', "Could not download #{@href}", 30
|
||||
Loading…
x
Reference in New Issue
Block a user