added new getAbsoluteZIndex() and getLevel() methods to Node

This commit is contained in:
Eric Rowell
2012-03-31 15:17:36 -07:00
parent 99d9381411
commit 8398670a47
4 changed files with 154 additions and 1 deletions

46
dist/kinetic-core.js vendored
View File

@@ -396,6 +396,52 @@ Kinetic.Node.prototype = {
getZIndex: function() {
return this.index;
},
/**
* get absolute z-index by taking into account
* all parent and sibling indices
*/
getAbsoluteZIndex: function() {
var level = this.getLevel();
var stage = this.getStage();
var that = this;
var index = 0;
function addChildren(children) {
var nodes = [];
for(var n = 0; n < children.length; n++) {
var child = children[n];
index++;
if(child.className !== 'Shape') {
nodes = nodes.concat(child.getChildren());
}
if(child.id === that.id) {
n = children.length;
}
}
if(nodes.length > 0 && nodes[0].getLevel() <= level) {
addChildren(nodes);
}
}
if(that.className !== 'Stage') {
addChildren(that.getStage().getChildren());
}
return index;
},
/**
* get node level in node tree
*/
getLevel: function() {
var level = 0;
var parent = this.parent;
while(parent) {
level++;
parent = parent.parent;
}
return level;
},
/**
* set node scale. If only one parameter is passed in,
* then both scaleX and scaleY are set with that parameter

File diff suppressed because one or more lines are too long