From efabc68ce06a88562ea86b2a8497ead9fd08cfd8 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 12 Jan 2015 22:16:30 -0700 Subject: [PATCH] Add download functionality to Gallery, as originally intended. --- builds/appchan-x.user.js | 34 ++++++++++++++++++---------------- builds/crx/script.js | 34 ++++++++++++++++++---------------- src/Images/Gallery.coffee | 6 ++++-- src/Menu/DownloadLink.coffee | 20 +++++++++++--------- 4 files changed, 51 insertions(+), 43 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 4deeddb04..0e55efe77 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -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)); } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index 6c1c9ad7a..f6b6b720f 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -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)); } }; diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index d2646eba3..dc59ee693 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -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 diff --git a/src/Menu/DownloadLink.coffee b/src/Menu/DownloadLink.coffee index 3545f9d2e..de6fc9173 100755 --- a/src/Menu/DownloadLink.coffee +++ b/src/Menu/DownloadLink.coffee @@ -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 \ No newline at end of file