mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-21 14:34:43 +00:00
Unify object initialization logic used in add and insertAt.
This commit is contained in:
parent
9594ba330f
commit
fc194eeec1
1 changed files with 14 additions and 10 deletions
|
|
@ -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;
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue