Commits

Shlomi Fish  committed 9fefa5f

Some hacks for old MSIEs.

But js-fc-solve still requires other stuff like Float64Array.

  • Participants
  • Parent commits 7790259

Comments (0)

Files changed (2)

File fc-solve/site/wml/src/js/common-hacks.js

+// Fix Uiint8Array / etc. on browsers that do not support it.
+// Taken from:
+// https://gist.github.com/1057924
+(function() {
+  try {
+    var a = new Uint8Array(1);
+    return; //no need
+  } catch(e) { }
+
+  function subarray(start, end) {
+    return this.slice(start, end);
+  }
+
+  function set_(array, offset) {
+    if (arguments.length < 2) offset = 0;
+    for (var i = 0, n = array.length; i < n; ++i, ++offset)
+      this[offset] = array[i] & 0xFF;
+  }
+
+  // we need typed arrays
+  function TypedArray(arg1) {
+    var result;
+    if (typeof arg1 === "number") {
+       result = new Array(arg1);
+       for (var i = 0; i < arg1; ++i)
+         result[i] = 0;
+    } else
+       result = arg1.slice(0);
+    result.subarray = subarray;
+    result.buffer = result;
+    result.byteLength = result.length;
+    result.set = set_;
+    if (typeof arg1 === "object" && arg1.buffer)
+      result.buffer = arg1.buffer;
+
+    return result;
+  }
+
+  window.Uint8Array = TypedArray;
+  window.Uint32Array = TypedArray;
+  window.Int32Array = TypedArray;
+})();
+
+
+(function() {
+  if ("response" in XMLHttpRequest.prototype ||
+      "mozResponseArrayBuffer" in XMLHttpRequest.prototype ||
+      "mozResponse" in XMLHttpRequest.prototype ||
+      "responseArrayBuffer" in XMLHttpRequest.prototype)
+    return;
+  Object.defineProperty(XMLHttpRequest.prototype, "response", {
+    get: function() {
+      return new Uint8Array( new VBArray(this.responseBody).toArray() );
+    }
+  });
+})();
+
+(function() {
+  if ("btoa" in window)
+    return;
+
+  var digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+
+  window.btoa = function(chars) {
+    var buffer = "";
+    var i, n;
+    for (i = 0, n = chars.length; i < n; i += 3) {
+      var b1 = chars.charCodeAt(i) & 0xFF;
+      var b2 = chars.charCodeAt(i + 1) & 0xFF;
+      var b3 = chars.charCodeAt(i + 2) & 0xFF;
+      var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
+      var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
+      var d4 = i + 2 < n ? (b3 & 0x3F) : 64;
+      buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
+    }
+    return buffer;
+  };
+})();

File fc-solve/site/wml/template.wml

 
 <define-tag my_extra_head_elements>
 <script type="text/javascript" src="$(ROOT)/js/common-methods.js"></script>
+<script type="text/javascript" src="$(ROOT)/js/common-hacks.js"></script>
 <script type="text/javascript" src="$(ROOT)/js/jq.js"></script>
 <link rel="alternate" type="application/rss+xml" title="Freecell Solver's Blog RSS Feed" href="<rss_feed />" />
 <link rel="alternate" type="application/atom+xml" title="Freecell Solver's Blog Atom Feed" href="http://fc-solve.blogspot.com/feeds/posts/default" />