|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
/* FileSaver.js |
|
|
|
|
* A saveAs() FileSaver implementation. |
|
|
|
|
* 2015-03-04 |
|
|
|
|
* 2015-05-07.2 |
|
|
|
|
* |
|
|
|
|
* By Eli Grey, http://eligrey.com
|
|
|
|
|
* License: X11/MIT |
|
|
|
@ -12,16 +12,10 @@ |
|
|
|
|
|
|
|
|
|
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ |
|
|
|
|
|
|
|
|
|
var saveAs = saveAs |
|
|
|
|
// IE 10+ (native saveAs)
|
|
|
|
|
|| (typeof navigator !== "undefined" && |
|
|
|
|
navigator.msSaveOrOpenBlob && navigator.msSaveOrOpenBlob.bind(navigator)) |
|
|
|
|
// Everyone else
|
|
|
|
|
|| (function(view) { |
|
|
|
|
var saveAs = saveAs || (function(view) { |
|
|
|
|
"use strict"; |
|
|
|
|
// IE <10 is explicitly unsupported
|
|
|
|
|
if (typeof navigator !== "undefined" && |
|
|
|
|
/MSIE [1-9]\./.test(navigator.userAgent)) { |
|
|
|
|
if (typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
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) { |
|
|
|
|
blob = auto_bom(blob); |
|
|
|
|
// First try a.download, then web filesystem, then object URLs
|
|
|
|
|
var |
|
|
|
|
filesaver = this |
|
|
|
@ -135,10 +137,6 @@ var saveAs = saveAs |
|
|
|
|
revoke(object_url); |
|
|
|
|
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
|
|
|
|
|
// viewed in a tab, so I force save with application/octet-stream
|
|
|
|
|
// http://code.google.com/p/chromium/issues/detail?id=91158
|
|
|
|
@ -211,6 +209,13 @@ var saveAs = saveAs |
|
|
|
|
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() { |
|
|
|
|
var filesaver = this; |
|
|
|
|
filesaver.readyState = filesaver.DONE; |
|
|
|
@ -245,4 +250,4 @@ if (typeof module !== "undefined" && module.exports) { |
|
|
|
|
define([], function() { |
|
|
|
|
return saveAs; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |