add orderOfNodes function to tree library

pull/1/head
ansuz 9 years ago
parent 7689151fc0
commit 4eee1f5210

@ -146,7 +146,7 @@ define([], function () {
if (root && el.parentNode === root.childNodes[0]) { return null; }
return rightmostNode(previousNode(el.parentNode));
} else {
return rightmostNode(el.parentNode.childNodes[i-1])
return rightmostNode(el.parentNode.childNodes[i-1]);
}
};
@ -162,5 +162,22 @@ define([], function () {
}
};
var orderOfNodes = tree.orderOfNodes = function (a, b, root) {
// b might not be supplied
if (!b) { return; }
// a and b might be the same element
if (a === b) { return 0; }
var cur = b;
while (cur) {
cur = previousNode(cur, root);
// if you find 'a' while traversing backwards
// they are in the expected order
if (cur === a) { return 1; }
}
// otherwise
return -1;
};
return tree;
});

Loading…
Cancel
Save