Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
add #lastChild / #firstChild
Browse files Browse the repository at this point in the history
  • Loading branch information
brighthas committed Nov 18, 2013
1 parent 4504304 commit 655df99
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions index.js
Expand Up @@ -261,16 +261,31 @@ o.prevNode = function (childId) {
if (child) {
var parent = child.parent;
if(parent){
var index = child.position(),
prevChildId = parent._childIdsList[index - 1];
var index = child.position(),
prevChildId = parent._childIdsList[index - 1];

if (prevChildId) {
return parent.getChild(prevChildId);
}
if (prevChildId) {
return parent.getChild(prevChildId);
}
}
}
}

o.firstChild = function(childId){
var root = childId ? this._getNode(childId) : this;
if(root){
return root.getNode(root._childIdsList[0]);
}
}

o.lastChild = function(childId){
var root = childId ? this._getNode(childId) : this;
if(root){
var list = root._childIdsList,len = list.length;
return root.getNode(list[len-1]);
}
}

// move childId node to parentId node.
o.move = function (childId, parentId) {

Expand Down

0 comments on commit 655df99

Please sign in to comment.