diff --git a/public/res/publisher.js b/public/res/publisher.js index 9c8b1da5..6e6d4205 100644 --- a/public/res/publisher.js +++ b/public/res/publisher.js @@ -7,6 +7,7 @@ define([ "settings", "eventMgr", "fileSystem", + "core", "fileMgr", "sharing", "classes/Provider", @@ -21,7 +22,7 @@ define([ "providers/sshProvider", "providers/tumblrProvider", "providers/wordpressProvider" -], function($, _, constants, utils, storage, settings, eventMgr, fileSystem, fileMgr, sharing, Provider, AsyncTask) { +], function($, _, constants, utils, storage, settings, eventMgr, fileSystem, core, fileMgr, sharing, Provider, AsyncTask) { var publisher = {}; @@ -350,7 +351,7 @@ define([ }); task.onSuccess(function() { if(pdf !== undefined) { - utils.saveAs(pdf, fileMgr.currentFile.title + ".pdf"); + utils.saveAs(pdf, fileMgr.currentFile.title + ".pdf", core.redirectConfirm); } }); task.enqueue(); diff --git a/public/res/utils.js b/public/res/utils.js index bae57a3f..2b930226 100644 --- a/public/res/utils.js +++ b/public/res/utils.js @@ -216,8 +216,8 @@ define([ }; // Export data on disk - utils.saveAs = function(content, filename) { - if(saveAs !== undefined) { + utils.saveAs = function(content, filename, redirectConfirm) { + if(saveAs !== undefined && !/constructor/i.test(window.HTMLElement) /* safari does not support saveAs*/) { if(_.isString(content)) { content = new Blob([ content @@ -228,8 +228,20 @@ define([ saveAs(content, filename); } else { - var uriContent = "data:application/octet-stream;base64," + utils.encodeBase64(content); - window.open(uriContent, 'file'); + if(_.isString(content)) { + var uriContent = "data:application/octet-stream;base64," + utils.encodeBase64(content); + window.open(uriContent, 'file'); + } + else { + var reader = new FileReader(); + reader.onload = function(event) { + redirectConfirm('You are being downloading a PDF file.', function() { + var uriContent = 'data:application/pdf;' + event.target.result.substring(event.target.result.indexOf('base64')); + window.open(uriContent, 'file'); + }); + }; + reader.readAsDataURL(content);//Convert the blob from clipboard to base64 + } } };