diff --git a/src/Node.js b/src/Node.js index ad09d9bb..8bbdf62c 100644 --- a/src/Node.js +++ b/src/Node.js @@ -1397,7 +1397,7 @@ } }, _get: function(selector) { - return this.nodeType === selector ? [this] : []; + return this.className === selector || this.nodeType === selector ? [this] : []; }, _off: function(type, name) { var evtListeners = this.eventListeners[type], diff --git a/src/Shape.js b/src/Shape.js index 19b7f0ac..ed215d6d 100644 --- a/src/Shape.js +++ b/src/Shape.js @@ -99,9 +99,6 @@ hasStroke: function() { return !!(this.stroke() || this.strokeRed() || this.strokeGreen() || this.strokeBlue()); }, - _get: function(selector) { - return this.className === selector || this.nodeType === selector ? [this] : []; - }, /** * determines if point is in the shape, regardless if other shapes are on top of it. Note: because * this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times diff --git a/src/plugins/Label.js b/src/plugins/Label.js index dac4b7c6..114e36de 100644 --- a/src/plugins/Label.js +++ b/src/plugins/Label.js @@ -58,9 +58,9 @@ ____init: function(config) { var that = this; - this.className = LABEL; Kinetic.Group.call(this, config); - + this.className = LABEL; + this.on('add.kinetic', function(evt) { that._addListeners(evt.child); that._sync(); diff --git a/test/unit/plugins/Label-test.js b/test/unit/plugins/Label-test.js index 0b00da6a..b768b09d 100644 --- a/test/unit/plugins/Label-test.js +++ b/test/unit/plugins/Label-test.js @@ -80,4 +80,31 @@ suite('Label', function() { layer.add(label); stage.add(layer); }); + + test('find label class', function() { + var stage = addStage(); + var layer = new Kinetic.Layer(); + + var label = new Kinetic.Label({ + x: 100, + y: 100, + }); + + // add a tag to the label + label.add(new Kinetic.Tag({ + fill: '#bbb' + })); + + // add text to the label + label.add(new Kinetic.Text({ + text: 'Test Label', + fill: 'green' + })); + + layer.add(label); + stage.add(layer); + + assert.equal(stage.find('Label')[0], label); + }); + }); \ No newline at end of file