server/php/basic/public_html/static/lib/FileSaver/FileSaver.js
changeset 495 444b80998255
parent 489 7f25a4453865
child 598 eb4f4eceada0
equal deleted inserted replaced
494:fd7bfe49155a 495:444b80998255
     1 /* FileSaver.js
     1 /* FileSaver.js
     2  * A saveAs() FileSaver implementation.
     2  * A saveAs() FileSaver implementation.
     3  * 2015-05-07.2
     3  * 1.1.20150716
     4  *
     4  *
     5  * By Eli Grey, http://eligrey.com
     5  * By Eli Grey, http://eligrey.com
     6  * License: X11/MIT
     6  * License: X11/MIT
     7  *   See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
     7  *   See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
     8  */
     8  */
    25 			return view.URL || view.webkitURL || view;
    25 			return view.URL || view.webkitURL || view;
    26 		}
    26 		}
    27 		, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
    27 		, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
    28 		, can_use_save_link = "download" in save_link
    28 		, can_use_save_link = "download" in save_link
    29 		, click = function(node) {
    29 		, click = function(node) {
    30 			var event = doc.createEvent("MouseEvents");
    30 			var event = new MouseEvent("click");
    31 			event.initMouseEvent(
       
    32 				"click", true, false, view, 0, 0, 0, 0, 0
       
    33 				, false, false, false, false, 0, null
       
    34 			);
       
    35 			node.dispatchEvent(event);
    31 			node.dispatchEvent(event);
    36 		}
    32 		}
    37 		, webkit_req_fs = view.webkitRequestFileSystem
    33 		, webkit_req_fs = view.webkitRequestFileSystem
    38 		, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
    34 		, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
    39 		, throw_outside = function(ex) {
    35 		, throw_outside = function(ex) {
    80 			if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
    76 			if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
    81 				return new Blob(["\ufeff", blob], {type: blob.type});
    77 				return new Blob(["\ufeff", blob], {type: blob.type});
    82 			}
    78 			}
    83 			return blob;
    79 			return blob;
    84 		}
    80 		}
    85 		, FileSaver = function(blob, name) {
    81 		, FileSaver = function(blob, name, no_auto_bom) {
    86 			blob = auto_bom(blob);
    82 			if (!no_auto_bom) {
       
    83 				blob = auto_bom(blob);
       
    84 			}
    87 			// First try a.download, then web filesystem, then object URLs
    85 			// First try a.download, then web filesystem, then object URLs
    88 			var
    86 			var
    89 				  filesaver = this
    87 				  filesaver = this
    90 				, type = blob.type
    88 				, type = blob.type
    91 				, blob_changed = false
    89 				, blob_changed = false
   129 			}
   127 			}
   130 			if (can_use_save_link) {
   128 			if (can_use_save_link) {
   131 				object_url = get_URL().createObjectURL(blob);
   129 				object_url = get_URL().createObjectURL(blob);
   132 				save_link.href = object_url;
   130 				save_link.href = object_url;
   133 				save_link.download = name;
   131 				save_link.download = name;
   134 				click(save_link);
   132 				setTimeout(function() {
   135 				filesaver.readyState = filesaver.DONE;
   133 					click(save_link);
   136 				dispatch_all();
   134 					dispatch_all();
   137 				revoke(object_url);
   135 					revoke(object_url);
       
   136 					filesaver.readyState = filesaver.DONE;
       
   137 				});
   138 				return;
   138 				return;
   139 			}
   139 			}
   140 			// Object and web filesystem URLs have a problem saving in Google Chrome when
   140 			// Object and web filesystem URLs have a problem saving in Google Chrome when
   141 			// viewed in a tab, so I force save with application/octet-stream
   141 			// viewed in a tab, so I force save with application/octet-stream
   142 			// http://code.google.com/p/chromium/issues/detail?id=91158
   142 			// http://code.google.com/p/chromium/issues/detail?id=91158
   203 					}));
   203 					}));
   204 				}), fs_error);
   204 				}), fs_error);
   205 			}), fs_error);
   205 			}), fs_error);
   206 		}
   206 		}
   207 		, FS_proto = FileSaver.prototype
   207 		, FS_proto = FileSaver.prototype
   208 		, saveAs = function(blob, name) {
   208 		, saveAs = function(blob, name, no_auto_bom) {
   209 			return new FileSaver(blob, name);
   209 			return new FileSaver(blob, name, no_auto_bom);
   210 		}
   210 		}
   211 	;
   211 	;
   212 	// IE 10+ (native saveAs)
   212 	// IE 10+ (native saveAs)
   213 	if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
   213 	if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
   214 		return function(blob, name) {
   214 		return function(blob, name, no_auto_bom) {
   215 			return navigator.msSaveOrOpenBlob(auto_bom(blob), name);
   215 			if (!no_auto_bom) {
       
   216 				blob = auto_bom(blob);
       
   217 			}
       
   218 			return navigator.msSaveOrOpenBlob(blob, name || "download");
   216 		};
   219 		};
   217 	}
   220 	}
   218 
   221 
   219 	FS_proto.abort = function() {
   222 	FS_proto.abort = function() {
   220 		var filesaver = this;
   223 		var filesaver = this;