leveraged new eachAncestorReverse() method where possible

This commit is contained in:
Eric Rowell
2012-12-30 23:48:46 -08:00
parent 7ba40a6a68
commit 9cd0df651c

View File

@@ -440,8 +440,7 @@
* iterate through ancestors in reverse * iterate through ancestors in reverse
* @name eachAncestorReverse * @name eachAncestorReverse
* @methodOf Kinetic.Node.prototype * @methodOf Kinetic.Node.prototype
* @param {Function} func function is passed two arguments, a node and * @param {Function} func function is passed a node on each iteration
* the iterator integer
*/ */
eachAncestorReverse: function(func) { eachAncestorReverse: function(func) {
var family = [], parent = this.getParent(); var family = [], parent = this.getParent();
@@ -455,21 +454,7 @@
var len = family.length; var len = family.length;
for(var n = 0; n < len; n++) { for(var n = 0; n < len; n++) {
func(family[n], n); func(family[n]);
}
},
/**
* iterate through ancestors
* @name eachAncestor
* @methodOf Kinetic.Node.prototype
* @param {Function} func function is passed two arguments, a node and
* the iterator integer
*/
eachAncestor: function(func) {
var family = [], parent = this.getParent(), n = 0;
while(parent) {
func(parent, n++);
parent = parent.parent;
} }
}, },
/** /**
@@ -686,22 +671,10 @@
// absolute transform // absolute transform
var am = new Kinetic.Transform(); var am = new Kinetic.Transform();
var family = []; this.eachAncestorReverse(function(node) {
var parent = this.parent;
family.unshift(this);
while(parent) {
family.unshift(parent);
parent = parent.parent;
}
var len = family.length;
for(var n = 0; n < len; n++) {
var node = family[n];
var m = node.getTransform(); var m = node.getTransform();
am.multiply(m); am.multiply(m);
} });
return am; return am;
}, },
/** /**