From 723d1d326412a072520dc5816045447fa939c18e Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Mon, 12 Jan 2015 22:17:50 -0700 Subject: [PATCH] Move download function in ImageCommon --- builds/appchan-x.user.js | 36 +++++++++++++++++------------------ builds/crx/script.js | 36 +++++++++++++++++------------------ src/Images/Gallery.coffee | 2 +- src/Images/ImageCommon.coffee | 10 ++++++++++ src/Menu/DownloadLink.coffee | 14 ++------------ 5 files changed, 49 insertions(+), 49 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 0e55efe77..d153c6b8d 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -11126,7 +11126,7 @@ cb = Gallery.cb; $.on(nodes.frame, 'click', cb.blank); $.on(nodes.next, 'click', cb.click); - $.on(nodes.name, 'click', DownloadLink.download); + $.on(nodes.name, 'click', ImageCommon.download); $.on($('.gal-prev', dialog), 'click', cb.prev); $.on($('.gal-next', dialog), 'click', cb.next); $.on($('.gal-start', dialog), 'click', cb.start); @@ -11599,6 +11599,22 @@ }); }; return $.on(video, 'mouseover', handler); + }, + 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)); } }; @@ -13374,7 +13390,7 @@ className: 'download-link', textContent: 'Download file' }); - $.on(a, 'click', this.download); + $.on(a, 'click', ImageCommon.download); return Menu.menu.addEntry({ el: a, order: 100, @@ -13389,22 +13405,6 @@ 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 f6b6b720f..209abb217 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -11163,7 +11163,7 @@ cb = Gallery.cb; $.on(nodes.frame, 'click', cb.blank); $.on(nodes.next, 'click', cb.click); - $.on(nodes.name, 'click', DownloadLink.download); + $.on(nodes.name, 'click', ImageCommon.download); $.on($('.gal-prev', dialog), 'click', cb.prev); $.on($('.gal-next', dialog), 'click', cb.next); $.on($('.gal-start', dialog), 'click', cb.start); @@ -11623,6 +11623,22 @@ }); }; return $.on(video, 'mouseover', handler); + }, + 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)); } }; @@ -13398,7 +13414,7 @@ className: 'download-link', textContent: 'Download file' }); - $.on(a, 'click', this.download); + $.on(a, 'click', ImageCommon.download); return Menu.menu.addEntry({ el: a, order: 100, @@ -13413,22 +13429,6 @@ 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 dc59ee693..a0cd1fcae 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -59,7 +59,7 @@ Gallery = {cb} = Gallery $.on nodes.frame, 'click', cb.blank $.on nodes.next, 'click', cb.click - $.on nodes.name, 'click', DownloadLink.download + $.on nodes.name, 'click', ImageCommon.download $.on $('.gal-prev', dialog), 'click', cb.prev $.on $('.gal-next', dialog), 'click', cb.next diff --git a/src/Images/ImageCommon.coffee b/src/Images/ImageCommon.coffee index 2c55fbbbf..d2360b5db 100644 --- a/src/Images/ImageCommon.coffee +++ b/src/Images/ImageCommon.coffee @@ -79,3 +79,13 @@ ImageCommon = $.asap (-> chrome? or (video.readyState >= 3 and video.currentTime <= Math.max 0.1, (video.duration - 0.5)) or new Date().getTime() >= t + 1000), -> video.controls = true $.on video, 'mouseover', handler + + 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 diff --git a/src/Menu/DownloadLink.coffee b/src/Menu/DownloadLink.coffee index de6fc9173..970ca100d 100755 --- a/src/Menu/DownloadLink.coffee +++ b/src/Menu/DownloadLink.coffee @@ -7,7 +7,7 @@ DownloadLink = textContent: 'Download file' # Specifying the filename with the download attribute only works for same-origin links. - $.on a, 'click', @download + $.on a, 'click', ImageCommon.download Menu.menu.addEntry el: a @@ -16,14 +16,4 @@ DownloadLink = return false unless file 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 + true \ No newline at end of file