Mercurial > kallithea
changeset 4162:a1b80a0a3e15 rhodecode-2.2.5-gpl
rhodecode.js: update array.indexOf for backward compatibility
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf#Polyfill
under MIT license / public domain
https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 02 Jul 2014 19:03:26 -0400 |
parents | f51578556bc2 |
children | 5046b724a140 |
files | rhodecode/public/js/rhodecode.js |
diffstat | 1 files changed, 27 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/public/js/rhodecode.js Wed Jul 02 19:03:26 2014 -0400 +++ b/rhodecode/public/js/rhodecode.js Wed Jul 02 19:03:26 2014 -0400 @@ -58,14 +58,36 @@ return this.replace(new RegExp(''+char+'+$'),''); } - +/* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf#Polyfill + under MIT license / public domain, see + https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses */ if(!Array.prototype.indexOf) { - Array.prototype.indexOf = function(needle) { - for(var i = 0; i < this.length; i++) { - if(this[i] === needle) { - return i; + Array.prototype.indexOf = function (searchElement, fromIndex) { + if ( this === undefined || this === null ) { + throw new TypeError( '"this" is null or not defined' ); + } + + var length = this.length >>> 0; // Hack to convert object.length to a UInt32 + + fromIndex = +fromIndex || 0; + + if (Math.abs(fromIndex) === Infinity) { + fromIndex = 0; + } + + if (fromIndex < 0) { + fromIndex += length; + if (fromIndex < 0) { + fromIndex = 0; } } + + for (;fromIndex < length; fromIndex++) { + if (this[fromIndex] === searchElement) { + return fromIndex; + } + } + return -1; }; }