Re-added Kinetic.Collection to _getNodes and a test confirming its necessity.

This commit is contained in:
David Johansson 2012-09-24 22:31:06 +02:00
parent 222addd579
commit 16c7cd2708
4 changed files with 54 additions and 10 deletions

View File

@ -2711,7 +2711,7 @@ Kinetic.Container.prototype = {
* get all shapes inside container
*/
_getNodes: function(sel) {
var arr = [];
var arr = new Kinetic.Collection();
function traverse(cont) {
var children = cont.getChildren();
for(var n = 0; n < children.length; n++) {

File diff suppressed because one or more lines are too long

View File

@ -229,7 +229,7 @@ Kinetic.Container.prototype = {
* get all shapes inside container
*/
_getNodes: function(sel) {
var arr = [];
var arr = new Kinetic.Collection();
function traverse(cont) {
var children = cont.getChildren();
for(var n = 0; n < children.length; n++) {

View File

@ -649,19 +649,63 @@ Test.prototype.tests = {
layer.add(circle);
layer.add(rect);
stage.add(layer);
var shapes = layer.get('.myShape');
test(shapes.length === 2, 'shapes array should have 2 elements');
shapes.apply('setX', 200);
layer.draw();
shapes.each(function() {
test(this.getX() === 200, 'shape x should be 200');
});
},
'SELECTOR - set fill on array by Shape-selector': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var circle = new Kinetic.Circle({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
radius: 70,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myShape'
});
var rect = new Kinetic.Rect({
x: 300,
y: 100,
width: 100,
height: 50,
fill: 'purple',
stroke: 'black',
strokeWidth: 4,
name: 'myShape'
});
layer.add(circle);
layer.add(rect);
stage.add(layer);
var shapes = layer.get('Shape');
test(shapes.length === 2, 'shapes array should have 2 elements');
shapes.apply('setFill', 'gray');
layer.draw();
shapes.each(function() {
test(this.getFill() === 'gray', 'shape x should be 200');
});
},
'SELECTOR - add listener to an array of nodes': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,