From 5a17f77f7a799d11ee7957a6210ee14a5858c80e Mon Sep 17 00:00:00 2001 From: j Date: Wed, 12 Sep 2018 19:57:29 +0200 Subject: [PATCH] download frame, fixes #3163 --- static/js/editor.js | 5 +++++ static/js/utils.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/static/js/editor.js b/static/js/editor.js index 1251ec98..190aac97 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -163,6 +163,11 @@ pandora.ui.editor = function(data) { pandora.$ui[dialog] && pandora.$ui[dialog].remove(); pandora.$ui[dialog] = pandora.ui[dialog](data).open(); }, + downloadframe: function(data_) { + var url = '/' + ui.item + '/' + Ox.max(pandora.site.video.resolutions) + 'p' + data_.position + '.jpg', + name = data.title + ' - ' + Ox.formatDuration(data_.position) + '.jpg'; + pandora.saveURL(url, name) + }, downloadvideo: function() { pandora.ui.downloadVideoDialog({ item: ui.item, diff --git a/static/js/utils.js b/static/js/utils.js index 097d7e4f..a1b187db 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -2577,6 +2577,25 @@ pandora.openURL = function(url) { } }; +pandora.saveURL = function(url, name) { + var link = document.createElement('a'); + if (typeof link.download === 'string') { + link.href = url; + link.setAttribute('download', name ? name : true); + //Firefox requires the link to be in the body + document.body.appendChild(link); + + //simulate click + link.click(); + + //remove the link when done + document.body.removeChild(link); + } else { + window.open(url); + } +} + + pandora.signin = function(data) { // fixme: this is still voodoo pandora.user = Ox.extend(data.user, {