Unify object initialization logic used in add and insertAt.

This commit is contained in:
kangax 2012-08-20 18:19:15 +02:00
parent 9594ba330f
commit fc194eeec1

View file

@ -359,15 +359,24 @@
add: function () {
this._objects.push.apply(this._objects, arguments);
for (var i = arguments.length; i--; ) {
this.stateful && arguments[i].setupState();
arguments[i].setCoords();
this.fire('object:added', { target: arguments[i] });
arguments[i].fire('added');
this._initObject(arguments[i]);
}
this.renderOnAddition && this.renderAll();
return this;
},
/**
* @private
* @method _initObject
*/
_initObject: function(obj) {
this.stateful && obj.setupState();
obj.setCoords();
obj.canvas = this;
this.fire('object:added', { target: obj });
obj.fire('added');
},
/**
* Inserts an object to canvas at specified index and renders canvas.
* An object should be an instance of (or inherit from) fabric.Object
@ -384,12 +393,7 @@
else {
this._objects.splice(index, 0, object);
}
this.stateful && object.setupState();
object.setCoords();
this.fire('object:added', { target: object });
object.fire('added');
this._initObject(object);
this.renderOnAddition && this.renderAll();
return this;
},