Skip to content

Commit

Permalink
Use own Common.indexOf method for IE 6-8 compatibility
Browse files Browse the repository at this point in the history
Conflicts:
	src/core/Common.js
  • Loading branch information
jmfd committed May 5, 2014
1 parent 186d839 commit b91af36
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/body/Composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var Composite = {};
* @return {composite} The original compositeA with the composite removed
*/
Composite.removeComposite = function(compositeA, compositeB, deep) {
var position = compositeA.composites.indexOf(compositeB);
var position = Common.indexOf(compositeA.composites, compositeB);
if (position !== -1) {
Composite.removeCompositeAt(compositeA, position);
Composite.setModified(compositeA, true, true, false);
Expand Down Expand Up @@ -198,7 +198,7 @@ var Composite = {};
* @return {composite} The original composite with the body removed
*/
Composite.removeBody = function(composite, body, deep) {
var position = composite.bodies.indexOf(body);
var position = Common.indexOf(composite.bodies, body);
if (position !== -1) {
Composite.removeBodyAt(composite, position);
Composite.setModified(composite, true, true, false);
Expand Down Expand Up @@ -248,7 +248,7 @@ var Composite = {};
* @return {composite} The original composite with the constraint removed
*/
Composite.removeConstraint = function(composite, constraint, deep) {
var position = composite.constraints.indexOf(constraint);
var position = Common.indexOf(composite.constraints, constraint);
if (position !== -1) {
Composite.removeConstraintAt(composite, position);
}
Expand Down
2 changes: 1 addition & 1 deletion src/collision/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ var Grid = {};
*/
var _bucketRemoveBody = function(grid, bucket, body) {
// remove from bucket
bucket.splice(bucket.indexOf(body), 1);
bucket.splice(Common.indexOf(bucket, body), 1);

// update pair counts
for (var i = 0; i < bucket.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/collision/Pairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var Pairs = {};
// deactivate previously active pairs that are now inactive
for (i = 0; i < pairsList.length; i++) {
pair = pairsList[i];
if (pair.isActive && activePairIds.indexOf(pair.id) === -1) {
if (pair.isActive && Common.indexOf(activePairIds, pair.id) === -1) {
Pair.setActive(pair, false, timestamp);
collisionEnd.push(pair);
}
Expand Down
20 changes: 20 additions & 0 deletions src/core/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,24 @@ var Common = {};
return Common._nextId++;
};

/**
* A wrapper for console.log, for providing errors and warnings
* @method indexOf
* @param {array} haystack
* @param {object} needle
*/
Common.indexOf = function(haystack, needle) {
if(haystack.indexOf) {
return haystack.indexOf(needle);
} else {
for(var i = 0; i < haystack.length; i++) {
if(haystack[i] == needle) {
return i;
}
}
}
return -1;
};


})();
6 changes: 3 additions & 3 deletions src/render/RenderPixi.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ var RenderPixi = {};
}

// add to scene graph if not already there
if (stage.children.indexOf(primitive) === -1)
if (Common.indexOf(stage.children, primitive) === -1)
stage.addChild(primitive);

// render the constraint on every update, since they can change dynamically
Expand Down Expand Up @@ -249,7 +249,7 @@ var RenderPixi = {};
sprite = render.sprites[spriteId] = _createBodySprite(render, body);

// add to scene graph if not already there
if (spriteBatch.children.indexOf(sprite) === -1)
if (Common.indexOf(spriteBatch.children, sprite) === -1)
spriteBatch.addChild(sprite);

// update body sprite
Expand All @@ -268,7 +268,7 @@ var RenderPixi = {};
}

// add to scene graph if not already there
if (stage.children.indexOf(primitive) === -1)
if (Common.indexOf(stage.children, primitive) === -1)
stage.addChild(primitive);

// update body primitive
Expand Down

0 comments on commit b91af36

Please sign in to comment.