1 /*! 2 3 JSZipUtils - A collection of cross-browser utilities to go along with JSZip. 4 <http://stuk.github.io/jszip-utils> 5 6 (c) 2014 Stuart Knightley, David Duponchel 7 Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip-utils/master/LICENSE.markdown. 8 9 */ 10 !function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.JSZipUtils=e():"undefined"!=typeof global?global.JSZipUtils=e():"undefined"!=typeof self&&(self.JSZipUtils=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 11 'use strict'; 12 13 var JSZipUtils = {}; 14 // just use the responseText with xhr1, response with xhr2. 15 // The transformation doesn't throw away high-order byte (with responseText) 16 // because JSZip handles that case. If not used with JSZip, you may need to 17 // do it, see https://developer.mozilla.org/En/Using_XMLHttpRequest#Handling_binary_data 18 JSZipUtils._getBinaryFromXHR = function (xhr) { 19 // for xhr.responseText, the 0xFF mask is applied by JSZip 20 return xhr.response || xhr.responseText; 21 }; 22 23 // taken from jQuery 24 function createStandardXHR() { 25 try { 26 return new window.XMLHttpRequest(); 27 } catch( e ) {} 28 } 29 30 function createActiveXHR() { 31 try { 32 return new window.ActiveXObject("Microsoft.XMLHTTP"); 33 } catch( e ) {} 34 } 35 36 // Create the request object 37 var createXHR = window.ActiveXObject ? 38 /* Microsoft failed to properly 39 * implement the XMLHttpRequest in IE7 (can't request local files), 40 * so we use the ActiveXObject when it is available 41 * Additionally XMLHttpRequest can be disabled in IE7/IE8 so 42 * we need a fallback. 43 */ 44 function() { 45 return createStandardXHR() || createActiveXHR(); 46 } : 47 // For all other browsers, use the standard XMLHttpRequest object 48 createStandardXHR; 49 50 51 52 JSZipUtils.getBinaryContent = function(path, callback) { 53 /* 54 * Here is the tricky part : getting the data. 55 * In firefox/chrome/opera/... setting the mimeType to 'text/plain; charset=x-user-defined' 56 * is enough, the result is in the standard xhr.responseText. 57 * cf https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Receiving_binary_data_in_older_browsers 58 * In IE <= 9, we must use (the IE only) attribute responseBody 59 * (for binary data, its content is different from responseText). 60 * In IE 10, the 'charset=x-user-defined' trick doesn't work, only the 61 * responseType will work : 62 * http://msdn.microsoft.com/en-us/library/ie/hh673569%28v=vs.85%29.aspx#Binary_Object_upload_and_download 63 * 64 * I'd like to use jQuery to avoid this XHR madness, but it doesn't support 65 * the responseType attribute : http://bugs.jquery.com/ticket/11461 66 */ 67 try { 68 69 var xhr = createXHR(); 70 71 xhr.open('GET', path, true); 72 73 // recent browsers 74 if ("responseType" in xhr) { 75 xhr.responseType = "arraybuffer"; 76 } 77 78 // older browser 79 if(xhr.overrideMimeType) { 80 xhr.overrideMimeType("text/plain; charset=x-user-defined"); 81 } 82 83 xhr.onreadystatechange = function(evt) { 84 var file, err; 85 // use `xhr` and not `this`... thanks IE 86 if (xhr.readyState === 4) { 87 if (xhr.status === 200 || xhr.status === 0) { 88 file = null; 89 err = null; 90 try { 91 file = JSZipUtils._getBinaryFromXHR(xhr); 92 } catch(e) { 93 err = new Error(e); 94 } 95 callback(err, file); 96 } else { 97 callback(new Error("Ajax error for " + path + " : " + this.status + " " + this.statusText), null); 98 } 99 } 100 }; 101 102 xhr.send(); 103 104 } catch (e) { 105 callback(new Error(e), null); 106 } 107 }; 108 109 // export 110 module.exports = JSZipUtils; 111 112 // enforcing Stuk's coding style 113 // vim: set shiftwidth=4 softtabstop=4: 114 115 },{}]},{},[1]) 116 (1) 117 }); 118 ;