From d9b75a7232cd45635ea0da818e431d60e6032795 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Thu, 24 Feb 2011 19:31:07 +0100 Subject: [PATCH] Implement Item#reverseChildren() and add tests for it. --- src/item/Item.js | 8 +++++++- test/tests/item.js | 14 +++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 295e5759..dad79723 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -142,7 +142,13 @@ Item = Base.extend({ // TODO: get/setKnockout (print specific feature) // TODO get/setAlphaIsShape // TODO: get/setData - // TODO: reverseChildren + + /** + * Reverses the order of this item's children + */ + reverseChildren: function() { + this.children.reverse(); + }, /** * The first item contained within this item. diff --git a/test/tests/item.js b/test/tests/item.js index 1c141040..5185864b 100644 --- a/test/tests/item.js +++ b/test/tests/item.js @@ -132,4 +132,16 @@ test('hidden', function() { var firstPath = new Path(); firstPath.visible = false; equals(firstPath.hidden, true); -}); \ No newline at end of file +}); + +test('reverseChildren()', function() { + var doc = new Doc(); + var path = new Path(); + var secondPath = new Path(); + var thirdPath = new Path(); + equals(doc.activeLayer.firstChild == path, true); + doc.activeLayer.reverseChildren(); + equals(doc.activeLayer.firstChild == path, false); + equals(doc.activeLayer.firstChild == thirdPath, true); + equals(doc.activeLayer.lastChild == path, true); +}) \ No newline at end of file