mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Implement Item#layer.
This commit is contained in:
parent
ae116cd043
commit
936fd43c37
2 changed files with 21 additions and 4 deletions
|
@ -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.
|
* The item that this item is contained within.
|
||||||
|
@ -681,8 +694,6 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
|
||||||
return raster;
|
return raster;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a hit test on the item (and its children, if it is a
|
* 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.
|
* {@link Group} or {@link Layer}) at the location of the specified point.
|
||||||
|
|
|
@ -67,18 +67,24 @@ test('addChild(item)', function() {
|
||||||
}, 1);
|
}, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('item.parent / item.isChild / item.isParent', function() {
|
test('item.parent / item.isChild / item.isParent / item.layer', function() {
|
||||||
var project = paper.project;
|
var project = paper.project;
|
||||||
var secondDoc = new Project();
|
var secondDoc = new Project();
|
||||||
var path = new Path();
|
var path = new Path();
|
||||||
project.activeLayer.addChild(path);
|
project.activeLayer.addChild(path);
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return project.activeLayer.children.indexOf(path) != -1;
|
return project.activeLayer.children.indexOf(path) != -1;
|
||||||
|
}, true);
|
||||||
|
equals(function() {
|
||||||
|
return path.layer == project.activeLayer;
|
||||||
}, true);
|
}, true);
|
||||||
secondDoc.activeLayer.addChild(path);
|
secondDoc.activeLayer.addChild(path);
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return project.activeLayer.isChild(path);
|
return project.activeLayer.isChild(path);
|
||||||
}, false);
|
}, false);
|
||||||
|
equals(function() {
|
||||||
|
return path.layer == secondDoc.activeLayer;
|
||||||
|
}, true);
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return path.isParent(project.activeLayer);
|
return path.isParent(project.activeLayer);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
Loading…
Reference in a new issue