added new selector capability to .get() method. You can now select all nodes by type inside of a container, such as by Shape, Group, or Layer

This commit is contained in:
Eric Rowell
2012-04-27 22:54:39 -07:00
parent 2879c0763f
commit 192681374d
5 changed files with 115 additions and 2 deletions

View File

@@ -71,6 +71,9 @@ Kinetic.Container.prototype = {
else if(selector.charAt(0) === '.') {
arr = stage.names[key] !== undefined ? stage.names[key] : [];
}
else if(selector === 'Shape' || selector === 'Group' || selector === 'Layer') {
return this._getNodes(selector);
}
else {
return false;
}
@@ -105,6 +108,27 @@ Kinetic.Container.prototype = {
return false;
},
/**
* get all shapes inside container
*/
_getNodes: function(sel) {
var arr = [];
function traverse(cont) {
var children = cont.getChildren();
for(var n = 0; n < children.length; n++) {
var child = children[n];
if(child.nodeType === sel) {
arr.push(child);
}
else if(child.nodeType !== 'Shape') {
traverse(child);
}
}
}
traverse(this);
return arr;
},
/**
* draw children
*/