diff --git a/src/item/Item.js b/src/item/Item.js index 0db84452..2448a601 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -441,7 +441,20 @@ var Item = this.Item = Base.extend(/** @lends Item# */{ } }, - // TODO: #getLayer() + /** + * The layer that this item is contained within. + * + * @type Layer + * @bean + */ + getLayer: function() { + var parent = this; + while (parent = parent._parent) { + if (parent instanceof Layer) + return parent; + } + return null; + }, /** * The item that this item is contained within. @@ -681,8 +694,6 @@ var Item = this.Item = Base.extend(/** @lends Item# */{ return raster; }, - - /** * Perform a hit test on the item (and its children, if it is a * {@link Group} or {@link Layer}) at the location of the specified point. diff --git a/test/tests/Item.js b/test/tests/Item.js index 95c35e62..c8b31a53 100644 --- a/test/tests/Item.js +++ b/test/tests/Item.js @@ -67,18 +67,24 @@ test('addChild(item)', function() { }, 1); }); -test('item.parent / item.isChild / item.isParent', function() { +test('item.parent / item.isChild / item.isParent / item.layer', function() { var project = paper.project; var secondDoc = new Project(); var path = new Path(); project.activeLayer.addChild(path); equals(function() { return project.activeLayer.children.indexOf(path) != -1; + }, true); + equals(function() { + return path.layer == project.activeLayer; }, true); secondDoc.activeLayer.addChild(path); equals(function() { return project.activeLayer.isChild(path); }, false); + equals(function() { + return path.layer == secondDoc.activeLayer; + }, true); equals(function() { return path.isParent(project.activeLayer); }, false);