mirror of
https://github.com/konvajs/konva.git
synced 2025-12-04 19:08:24 +08:00
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:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -349,6 +349,13 @@ Kinetic.Stage.prototype = {
|
||||
*/
|
||||
getHeight: function() {
|
||||
return this.attrs.height;
|
||||
},
|
||||
/**
|
||||
* get shapes in point
|
||||
* @param {Object} point
|
||||
*/
|
||||
getShapesInPoint: function(pos) {
|
||||
|
||||
},
|
||||
/**
|
||||
* detect event
|
||||
|
||||
Reference in New Issue
Block a user