Found a clean way for Layer#initialize() to call this.base() too, without implicitely calling paper.project.activeLayer.appendTop.

This commit is contained in:
Jürg Lehni 2011-05-21 01:05:22 +01:00
parent 9f1172f24a
commit b461368b18
3 changed files with 9 additions and 9 deletions

View file

@ -18,7 +18,10 @@ var Item = this.Item = Base.extend({
beans: true,
initialize: function() {
paper.project.activeLayer.appendTop(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)
paper.project.activeLayer.appendTop(this);
this._style = PathStyle.create(this);
this.setStyle(this._project.getCurrentStyle());
},

View file

@ -17,14 +17,11 @@
var Layer = this.Layer = Group.extend({
beans: true,
initialize: function() {
// TODO: Isn't there a way to call this.base() here and then move the
// layer into layers instead?
this._children = [];
this._namedChildren = {};
initialize: function(items) {
this._project = paper.project;
// Push it onto project.layers and set index:
this._index = this._project.layers.push(this) - 1;
this.base.apply(this, arguments);
this.activate();
},

View file

@ -23,15 +23,15 @@ var Project = this.Project = Base.extend({
this._scope = paper;
// Push it onto this._scope.projects and set index:
this._index = this._scope.projects.push(this) - 1;
this._currentStyle = PathStyle.create(null);
this._selectedItems = {};
this._selectedItemCount = 0;
// Activate straight away so paper.project is set, as required by
// Layer and DoumentView constructors.
this.activate();
this.layers = [];
this.symbols = [];
this.activeLayer = new Layer();
this._selectedItems = {};
this._selectedItemCount = 0;
this._currentStyle = PathStyle.create(null);
},
getCurrentStyle: function() {