Fixed saveAs error on Safari. Fixes #252

This commit is contained in:
benweet 2014-01-13 01:38:55 +00:00
parent 27560c73d3
commit 86c58f4cf1
2 changed files with 19 additions and 6 deletions

View File

@ -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();

View File

@ -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,9 +228,21 @@ define([
saveAs(content, filename);
}
else {
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
}
}
};
// Generates a random string