Implement Item#layer.

This commit is contained in:
Jürg Lehni 2011-09-18 10:38:16 +02:00
parent ae116cd043
commit 936fd43c37
2 changed files with 21 additions and 4 deletions

View file

@ -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.

View file

@ -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);