Update FileSaver.js

master
Daniel Berteaud 9 years ago
parent 8f1825ae5a
commit 1deda170fb
  1. 35
      public/js/FileSaver.js

@ -1,6 +1,6 @@
/* FileSaver.js /* FileSaver.js
* A saveAs() FileSaver implementation. * A saveAs() FileSaver implementation.
* 2015-05-07.2 * 1.1.20150716
* *
* By Eli Grey, http://eligrey.com * By Eli Grey, http://eligrey.com
* License: X11/MIT * License: X11/MIT
@ -27,11 +27,7 @@ var saveAs = saveAs || (function(view) {
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a") , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
, can_use_save_link = "download" in save_link , can_use_save_link = "download" in save_link
, click = function(node) { , click = function(node) {
var event = doc.createEvent("MouseEvents"); var event = new MouseEvent("click");
event.initMouseEvent(
"click", true, false, view, 0, 0, 0, 0, 0
, false, false, false, false, 0, null
);
node.dispatchEvent(event); node.dispatchEvent(event);
} }
, webkit_req_fs = view.webkitRequestFileSystem , webkit_req_fs = view.webkitRequestFileSystem
@ -82,8 +78,10 @@ var saveAs = saveAs || (function(view) {
} }
return blob; return blob;
} }
, FileSaver = function(blob, name) { , FileSaver = function(blob, name, no_auto_bom) {
blob = auto_bom(blob); if (!no_auto_bom) {
blob = auto_bom(blob);
}
// First try a.download, then web filesystem, then object URLs // First try a.download, then web filesystem, then object URLs
var var
filesaver = this filesaver = this
@ -131,10 +129,12 @@ var saveAs = saveAs || (function(view) {
object_url = get_URL().createObjectURL(blob); object_url = get_URL().createObjectURL(blob);
save_link.href = object_url; save_link.href = object_url;
save_link.download = name; save_link.download = name;
click(save_link); setTimeout(function() {
filesaver.readyState = filesaver.DONE; click(save_link);
dispatch_all(); dispatch_all();
revoke(object_url); revoke(object_url);
filesaver.readyState = filesaver.DONE;
});
return; return;
} }
// Object and web filesystem URLs have a problem saving in Google Chrome when // Object and web filesystem URLs have a problem saving in Google Chrome when
@ -205,14 +205,17 @@ var saveAs = saveAs || (function(view) {
}), fs_error); }), fs_error);
} }
, FS_proto = FileSaver.prototype , FS_proto = FileSaver.prototype
, saveAs = function(blob, name) { , saveAs = function(blob, name, no_auto_bom) {
return new FileSaver(blob, name); return new FileSaver(blob, name, no_auto_bom);
} }
; ;
// IE 10+ (native saveAs) // IE 10+ (native saveAs)
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) { if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
return function(blob, name) { return function(blob, name, no_auto_bom) {
return navigator.msSaveOrOpenBlob(auto_bom(blob), name); if (!no_auto_bom) {
blob = auto_bom(blob);
}
return navigator.msSaveOrOpenBlob(blob, name || "download");
}; };
} }

Loading…
Cancel
Save