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 ($) {