2011-03-06 19:50:44 -05:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
2011-03-07 20:41:50 -05:00
|
|
|
* http://paperjs.org/
|
2011-03-06 19:50:44 -05:00
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
2011-03-07 20:41:50 -05:00
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
2011-03-06 19:50:44 -05:00
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
2011-03-07 20:41:50 -05:00
|
|
|
* All rights reserved.
|
2011-03-06 19:50:44 -05:00
|
|
|
*/
|
|
|
|
|
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-04-21 09:47:00 -04:00
|
|
|
this._document = paper.document;
|
|
|
|
this._document.layers.push(this);
|
2011-02-12 10:20:10 -05:00
|
|
|
this.activate();
|
|
|
|
},
|
2011-02-15 19:18:58 -05:00
|
|
|
|
|
|
|
getIndex: function() {
|
2011-04-21 09:47:00 -04:00
|
|
|
return this.parent ? this.base() : this._document.layers.indexOf(this);
|
2011-02-15 19:18:58 -05:00
|
|
|
},
|
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-04-21 09:47:00 -04:00
|
|
|
return !!this._document.layers.splice(this.getIndex(), 1).length;
|
2011-02-16 12:55:12 -05:00
|
|
|
} else {
|
2011-03-04 16:34:14 -05:00
|
|
|
return this.base();
|
2011-02-16 12:55:12 -05:00
|
|
|
}
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-16 12:55:12 -05:00
|
|
|
getNextSibling: function() {
|
2011-03-04 16:34:14 -05:00
|
|
|
return this.parent ? this.base()
|
2011-04-21 09:47:00 -04:00
|
|
|
: this._document.layers[this.getIndex() + 1] || null;
|
2011-02-16 12:55:12 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-16 12:55:12 -05:00
|
|
|
getPreviousSibling: function() {
|
2011-03-04 16:34:14 -05:00
|
|
|
return this.parent ? this.base()
|
2011-04-21 09:47:00 -04:00
|
|
|
: this._document.layers[this.getIndex() - 1] || null;
|
2011-02-16 12:55:12 -05:00
|
|
|
},
|
2011-02-15 19:18:58 -05:00
|
|
|
|
2011-02-12 10:20:10 -05:00
|
|
|
activate: function() {
|
2011-04-21 09:47:00 -04:00
|
|
|
this._document.activeLayer = this;
|
2011-02-11 12:37:36 -05:00
|
|
|
}
|
2011-03-04 20:53:32 -05:00
|
|
|
}, new function () {
|
|
|
|
function move(above) {
|
|
|
|
return function(item) {
|
|
|
|
// if the item is a layer and contained within Document#layers
|
2011-05-07 09:34:57 -04:00
|
|
|
if (item instanceof Layer && !item.parent
|
|
|
|
&& this.removeFromParent()) {
|
2011-04-21 09:47:00 -04:00
|
|
|
item._document.layers.splice(item.getIndex() + (above ? 1 : -1),
|
2011-03-04 20:53:32 -05:00
|
|
|
0, this);
|
2011-04-21 09:47:00 -04:00
|
|
|
this.setDocument(item._document);
|
2011-03-04 20:53:32 -05:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return this.base(item);
|
|
|
|
}
|
2011-05-02 06:23:42 -04:00
|
|
|
};
|
2011-03-04 20:53:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
moveAbove: move(true),
|
|
|
|
|
|
|
|
moveBelow: move(false)
|
|
|
|
};
|
2011-02-13 11:26:24 -05:00
|
|
|
});
|