Add download functionality to Gallery, as originally intended.

Conflicts:
	builds/appchan-x.user.js
	builds/crx/script.js
This commit is contained in:
Zixaphir 2015-01-12 22:16:30 -07:00 committed by ccd0
parent bed88c3324
commit c84a8abd55
2 changed files with 15 additions and 11 deletions

View File

@ -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

View File

@ -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