From 7fdf439ef28fce84b50144adad3b764e69f47c45 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Sat, 12 Feb 2011 19:12:23 +0100 Subject: [PATCH] Group: allow passing of array of items to constructor and pass on ctx in draw function. Add tests for Group. --- src/item/Group.js | 14 ++++++++++---- test/index.html | 1 + test/tests/Group.js | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 test/tests/Group.js diff --git a/src/item/Group.js b/src/item/Group.js index 029a34bd..b87c4d0a 100644 --- a/src/item/Group.js +++ b/src/item/Group.js @@ -1,12 +1,18 @@ -GroupItem = Item.extend({ - initialize: function() { +Group = Item.extend({ + initialize: function(items) { + this.base(); this.children = []; + if(items) { + for(var i = 0, l = items.length; i < l; i++) { + this.appendTop(items[i]); + } + } this.clipped = false; }, - draw: function() { + draw: function(ctx) { for(var i = 0, l = this.children.length; i < l; i++) { - this.children[i].draw(); + this.children[i].draw(ctx); } }, diff --git a/test/index.html b/test/index.html index 9fbb0834..aeec2083 100644 --- a/test/index.html +++ b/test/index.html @@ -28,6 +28,7 @@ + diff --git a/test/tests/Group.js b/test/tests/Group.js new file mode 100644 index 00000000..f5511b67 --- /dev/null +++ b/test/tests/Group.js @@ -0,0 +1,15 @@ +module('Group'); + +test('new Group()', function() { + var doc = new Doc(); + var group = new Group(); + equals(doc.activeLayer.children[0] == group, true); +}); + +test('new Group([item])', function() { + var doc = new Doc(); + var path = new Path(); + var group = new Group([path]); + equals(doc.activeLayer.children.length == 1, true); + equals(group.children[0] == path, true); +}); \ No newline at end of file