From 0d9f8786f9f52eabb5c1c2515c4b710d21071509 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 5 Jun 2014 15:35:38 +0000 Subject: [PATCH] JS for IE8: failsafe console handling & others It's quite tricky to get this working. Still not perfect, but works as expected. Also added Function.bind and Array.indexOf - absence of both used to cause JS errors. refs #6417 --- public/js/helpers.js | 50 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/public/js/helpers.js b/public/js/helpers.js index 1b6fdb8d6..849df2b63 100644 --- a/public/js/helpers.js +++ b/public/js/helpers.js @@ -16,7 +16,28 @@ })(Object); -(function (console) { +(function (Array) { + + 'use strict'; + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function(elt) { + var len = this.length >>> 0; + + var from = Number(arguments[1]) || 0; + from = (from < 0) ? Math.ceil(from) : Math.floor(from); + if (from < 0) from += len; + + for (; from < len; from++) { + if (from in this && this[from] === elt) { + return from; + } + } + return -1; + }; + } +})(Array); + +if ('undefined' !== typeof console) { (function (console) { 'use strict'; @@ -40,7 +61,32 @@ console[method] = this.call(console[method], console); }, Function.prototype.bind); } -})(console); +})(console); } + +/* I intentionally moved this here, AFTER console handling */ +/* Could be switched, but please take care when doing so */ +if (!Function.prototype.bind) { + Function.prototype.bind = function (oThis) { + if (typeof this !== 'function') { + throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function () {}, + fBound = function () { + return fToBind.apply(this instanceof fNOP && oThis + ? this + : oThis, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + fNOP.prototype = this.prototype; + fBound.prototype = new fNOP(); + + return fBound; + }; +} /* jQuery Plugins */ (function ($) {