mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Rename Item#children to private Item#_children and add #getChildren getter.
This commit is contained in:
parent
185a7f15ac
commit
0bab694a01
5 changed files with 84 additions and 73 deletions
|
@ -19,7 +19,7 @@ var Group = this.Group = Item.extend({
|
|||
|
||||
initialize: function(items) {
|
||||
this.base();
|
||||
this.children = [];
|
||||
this._children = [];
|
||||
if (items) {
|
||||
for (var i = 0, l = items.length; i < l; i++) {
|
||||
this.appendTop(items[i]);
|
||||
|
@ -53,8 +53,8 @@ var Group = this.Group = Item.extend({
|
|||
},
|
||||
|
||||
draw: function(ctx, param) {
|
||||
for (var i = 0, l = this.children.length; i < l; i++) {
|
||||
Item.draw(this.children[i], ctx, param);
|
||||
for (var i = 0, l = this._children.length; i < l; i++) {
|
||||
Item.draw(this._children[i], ctx, param);
|
||||
if (this._clipped && i == 0)
|
||||
ctx.clip();
|
||||
}
|
||||
|
|
125
src/item/Item.js
125
src/item/Item.js
|
@ -67,9 +67,9 @@ var Item = this.Item = Base.extend({
|
|||
},
|
||||
|
||||
setSelected: function(selected) {
|
||||
if (this.children) {
|
||||
for (var i = 0, l = this.children.length; i < l; i++) {
|
||||
this.children[i].setSelected(selected);
|
||||
if (this._children) {
|
||||
for (var i = 0, l = this._children.length; i < l; i++) {
|
||||
this._children[i].setSelected(selected);
|
||||
}
|
||||
} else {
|
||||
if ((selected = !!selected) != this._selected) {
|
||||
|
@ -82,9 +82,9 @@ var Item = this.Item = Base.extend({
|
|||
},
|
||||
|
||||
isSelected: function() {
|
||||
if (this.children) {
|
||||
for (var i = 0, l = this.children.length; i < l; i++) {
|
||||
if (this.children[i].isSelected()) {
|
||||
if (this._children) {
|
||||
for (var i = 0, l = this._children.length; i < l; i++) {
|
||||
if (this._children[i].isSelected()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -101,9 +101,9 @@ var Item = this.Item = Base.extend({
|
|||
_setDocument: function(document) {
|
||||
if (this._document != document) {
|
||||
this._document = document;
|
||||
if (this.children) {
|
||||
for (var i = 0, l = this.children.length; i < l; i++) {
|
||||
this.children[i]._setDocument(document);
|
||||
if (this._children) {
|
||||
for (var i = 0, l = this._children.length; i < l; i++) {
|
||||
this._children[i]._setDocument(document);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,49 +219,11 @@ var Item = this.Item = Base.extend({
|
|||
}
|
||||
},
|
||||
|
||||
// TODO: getIsolated / setIsolated (print specific feature)
|
||||
// TODO: get/setIsolated (print specific feature)
|
||||
// TODO: get/setKnockout (print specific feature)
|
||||
// TODO get/setAlphaIsShape
|
||||
// TODO: get/setData
|
||||
|
||||
/**
|
||||
* Reverses the order of this item's children
|
||||
*/
|
||||
reverseChildren: function() {
|
||||
if (this.children) {
|
||||
this.children.reverse();
|
||||
// TODO: Reassign _index
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The first item contained within this item.
|
||||
*/
|
||||
getFirstChild: function() {
|
||||
return this.children && this.children[0] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* The last item contained within this item.
|
||||
*/
|
||||
getLastChild: function() {
|
||||
return this.children && this.children[this.children.length - 1] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* The next item on the same level as this item.
|
||||
*/
|
||||
getNextSibling: function() {
|
||||
return this._parent && this._parent.children[this._index + 1] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* The previous item on the same level as this item.
|
||||
*/
|
||||
getPreviousSibling: function() {
|
||||
return this._parent && this._parent.children[this._index - 1] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* The item that this item is contained within.
|
||||
*/
|
||||
|
@ -269,6 +231,8 @@ var Item = this.Item = Base.extend({
|
|||
return this._parent;
|
||||
},
|
||||
|
||||
// TODO: #getLayer()
|
||||
|
||||
/**
|
||||
* The index of this item within the list of it's parent's children.
|
||||
*/
|
||||
|
@ -276,12 +240,59 @@ var Item = this.Item = Base.extend({
|
|||
return this._index;
|
||||
},
|
||||
|
||||
/**
|
||||
* The children items contained within this item.
|
||||
*/
|
||||
getChildren: function() {
|
||||
return this._children;
|
||||
},
|
||||
|
||||
// TODO: #setChildren()
|
||||
|
||||
/**
|
||||
* Reverses the order of this item's children
|
||||
*/
|
||||
reverseChildren: function() {
|
||||
// TODO: Reassign _index
|
||||
if (this._children) {
|
||||
this._children.reverse();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The first item contained within this item.
|
||||
*/
|
||||
getFirstChild: function() {
|
||||
return this._children && this._children[0] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* The last item contained within this item.
|
||||
*/
|
||||
getLastChild: function() {
|
||||
return this._children && this._children[this._children.length - 1] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* The next item on the same level as this item.
|
||||
*/
|
||||
getNextSibling: function() {
|
||||
return this._parent && this._parent._children[this._index + 1] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* The previous item on the same level as this item.
|
||||
*/
|
||||
getPreviousSibling: function() {
|
||||
return this._parent && this._parent._children[this._index - 1] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the item from its parent's children list.
|
||||
*/
|
||||
_removeFromParent: function() {
|
||||
if (this._parent) {
|
||||
var ok = !!Base.splice(this._parent.children, null,
|
||||
var ok = !!Base.splice(this._parent._children, null,
|
||||
this._index, 1).length;
|
||||
this._parent = null;
|
||||
this._index = null;
|
||||
|
@ -307,7 +318,7 @@ var Item = this.Item = Base.extend({
|
|||
* @return {@true if it has one or more children}
|
||||
*/
|
||||
hasChildren: function() {
|
||||
return this.children && this.children.length > 0;
|
||||
return this._children && this._children.length > 0;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -460,7 +471,7 @@ var Item = this.Item = Base.extend({
|
|||
},
|
||||
|
||||
_getBounds: function(includeStroke) {
|
||||
var children = this.children;
|
||||
var children = this._children;
|
||||
if (children && children.length) {
|
||||
var x1 = Infinity,
|
||||
x2 = -Infinity,
|
||||
|
@ -588,9 +599,9 @@ var Item = this.Item = Base.extend({
|
|||
// Transform position as well
|
||||
if (this._position)
|
||||
this._position = matrix._transformPoint(this._position);
|
||||
if (this.children) {
|
||||
for (var i = 0, l = this.children.length; i < l; i++) {
|
||||
var child = this.children[i];
|
||||
if (this._children) {
|
||||
for (var i = 0, l = this._children.length; i < l; i++) {
|
||||
var child = this._children[i];
|
||||
child.transform(matrix, flags);
|
||||
}
|
||||
}
|
||||
|
@ -819,8 +830,8 @@ var Item = this.Item = Base.extend({
|
|||
function append(top) {
|
||||
return function(item) {
|
||||
item._removeFromParent();
|
||||
if (this.children) {
|
||||
Base.splice(this.children, [item], top ? undefined : 0, 0);
|
||||
if (this._children) {
|
||||
Base.splice(this._children, [item], top ? undefined : 0, 0);
|
||||
item._parent = this;
|
||||
item._setDocument(this._document);
|
||||
return true;
|
||||
|
@ -833,7 +844,7 @@ var Item = this.Item = Base.extend({
|
|||
return function(item) {
|
||||
// first remove the item from its parent's children list
|
||||
if (item._parent && this._removeFromParent()) {
|
||||
Base.splice(item._parent.children, [this],
|
||||
Base.splice(item._parent._children, [this],
|
||||
item._index + (above ? 1 : -1), 0);
|
||||
this._parent = item._parent;
|
||||
this._setDocument(item._document);
|
||||
|
|
|
@ -18,7 +18,7 @@ var Layer = this.Layer = Group.extend({
|
|||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
this.children = [];
|
||||
this._children = [];
|
||||
this._document = paper.document;
|
||||
// Push it onto document.layers and set index:
|
||||
this._index = this._document.layers.push(this) - 1;
|
||||
|
|
|
@ -60,7 +60,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
|
|||
get = 'get' + part;
|
||||
|
||||
fields[set] = function(value) {
|
||||
var children = this._item && this._item.children;
|
||||
var children = this._item && this._item._children;
|
||||
value = isColor ? Color.read(arguments) : value;
|
||||
if (children) {
|
||||
for (var i = 0, l = children.length; i < l; i++)
|
||||
|
@ -79,7 +79,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
|
|||
};
|
||||
|
||||
fields[get] = function() {
|
||||
var children = this._item && this._item.children,
|
||||
var children = this._item && this._item._children,
|
||||
style;
|
||||
// If this item has children, walk through all of them and see if
|
||||
// they all have the same style.
|
||||
|
|
|
@ -18,7 +18,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
|
|||
// PORT: port the reversing of segments and keepDirection flag
|
||||
initialize: function(items, keepDirection) {
|
||||
this.base();
|
||||
this.children = [];
|
||||
this._children = [];
|
||||
if (items) {
|
||||
for (var i = 0, l = items.length; i < l; i++) {
|
||||
var item = items[i];
|
||||
|
@ -40,8 +40,8 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
|
|||
* @return the simplified compound path.
|
||||
*/
|
||||
simplify: function() {
|
||||
if (this.children.length == 1) {
|
||||
var child = this.children[0];
|
||||
if (this._children.length == 1) {
|
||||
var child = this._children[0];
|
||||
child.moveAbove(this);
|
||||
this.remove();
|
||||
return child;
|
||||
|
@ -50,16 +50,16 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
|
|||
},
|
||||
|
||||
smooth: function() {
|
||||
for (var i = 0, l = this.children.length; i < l; i++)
|
||||
this.children[i].smooth();
|
||||
for (var i = 0, l = this._children.length; i < l; i++)
|
||||
this._children[i].smooth();
|
||||
},
|
||||
|
||||
draw: function(ctx, param) {
|
||||
var firstChild = this.children[0];
|
||||
var firstChild = this._children[0];
|
||||
ctx.beginPath();
|
||||
param.compound = true;
|
||||
for (var i = 0, l = this.children.length; i < l; i++)
|
||||
Item.draw(this.children[i], ctx, param);
|
||||
for (var i = 0, l = this._children.length; i < l; i++)
|
||||
Item.draw(this._children[i], ctx, param);
|
||||
firstChild._setStyles(ctx);
|
||||
var fillColor = firstChild.getFillColor(),
|
||||
strokeColor = firstChild.getStrokeColor();
|
||||
|
@ -74,8 +74,8 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
|
|||
}
|
||||
}, new function() { // Injection scope for PostScript-like drawing functions
|
||||
function getCurrentPath(that) {
|
||||
if (that.children.length) {
|
||||
return that.children[that.children.length - 1];
|
||||
if (that._children.length) {
|
||||
return that._children[that._children.length - 1];
|
||||
} else {
|
||||
throw new Error('Use a moveTo() command first');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue