X-Git-Url: http://git.roojs.org/?p=bootswatch;a=blobdiff_plain;f=bower_components%2Fbootstrap%2Fdocs-assets%2Fjs%2Fjszip.js;fp=bower_components%2Fbootstrap%2Fassets%2Fjs%2Fjszip.js;h=79a7654a4d088f8fa202e8ddfbfc0b5c66d5f91d;hp=037818903841eac934f3b339b9f22e92f8a1be11;hb=48c64127b37be4a692a70cb7b38ed9744163582b;hpb=620e501c3d804b1dc2c7d796d7ae378db5e1a040 diff --git a/bower_components/bootstrap/assets/js/jszip.js b/bower_components/bootstrap/docs-assets/js/jszip.js similarity index 96% rename from bower_components/bootstrap/assets/js/jszip.js rename to bower_components/bootstrap/docs-assets/js/jszip.js index 0378189..79a7654 100755 --- a/bower_components/bootstrap/assets/js/jszip.js +++ b/bower_components/bootstrap/docs-assets/js/jszip.js @@ -58,8 +58,62 @@ JSZip.defaults = { compression: null }; +/* + * List features that require a modern browser, and if the current browser support them. + */ +JSZip.support = { + // contains true if JSZip can read/generate ArrayBuffer, false otherwise. + arraybuffer : (function(){ + return typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined"; + })(), + // contains true if JSZip can read/generate nodejs Buffer, false otherwise. + nodebuffer : (function(){ + return typeof Buffer !== "undefined"; + })(), + // contains true if JSZip can read/generate Uint8Array, false otherwise. + uint8array : (function(){ + return typeof Uint8Array !== "undefined"; + })(), + // contains true if JSZip can read/generate Blob, false otherwise. + blob : (function(){ + // the spec started with BlobBuilder then replaced it with a construtor for Blob. + // Result : we have browsers that : + // * know the BlobBuilder (but with prefix) + // * know the Blob constructor + // * know about Blob but not about how to build them + // About the "=== 0" test : if given the wrong type, it may be converted to a string. + // Instead of an empty content, we will get "[object Uint8Array]" for example. + if (typeof ArrayBuffer === "undefined") { + return false; + } + var buffer = new ArrayBuffer(0); + try { + return new Blob([buffer], { type: "application/zip" }).size === 0; + } + catch(e) {} + + try { + var builder = new (window.BlobBuilder || window.WebKitBlobBuilder || + window.MozBlobBuilder || window.MSBlobBuilder)(); + builder.append(buffer); + return builder.getBlob('application/zip').size === 0; + } + catch(e) {} + + return false; + })() +}; JSZip.prototype = (function () { + var textEncoder, textDecoder; + if ( + JSZip.support.uint8array && + typeof TextEncoder === "function" && + typeof TextDecoder === "function" + ) { + textEncoder = new TextEncoder("utf-8"); + textDecoder = new TextDecoder("utf-8"); + } /** * Returns the raw data of a ZipObject, decompress the content if necessary. @@ -97,8 +151,8 @@ JSZip.prototype = (function () { if (!file.options.binary) { // unicode text ! // unicode string => binary string is a painful process, check if we can avoid it. - if (JSZip.support.uint8array && typeof TextEncoder === "function") { - return TextEncoder("utf-8").encode(result); + if (textEncoder) { + return textEncoder.encode(result); } if (JSZip.support.nodebuffer) { return new Buffer(result, "utf-8"); @@ -557,7 +611,7 @@ JSZip.prototype = (function () { */ file : function(name, data, o) { if (arguments.length === 1) { - if (name instanceof RegExp) { + if (JSZip.utils.isRegExp(name)) { var regexp = name; return this.filter(function(relativePath, file) { return !file.options.dir && regexp.test(relativePath); @@ -584,7 +638,7 @@ JSZip.prototype = (function () { return this; } - if (arg instanceof RegExp) { + if (JSZip.utils.isRegExp(arg)) { return this.filter(function(relativePath, file) { return file.options.dir && arg.test(relativePath); }); @@ -659,7 +713,7 @@ JSZip.prototype = (function () { if ( !this.files.hasOwnProperty(name) ) { continue; } var file = this.files[name]; - var compressionName = file.compression || options.compression.toUpperCase(); + var compressionName = file.options.compression || options.compression.toUpperCase(); var compression = JSZip.compressions[compressionName]; if (!compression) { throw new Error(compressionName + " is not a valid compression method !"); @@ -854,8 +908,8 @@ JSZip.prototype = (function () { // TextEncoder + Uint8Array to binary string is faster than checking every bytes on long strings. // http://jsperf.com/utf8encode-vs-textencoder // On short strings (file names for example), the TextEncoder API is (currently) slower. - if (JSZip.support.uint8array && typeof TextEncoder === "function") { - var u8 = TextEncoder("utf-8").encode(string); + if (textEncoder) { + var u8 = textEncoder.encode(string); return JSZip.utils.transformTo("string", u8); } if (JSZip.support.nodebuffer) { @@ -898,8 +952,8 @@ JSZip.prototype = (function () { // check if we can use the TextDecoder API // see http://encoding.spec.whatwg.org/#api - if (JSZip.support.uint8array && typeof TextDecoder === "function") { - return TextDecoder("utf-8").decode( + if (textDecoder) { + return textDecoder.decode( JSZip.utils.transformTo("uint8array", input) ); } @@ -960,52 +1014,6 @@ JSZip.compressions = { } }; -/* - * List features that require a modern browser, and if the current browser support them. - */ -JSZip.support = { - // contains true if JSZip can read/generate ArrayBuffer, false otherwise. - arraybuffer : (function(){ - return typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined"; - })(), - // contains true if JSZip can read/generate nodejs Buffer, false otherwise. - nodebuffer : (function(){ - return typeof Buffer !== "undefined"; - })(), - // contains true if JSZip can read/generate Uint8Array, false otherwise. - uint8array : (function(){ - return typeof Uint8Array !== "undefined"; - })(), - // contains true if JSZip can read/generate Blob, false otherwise. - blob : (function(){ - // the spec started with BlobBuilder then replaced it with a construtor for Blob. - // Result : we have browsers that : - // * know the BlobBuilder (but with prefix) - // * know the Blob constructor - // * know about Blob but not about how to build them - // About the "=== 0" test : if given the wrong type, it may be converted to a string. - // Instead of an empty content, we will get "[object Uint8Array]" for example. - if (typeof ArrayBuffer === "undefined") { - return false; - } - var buffer = new ArrayBuffer(0); - try { - return new Blob([buffer], { type: "application/zip" }).size === 0; - } - catch(e) {} - - try { - var builder = new (window.BlobBuilder || window.WebKitBlobBuilder || - window.MozBlobBuilder || window.MSBlobBuilder)(); - builder.append(buffer); - return builder.getBlob('application/zip').size === 0; - } - catch(e) {} - - return false; - })() -}; - (function () { JSZip.utils = { /** @@ -1120,12 +1128,36 @@ JSZip.support = { var chunk = 65536; var result = [], len = array.length, type = JSZip.utils.getTypeOf(array), k = 0; + var canUseApply = true; + try { + switch(type) { + case "uint8array": + String.fromCharCode.apply(null, new Uint8Array(0)); + break; + case "nodebuffer": + String.fromCharCode.apply(null, new Buffer(0)); + break; + } + } catch(e) { + canUseApply = false; + } + + // no apply : slow and painful algorithm + // default browser on android 4.* + if (!canUseApply) { + var resultStr = ""; + for(var i = 0; i < array.length;i++) { + resultStr += String.fromCharCode(array[i]); + } + return resultStr; + } + while (k < len && chunk > 1) { try { if (type === "array" || type === "nodebuffer") { - result.push(String.fromCharCode.apply(null, array.slice(k, Math.max(k + chunk, len)))); + result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len)))); } else { - result.push(String.fromCharCode.apply(null, array.subarray(k, k + chunk))); + result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len)))); } k += chunk; } catch (e) { @@ -1263,7 +1295,7 @@ JSZip.support = { if (typeof input === "string") { return "string"; } - if (input instanceof Array) { + if (Object.prototype.toString.call(input) === "[object Array]") { return "array"; } if (JSZip.support.nodebuffer && Buffer.isBuffer(input)) { @@ -1277,6 +1309,16 @@ JSZip.support = { } }; + /** + * Cross-window, cross-Node-context regular expression detection + * @param {Object} object Anything + * @return {Boolean} true if the object is a regular expression, + * false otherwise + */ + JSZip.utils.isRegExp = function (object) { + return Object.prototype.toString.call(object) === "[object RegExp]"; + }; + /** * Throw an exception if the type is not supported. * @param {String} type the type to check. @@ -1422,4 +1464,4 @@ JSZip.base64 = (function() { }()); // enforcing Stuk's coding style -// vim: set shiftwidth=3 softtabstop=3: \ No newline at end of file +// vim: set shiftwidth=3 softtabstop=3: