Merge pull request #515 from gaddie-3/master

Added the ability to pass multiple selectors to get()
This commit is contained in:
Eric Rowell
2013-07-21 14:53:14 -07:00

View File

@@ -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) {