Add download functionality to Gallery, as originally intended.
This commit is contained in:
parent
de49f1b78f
commit
efabc68ce0
@ -11126,6 +11126,7 @@
|
|||||||
cb = Gallery.cb;
|
cb = Gallery.cb;
|
||||||
$.on(nodes.frame, 'click', cb.blank);
|
$.on(nodes.frame, 'click', cb.blank);
|
||||||
$.on(nodes.next, 'click', cb.click);
|
$.on(nodes.next, 'click', cb.click);
|
||||||
|
$.on(nodes.name, 'click', DownloadLink.download);
|
||||||
$.on($('.gal-prev', dialog), 'click', cb.prev);
|
$.on($('.gal-prev', dialog), 'click', cb.prev);
|
||||||
$.on($('.gal-next', dialog), 'click', cb.next);
|
$.on($('.gal-next', dialog), 'click', cb.next);
|
||||||
$.on($('.gal-start', dialog), 'click', cb.start);
|
$.on($('.gal-start', dialog), 'click', cb.start);
|
||||||
@ -13373,22 +13374,7 @@
|
|||||||
className: 'download-link',
|
className: 'download-link',
|
||||||
textContent: 'Download file'
|
textContent: 'Download file'
|
||||||
});
|
});
|
||||||
$.on(a, 'click', function(e) {
|
$.on(a, 'click', this.download);
|
||||||
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));
|
|
||||||
});
|
|
||||||
return Menu.menu.addEntry({
|
return Menu.menu.addEntry({
|
||||||
el: a,
|
el: a,
|
||||||
order: 100,
|
order: 100,
|
||||||
@ -13403,6 +13389,22 @@
|
|||||||
return true;
|
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;
|
cb = Gallery.cb;
|
||||||
$.on(nodes.frame, 'click', cb.blank);
|
$.on(nodes.frame, 'click', cb.blank);
|
||||||
$.on(nodes.next, 'click', cb.click);
|
$.on(nodes.next, 'click', cb.click);
|
||||||
|
$.on(nodes.name, 'click', DownloadLink.download);
|
||||||
$.on($('.gal-prev', dialog), 'click', cb.prev);
|
$.on($('.gal-prev', dialog), 'click', cb.prev);
|
||||||
$.on($('.gal-next', dialog), 'click', cb.next);
|
$.on($('.gal-next', dialog), 'click', cb.next);
|
||||||
$.on($('.gal-start', dialog), 'click', cb.start);
|
$.on($('.gal-start', dialog), 'click', cb.start);
|
||||||
@ -13397,22 +13398,7 @@
|
|||||||
className: 'download-link',
|
className: 'download-link',
|
||||||
textContent: 'Download file'
|
textContent: 'Download file'
|
||||||
});
|
});
|
||||||
$.on(a, 'click', function(e) {
|
$.on(a, 'click', this.download);
|
||||||
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));
|
|
||||||
});
|
|
||||||
return Menu.menu.addEntry({
|
return Menu.menu.addEntry({
|
||||||
el: a,
|
el: a,
|
||||||
order: 100,
|
order: 100,
|
||||||
@ -13427,6 +13413,22 @@
|
|||||||
return true;
|
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'
|
nodes.menu = new UI.Menu 'gallery'
|
||||||
|
|
||||||
{cb} = Gallery
|
{cb} = Gallery
|
||||||
$.on nodes.frame, 'click', cb.blank
|
$.on nodes.frame, 'click', cb.blank
|
||||||
$.on nodes.next, 'click', cb.click
|
$.on nodes.next, 'click', cb.click
|
||||||
|
$.on nodes.name, 'click', DownloadLink.download
|
||||||
|
|
||||||
$.on $('.gal-prev', dialog), 'click', cb.prev
|
$.on $('.gal-prev', dialog), 'click', cb.prev
|
||||||
$.on $('.gal-next', dialog), 'click', cb.next
|
$.on $('.gal-next', dialog), 'click', cb.next
|
||||||
$.on $('.gal-start', dialog), 'click', cb.start
|
$.on $('.gal-start', dialog), 'click', cb.start
|
||||||
|
|||||||
@ -7,15 +7,7 @@ DownloadLink =
|
|||||||
textContent: 'Download file'
|
textContent: 'Download file'
|
||||||
|
|
||||||
# Specifying the filename with the download attribute only works for same-origin links.
|
# Specifying the filename with the download attribute only works for same-origin links.
|
||||||
$.on a, 'click', (e) ->
|
$.on a, 'click', @download
|
||||||
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
|
|
||||||
|
|
||||||
Menu.menu.addEntry
|
Menu.menu.addEntry
|
||||||
el: a
|
el: a
|
||||||
@ -25,3 +17,13 @@ DownloadLink =
|
|||||||
a.href = file.URL
|
a.href = file.URL
|
||||||
a.download = file.name
|
a.download = file.name
|
||||||
true
|
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