2011-03-04 08:34:31 -05:00
|
|
|
var Layer = this.Layer = Group.extend({
|
2011-02-15 19:18:58 -05:00
|
|
|
beans: true,
|
|
|
|
|
2011-02-11 12:37:36 -05:00
|
|
|
initialize: function() {
|
|
|
|
this.children = [];
|
2011-03-03 11:21:17 -05:00
|
|
|
this.document = paper.document;
|
2011-02-12 10:20:10 -05:00
|
|
|
this.document.layers.push(this);
|
|
|
|
this.activate();
|
|
|
|
},
|
2011-02-15 19:18:58 -05:00
|
|
|
|
|
|
|
getIndex: function() {
|
|
|
|
return !this.parent ? this.document.layers.indexOf(this) : this.base();
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-16 12:55:12 -05:00
|
|
|
/**
|
|
|
|
* Removes the layer from its document's layers list
|
|
|
|
* or its parent's children list.
|
|
|
|
*/
|
|
|
|
removeFromParent: function() {
|
2011-02-20 21:32:39 -05:00
|
|
|
if (!this.parent) {
|
2011-02-16 12:55:12 -05:00
|
|
|
this.document.layers.splice(this.index, 1);
|
|
|
|
} else {
|
|
|
|
this.base();
|
|
|
|
}
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-16 12:55:12 -05:00
|
|
|
moveAbove: function(item) {
|
|
|
|
// if the item is a layer and contained within Document#layers
|
2011-02-20 21:32:39 -05:00
|
|
|
if (item instanceof Layer && !item.parent) {
|
2011-02-16 12:55:12 -05:00
|
|
|
this.removeFromParent();
|
|
|
|
item.document.layers.splice(item.index + 1, 0, this);
|
|
|
|
this.document = item.document;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
this.base(item);
|
|
|
|
}
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-16 12:55:12 -05:00
|
|
|
moveBelow: function(item) {
|
|
|
|
// if the item is a layer and contained within Document#layers
|
2011-02-20 21:32:39 -05:00
|
|
|
if (item instanceof Layer && !item.parent) {
|
2011-02-16 12:55:12 -05:00
|
|
|
this.removeFromParent();
|
|
|
|
item.document.layers.splice(item.index - 1, 0, this);
|
|
|
|
this.document = item.document;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
this.base(item);
|
|
|
|
}
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-16 12:55:12 -05:00
|
|
|
getNextSibling: function() {
|
2011-02-20 21:32:39 -05:00
|
|
|
if (!this.parent) {
|
2011-02-16 12:55:12 -05:00
|
|
|
var index = this.index + 1;
|
|
|
|
if (index < this.document.layers.length)
|
|
|
|
return this.document.layers[index];
|
|
|
|
} else {
|
|
|
|
return this.base();
|
|
|
|
}
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-16 12:55:12 -05:00
|
|
|
getPreviousSibling: function() {
|
2011-02-20 21:32:39 -05:00
|
|
|
if (!this.parent) {
|
2011-02-16 12:55:12 -05:00
|
|
|
var index = this.index - 1;
|
|
|
|
if (index <= 0)
|
|
|
|
return this.document.layers[index];
|
|
|
|
} else {
|
|
|
|
return this.base();
|
|
|
|
}
|
|
|
|
},
|
2011-02-15 19:18:58 -05:00
|
|
|
|
2011-02-12 10:20:10 -05:00
|
|
|
activate: function() {
|
|
|
|
this.document.activeLayer = this;
|
2011-02-11 12:37:36 -05:00
|
|
|
}
|
2011-02-13 11:26:24 -05:00
|
|
|
});
|