0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-27 13:59:01 -05:00

Use own Common.indexOf method for IE 6-8 compatibility

Conflicts:
	src/core/Common.js
This commit is contained in:
Jonathan Deutsch 2014-04-08 11:57:38 -07:00
parent 186d839942
commit b91af36575
5 changed files with 28 additions and 8 deletions

View file

@ -148,7 +148,7 @@ var Composite = {};
* @return {composite} The original compositeA with the composite removed * @return {composite} The original compositeA with the composite removed
*/ */
Composite.removeComposite = function(compositeA, compositeB, deep) { Composite.removeComposite = function(compositeA, compositeB, deep) {
var position = compositeA.composites.indexOf(compositeB); var position = Common.indexOf(compositeA.composites, compositeB);
if (position !== -1) { if (position !== -1) {
Composite.removeCompositeAt(compositeA, position); Composite.removeCompositeAt(compositeA, position);
Composite.setModified(compositeA, true, true, false); Composite.setModified(compositeA, true, true, false);
@ -198,7 +198,7 @@ var Composite = {};
* @return {composite} The original composite with the body removed * @return {composite} The original composite with the body removed
*/ */
Composite.removeBody = function(composite, body, deep) { Composite.removeBody = function(composite, body, deep) {
var position = composite.bodies.indexOf(body); var position = Common.indexOf(composite.bodies, body);
if (position !== -1) { if (position !== -1) {
Composite.removeBodyAt(composite, position); Composite.removeBodyAt(composite, position);
Composite.setModified(composite, true, true, false); Composite.setModified(composite, true, true, false);
@ -248,7 +248,7 @@ var Composite = {};
* @return {composite} The original composite with the constraint removed * @return {composite} The original composite with the constraint removed
*/ */
Composite.removeConstraint = function(composite, constraint, deep) { Composite.removeConstraint = function(composite, constraint, deep) {
var position = composite.constraints.indexOf(constraint); var position = Common.indexOf(composite.constraints, constraint);
if (position !== -1) { if (position !== -1) {
Composite.removeConstraintAt(composite, position); Composite.removeConstraintAt(composite, position);
} }

View file

@ -244,7 +244,7 @@ var Grid = {};
*/ */
var _bucketRemoveBody = function(grid, bucket, body) { var _bucketRemoveBody = function(grid, bucket, body) {
// remove from bucket // remove from bucket
bucket.splice(bucket.indexOf(body), 1); bucket.splice(Common.indexOf(bucket, body), 1);
// update pair counts // update pair counts
for (var i = 0; i < bucket.length; i++) { for (var i = 0; i < bucket.length; i++) {

View file

@ -85,7 +85,7 @@ var Pairs = {};
// deactivate previously active pairs that are now inactive // deactivate previously active pairs that are now inactive
for (i = 0; i < pairsList.length; i++) { for (i = 0; i < pairsList.length; i++) {
pair = pairsList[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); Pair.setActive(pair, false, timestamp);
collisionEnd.push(pair); collisionEnd.push(pair);
} }

View file

@ -278,4 +278,24 @@ var Common = {};
return Common._nextId++; 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;
};
})(); })();

View file

@ -203,7 +203,7 @@ var RenderPixi = {};
} }
// add to scene graph if not already there // add to scene graph if not already there
if (stage.children.indexOf(primitive) === -1) if (Common.indexOf(stage.children, primitive) === -1)
stage.addChild(primitive); stage.addChild(primitive);
// render the constraint on every update, since they can change dynamically // render the constraint on every update, since they can change dynamically
@ -249,7 +249,7 @@ var RenderPixi = {};
sprite = render.sprites[spriteId] = _createBodySprite(render, body); sprite = render.sprites[spriteId] = _createBodySprite(render, body);
// add to scene graph if not already there // add to scene graph if not already there
if (spriteBatch.children.indexOf(sprite) === -1) if (Common.indexOf(spriteBatch.children, sprite) === -1)
spriteBatch.addChild(sprite); spriteBatch.addChild(sprite);
// update body sprite // update body sprite
@ -268,7 +268,7 @@ var RenderPixi = {};
} }
// add to scene graph if not already there // add to scene graph if not already there
if (stage.children.indexOf(primitive) === -1) if (Common.indexOf(stage.children, primitive) === -1)
stage.addChild(primitive); stage.addChild(primitive);
// update body primitive // update body primitive