mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:27:58 +08:00
leveraged new eachAncestorReverse() method where possible
This commit is contained in:
35
src/Node.js
35
src/Node.js
@@ -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;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user