Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add nextDepthNode & prevDepthNode

  • Loading branch information...
commit 661277860a35faa1bc7fcd305869146ef08c2d18 1 parent 9c4d872
@brighthas brighthas authored
Showing with 43 additions and 3 deletions.
  1. +18 −2 index.js
  2. +25 −1 test/index.js
View
20 index.js
@@ -243,7 +243,6 @@ o.down = function (childId) {
o.nextNode = function (childId) {
var child = childId? this._getNode(childId) : this;
- if (child) {
var parent = child.parent;
if(parent){
var index = child.position(),
@@ -253,12 +252,20 @@ o.nextNode = function (childId) {
return parent.getChild(nextChildId);
}
}
+}
+
+o.nextDepthNode = function nextDeepNode(childId) {
+ var node = childId? this._getNode(childId) : this;
+ var firstChild = node.firstChild();
+ if(firstChild){
+ return firstChild;
+ }else{
+ return node.nextNode();
}
}
o.prevNode = function (childId) {
var child = childId ? this._getNode(childId) : this;
- if (child) {
var parent = child.parent;
if(parent){
var index = child.position(),
@@ -268,6 +275,15 @@ o.prevNode = function (childId) {
return parent.getChild(prevChildId);
}
}
+}
+
+o.prevDepthNode = function prevDeepNode(childId) {
+ var child = childId ? this._getNode(childId) : this;
+ var prevNode = child.prevNode();
+ if(prevNode){
+ return child.depthLastChild();
+ }else{
+ return child.parent;
}
}
View
26 test/index.js
@@ -234,5 +234,29 @@ describe("Node",function(){
assert(root.allChildIds.length === 2)
})
-
+ it("#nextDepthNode",function(){
+ var root = new Node();
+ var n1 = new Node;
+ var n2 = new Node;
+ var n3 = new Node;
+ var o = root.appendChild(n1).appendChild(n2);
+ n2.appendChild(n3);
+ var nn = root.nextDepthNode().nextDepthNode().nextDepthNode();
+ assert(nn === n3)
+ })
+
+ it("#prevDepthNode",function(){
+ var root = new Node();
+ var n1 = new Node;
+ var n2 = new Node;
+ var n3 = new Node;
+ var o = root.appendChild(n1).appendChild(n2);
+ n2.appendChild(n3);
+ var nn = n3.prevDepthNode();
+
+ assert(nn === n2)
+ })
+
+
+
});
Please sign in to comment.
Something went wrong with that request. Please try again.