From 1e4a2760f93eb3b57638164a34311066cc69840d Mon Sep 17 00:00:00 2001 From: John Martin Date: Tue, 2 Oct 2012 14:20:32 +0100 Subject: [PATCH] Added fix js file for adding support for ECMA262-5 Array methods for browsers that don\'t support them --- _includes/recline-deps.html | 1 + src/ecma-fixes.js | 67 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/ecma-fixes.js diff --git a/_includes/recline-deps.html b/_includes/recline-deps.html index 1a72adb7..604f0c58 100644 --- a/_includes/recline-deps.html +++ b/_includes/recline-deps.html @@ -42,6 +42,7 @@ --> + diff --git a/src/ecma-fixes.js b/src/ecma-fixes.js new file mode 100644 index 00000000..de8148be --- /dev/null +++ b/src/ecma-fixes.js @@ -0,0 +1,67 @@ +// This file adds in full array method support in browsers that don't support it +// see: http://stackoverflow.com/questions/2790001/fixing-javascript-array-functions-in-internet-explorer-indexof-foreach-etc + +// Add ECMA262-5 Array methods if not supported natively +if (!('indexOf' in Array.prototype)) { + Array.prototype.indexOf= function(find, i /*opt*/) { + if (i===undefined) i= 0; + if (i<0) i+= this.length; + if (i<0) i= 0; + for (var n= this.length; ithis.length-1) i= this.length-1; + for (i++; i-->0;) /* i++ because from-argument is sadly inclusive */ + if (i in this && this[i]===find) + return i; + return -1; + }; +} +if (!('forEach' in Array.prototype)) { + Array.prototype.forEach= function(action, that /*opt*/) { + for (var i= 0, n= this.length; i