mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Layer: implement moveAbove / moveBelow / nextSibling / previousSibling
This commit is contained in:
parent
a7dc48951d
commit
3e2b4adc27
1 changed files with 57 additions and 1 deletions
|
@ -3,7 +3,7 @@ Layer = Item.extend({
|
|||
|
||||
initialize: function() {
|
||||
this.children = [];
|
||||
this.document = this.parent = Paper.document;
|
||||
this.document = Paper.document;
|
||||
this.document.layers.push(this);
|
||||
this.activate();
|
||||
},
|
||||
|
@ -12,6 +12,62 @@ Layer = Item.extend({
|
|||
return !this.parent ? this.document.layers.indexOf(this) : this.base();
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the layer from its document's layers list
|
||||
* or its parent's children list.
|
||||
*/
|
||||
removeFromParent: function() {
|
||||
if(!this.parent) {
|
||||
this.document.layers.splice(this.index, 1);
|
||||
} else {
|
||||
this.base();
|
||||
}
|
||||
},
|
||||
|
||||
moveAbove: function(item) {
|
||||
// if the item is a layer and contained within Document#layers
|
||||
if(item instanceof Layer && !item.parent) {
|
||||
this.removeFromParent();
|
||||
item.document.layers.splice(item.index + 1, 0, this);
|
||||
this.document = item.document;
|
||||
return true;
|
||||
} else {
|
||||
this.base(item);
|
||||
}
|
||||
},
|
||||
|
||||
moveBelow: function(item) {
|
||||
// if the item is a layer and contained within Document#layers
|
||||
if(item instanceof Layer && !item.parent) {
|
||||
this.removeFromParent();
|
||||
item.document.layers.splice(item.index - 1, 0, this);
|
||||
this.document = item.document;
|
||||
return true;
|
||||
} else {
|
||||
this.base(item);
|
||||
}
|
||||
},
|
||||
|
||||
getNextSibling: function() {
|
||||
if(!this.parent) {
|
||||
var index = this.index + 1;
|
||||
if (index < this.document.layers.length)
|
||||
return this.document.layers[index];
|
||||
} else {
|
||||
return this.base();
|
||||
}
|
||||
},
|
||||
|
||||
getPreviousSibling: function() {
|
||||
if(!this.parent) {
|
||||
var index = this.index - 1;
|
||||
if (index <= 0)
|
||||
return this.document.layers[index];
|
||||
} else {
|
||||
return this.base();
|
||||
}
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
this.document.activeLayer = this;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue