|
|
@ -1,9 +1,9 @@ |
|
|
|
/* FileSaver.js |
|
|
|
/* FileSaver.js |
|
|
|
* A saveAs() FileSaver implementation. |
|
|
|
* A saveAs() FileSaver implementation. |
|
|
|
* 1.1.20150716 |
|
|
|
* 1.1.20151003 |
|
|
|
* |
|
|
|
* |
|
|
|
* By Eli Grey, http://eligrey.com
|
|
|
|
* By Eli Grey, http://eligrey.com
|
|
|
|
* License: X11/MIT |
|
|
|
* License: MIT |
|
|
|
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
|
|
|
|
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
@ -30,6 +30,7 @@ var saveAs = saveAs || (function(view) { |
|
|
|
var event = new MouseEvent("click"); |
|
|
|
var event = new MouseEvent("click"); |
|
|
|
node.dispatchEvent(event); |
|
|
|
node.dispatchEvent(event); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
, is_safari = /Version\/[\d\.]+.*Safari/.test(navigator.userAgent) |
|
|
|
, webkit_req_fs = view.webkitRequestFileSystem |
|
|
|
, webkit_req_fs = view.webkitRequestFileSystem |
|
|
|
, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem |
|
|
|
, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem |
|
|
|
, throw_outside = function(ex) { |
|
|
|
, throw_outside = function(ex) { |
|
|
@ -94,6 +95,19 @@ var saveAs = saveAs || (function(view) { |
|
|
|
} |
|
|
|
} |
|
|
|
// on any filesys errors revert to saving with object URLs
|
|
|
|
// on any filesys errors revert to saving with object URLs
|
|
|
|
, fs_error = function() { |
|
|
|
, fs_error = function() { |
|
|
|
|
|
|
|
if (target_view && is_safari && typeof FileReader !== "undefined") { |
|
|
|
|
|
|
|
// Safari doesn't allow downloading of blob urls
|
|
|
|
|
|
|
|
var reader = new FileReader(); |
|
|
|
|
|
|
|
reader.onloadend = function() { |
|
|
|
|
|
|
|
var base64Data = reader.result; |
|
|
|
|
|
|
|
target_view.location.href = "data:attachment/file" + base64Data.slice(base64Data.search(/[,;]/)); |
|
|
|
|
|
|
|
filesaver.readyState = filesaver.DONE; |
|
|
|
|
|
|
|
dispatch_all(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
reader.readAsDataURL(blob); |
|
|
|
|
|
|
|
filesaver.readyState = filesaver.INIT; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
// don't create more object URLs than needed
|
|
|
|
// don't create more object URLs than needed
|
|
|
|
if (blob_changed || !object_url) { |
|
|
|
if (blob_changed || !object_url) { |
|
|
|
object_url = get_URL().createObjectURL(blob); |
|
|
|
object_url = get_URL().createObjectURL(blob); |
|
|
@ -102,7 +116,7 @@ var saveAs = saveAs || (function(view) { |
|
|
|
target_view.location.href = object_url; |
|
|
|
target_view.location.href = object_url; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var new_tab = view.open(object_url, "_blank"); |
|
|
|
var new_tab = view.open(object_url, "_blank"); |
|
|
|
if (new_tab == undefined && typeof safari !== "undefined") { |
|
|
|
if (new_tab == undefined && is_safari) { |
|
|
|
//Apple do not allow window.open, see http://bit.ly/1kZffRI
|
|
|
|
//Apple do not allow window.open, see http://bit.ly/1kZffRI
|
|
|
|
view.location.href = object_url |
|
|
|
view.location.href = object_url |
|
|
|
} |
|
|
|
} |
|
|
|