From 29fd66898e4e680f8c321805ccdcc046deafe628 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 Conflicts: builds/appchan-x.user.js builds/crx/script.js src/Images/ImageCommon.coffee --- src/Images/Gallery.coffee | 2 +- src/Images/ImageCommon.coffee | 10 ++++++++++ src/Menu/DownloadLink.coffee | 14 ++------------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 2cc714c6f..6b9adab75 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -61,7 +61,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 3ee657eea..1d7d3a671 100644 --- a/src/Images/ImageCommon.coffee +++ b/src/Images/ImageCommon.coffee @@ -83,3 +83,13 @@ ImageCommon = # XXX Estimate whether clicks are on the video controls and should be ignored. onControls: (e) -> e.target.controls and e.target.getBoundingClientRect().bottom - e.clientY < 35 + + 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 diff --git a/src/Menu/DownloadLink.coffee b/src/Menu/DownloadLink.coffee index 61ff0f5fd..2bc929c2a 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