Define Item#style before calling #addChild() in #initialize(), to avoid issues with layers.

This commit is contained in:
Jürg Lehni 2014-03-01 22:49:46 +01:00
parent a3114e5c28
commit 7cf4591a1e

View file

@ -71,19 +71,20 @@ var Item = Base.extend(Callback, /** @lends Item# */{
_initialize: function(props, point) {
// Define this Item's unique id. But allow the creation of internally
// used paths with no ids.
var internal = props && props.internal === true;
var internal = props && props.internal === true,
matrix = this._matrix = new Matrix();
project = paper.project;
if (!internal)
this._id = Item._id = (Item._id || 0) + 1;
// Handle matrix before everything else, to avoid issues with
// #addChild() calling _changed() and accessing _matrix already.
var matrix = this._matrix = new Matrix();
if (point)
matrix.translate(point);
matrix._owner = this;
this._style = new Style(project._currentStyle, this);
// If _project is already set, the item was already moved into the DOM
// hierarchy. Used by Layer, where it's added to project.layers instead
if (!this._project) {
var project = paper.project;
// Do not insert into DOM if it's an internal path or
// props.insert is false.
if (internal || props && props.insert === false) {
@ -94,7 +95,6 @@ var Item = Base.extend(Callback, /** @lends Item# */{
(project.activeLayer || new Layer()).addChild(this);
}
}
this._style = new Style(this._project._currentStyle, this);
return props ? this._set(props, { insert: true }) : true;
},