mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
Merge pull request #515 from gaddie-3/master
Added the ability to pass multiple selectors to get()
This commit is contained in:
@@ -79,7 +79,8 @@
|
||||
},
|
||||
/**
|
||||
* return a {@link Kinetic.Collection} of nodes that match the selector. Use '#' for id selections
|
||||
* and '.' for name selections. You can also select by type or class name
|
||||
* and '.' for name selections. You can also select by type or class name. Pass multiple selectors
|
||||
* separated by a space.
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {String} selector
|
||||
@@ -95,10 +96,15 @@
|
||||
*
|
||||
* // select all rectangles inside layer<br>
|
||||
* var nodes = layer.get('Rect');
|
||||
*
|
||||
* // select node with an id of foo or a name of bar inside layer<br>
|
||||
* var nodes = layer.get('#foo .bar');
|
||||
*/
|
||||
get: function(selector) {
|
||||
var collection = new Kinetic.Collection();
|
||||
// ID selector
|
||||
selector = selector.split(" ");
|
||||
for (index = 0; index < selector.length; ++index) {
|
||||
if(selector.charAt(0) === '#') {
|
||||
var node = this._getNodeById(selector.slice(1));
|
||||
if(node) {
|
||||
@@ -120,6 +126,7 @@
|
||||
}
|
||||
Kinetic.Collection.apply(collection, retArr);
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
},
|
||||
_getNodeById: function(key) {
|
||||
|
Reference in New Issue
Block a user