Move download function in ImageCommon
This commit is contained in:
parent
efabc68ce0
commit
723d1d3264
@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user