index_IE.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* jshint evil: true, newcap: false */
  2. /* global IEBinaryToArray_ByteStr, IEBinaryToArray_ByteStr_Last */
  3. "use strict";
  4. // Adapted from http://stackoverflow.com/questions/1095102/how-do-i-load-binary-image-data-using-javascript-and-xmlhttprequest
  5. var IEBinaryToArray_ByteStr_Script =
  6. "<!-- IEBinaryToArray_ByteStr -->\r\n"+
  7. "<script type='text/vbscript'>\r\n"+
  8. "Function IEBinaryToArray_ByteStr(Binary)\r\n"+
  9. " IEBinaryToArray_ByteStr = CStr(Binary)\r\n"+
  10. "End Function\r\n"+
  11. "Function IEBinaryToArray_ByteStr_Last(Binary)\r\n"+
  12. " Dim lastIndex\r\n"+
  13. " lastIndex = LenB(Binary)\r\n"+
  14. " if lastIndex mod 2 Then\r\n"+
  15. " IEBinaryToArray_ByteStr_Last = Chr( AscB( MidB( Binary, lastIndex, 1 ) ) )\r\n"+
  16. " Else\r\n"+
  17. " IEBinaryToArray_ByteStr_Last = "+'""'+"\r\n"+
  18. " End If\r\n"+
  19. "End Function\r\n"+
  20. "</script>\r\n";
  21. // inject VBScript
  22. document.write(IEBinaryToArray_ByteStr_Script);
  23. global.JSZipUtils._getBinaryFromXHR = function (xhr) {
  24. var binary = xhr.responseBody;
  25. var byteMapping = {};
  26. for ( var i = 0; i < 256; i++ ) {
  27. for ( var j = 0; j < 256; j++ ) {
  28. byteMapping[ String.fromCharCode( i + (j << 8) ) ] =
  29. String.fromCharCode(i) + String.fromCharCode(j);
  30. }
  31. }
  32. var rawBytes = IEBinaryToArray_ByteStr(binary);
  33. var lastChr = IEBinaryToArray_ByteStr_Last(binary);
  34. return rawBytes.replace(/[\s\S]/g, function( match ) {
  35. return byteMapping[match];
  36. }) + lastChr;
  37. };
  38. // enforcing Stuk's coding style
  39. // vim: set shiftwidth=4 softtabstop=4: