Skip to content

Commit af6e6e7

Browse files
committed
Merge branch 'master' of github.com:jsoma/tabletop
2 parents fe8d50d + a0d3c7b commit af6e6e7

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

src/tabletop.js

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,21 @@
2121
}
2222
} catch (e) { }
2323

24-
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
25-
if (!Array.prototype.indexOf) {
26-
Array.prototype.indexOf = function (searchElement, fromIndex) {
27-
if (this == null) {
28-
throw new TypeError();
29-
}
30-
var t = Object(this);
31-
var len = t.length >>> 0;
32-
if (len === 0) {
33-
return -1;
34-
}
35-
var n = 0;
36-
if (arguments.length > 1) {
37-
n = Number(arguments[1]);
38-
if (n != n) { // shortcut for verifying if it's NaN
39-
n = 0;
40-
} else if (n != 0 && n != Infinity && n != -Infinity) {
41-
n = (n > 0 || -1) * Math.floor(Math.abs(n));
42-
}
43-
}
44-
if (n >= len) {
45-
return -1;
46-
}
47-
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
48-
for (; k < len; k++) {
49-
if (k in t && t[k] === searchElement) {
50-
return k;
51-
}
52-
}
53-
return -1;
54-
}
55-
}
24+
// Create a simple indexOf function for support
25+
// of older browsers. Uses native indexOf if
26+
// available. Code similar to underscores.
27+
// By making a separate function, instead of adding
28+
// to the prototype, we will not break bad for loops
29+
// in older browsers
30+
var indexOfProto = Array.prototype.indexOf;
31+
var ttIndexOf = function(array, item) {
32+
var i = 0, l = array.length;
33+
34+
if (indexOfProto && array.indexOf === indexOfProto) return array.indexOf(item);
35+
for (; i < l; i++) if (array[i] === item) return i;
36+
return -1;
37+
};
38+
5639
/*
5740
Initialize with Tabletop.init( { key: '0AjAPaAU9MeLFdHUxTlJiVVRYNGRJQnRmSnQwTlpoUXc' } )
5841
OR!
@@ -268,7 +251,7 @@
268251
if(this.wanted.length === 0) {
269252
return true;
270253
} else {
271-
return this.wanted.indexOf(sheetName) !== -1;
254+
return (ttIndexOf(this.wanted, sheetName) !== -1);
272255
}
273256
},
274257

@@ -297,7 +280,7 @@
297280
Add another sheet to the wanted list
298281
*/
299282
addWanted: function(sheet) {
300-
if(this.wanted.indexOf(sheet) === -1) {
283+
if(ttIndexOf(this.wanted, sheet) === -1) {
301284
this.wanted.push(sheet);
302285
}
303286
},
@@ -371,7 +354,7 @@
371354
postProcess: this.postProcess,
372355
tabletop: this } );
373356
this.models[ model.name ] = model;
374-
if(this.model_names.indexOf(model.name) === -1) {
357+
if(ttIndexOf(this.model_names, model.name) === -1) {
375358
this.model_names.push(model.name);
376359
}
377360
this.sheetsToLoad--;

0 commit comments

Comments
 (0)