From c84a8abd5589a510778b95460abce9dc288fd02a 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. Conflicts: builds/appchan-x.user.js builds/crx/script.js --- src/Images/Gallery.coffee | 6 ++++-- src/Menu/DownloadLink.coffee | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 3538af6f0..2cc714c6f 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -59,8 +59,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 f726fcc77..61ff0f5fd 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