Update FileSaver.js

master
Daniel Berteaud 10 years ago
parent 60d00c7bc6
commit d130c71603
  1. 33
      public/js/FileSaver.js

@ -1,6 +1,6 @@
/* FileSaver.js /* FileSaver.js
* A saveAs() FileSaver implementation. * A saveAs() FileSaver implementation.
* 2015-03-04 * 2015-05-07.2
* *
* By Eli Grey, http://eligrey.com * By Eli Grey, http://eligrey.com
* License: X11/MIT * License: X11/MIT
@ -12,16 +12,10 @@
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs = saveAs var saveAs = saveAs || (function(view) {
// IE 10+ (native saveAs)
|| (typeof navigator !== "undefined" &&
navigator.msSaveOrOpenBlob && navigator.msSaveOrOpenBlob.bind(navigator))
// Everyone else
|| (function(view) {
"use strict"; "use strict";
// IE <10 is explicitly unsupported // IE <10 is explicitly unsupported
if (typeof navigator !== "undefined" && if (typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
/MSIE [1-9]\./.test(navigator.userAgent)) {
return; return;
} }
var var
@ -81,7 +75,15 @@ var saveAs = saveAs
} }
} }
} }
, auto_bom = function(blob) {
// prepend BOM for UTF-8 XML and text/* types (including HTML)
if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
return new Blob(["\ufeff", blob], {type: blob.type});
}
return blob;
}
, FileSaver = function(blob, name) { , FileSaver = function(blob, name) {
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
@ -135,10 +137,6 @@ var saveAs = saveAs
revoke(object_url); revoke(object_url);
return; return;
} }
// prepend BOM for UTF-8 XML and text/plain types
if (/^\s*(?:text\/(?:plain|xml)|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
blob = new Blob(["\ufeff", blob], {type: blob.type});
}
// 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
// viewed in a tab, so I force save with application/octet-stream // viewed in a tab, so I force save with application/octet-stream
// http://code.google.com/p/chromium/issues/detail?id=91158 // http://code.google.com/p/chromium/issues/detail?id=91158
@ -211,6 +209,13 @@ var saveAs = saveAs
return new FileSaver(blob, name); return new FileSaver(blob, name);
} }
; ;
// IE 10+ (native saveAs)
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
return function(blob, name) {
return navigator.msSaveOrOpenBlob(auto_bom(blob), name);
};
}
FS_proto.abort = function() { FS_proto.abort = function() {
var filesaver = this; var filesaver = this;
filesaver.readyState = filesaver.DONE; filesaver.readyState = filesaver.DONE;
@ -245,4 +250,4 @@ if (typeof module !== "undefined" && module.exports) {
define([], function() { define([], function() {
return saveAs; return saveAs;
}); });
} }
Loading…
Cancel
Save