Move download function in ImageCommon

Conflicts:
	builds/appchan-x.user.js
	builds/crx/script.js
	src/Images/ImageCommon.coffee
This commit is contained in:
Zixaphir 2015-01-12 22:17:50 -07:00 committed by ccd0
parent c84a8abd55
commit 29fd66898e
3 changed files with 13 additions and 13 deletions

View File

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

View File

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

View File

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