Skip to content

Commit

Permalink
Add node.getSelectedNodes() method
Browse files Browse the repository at this point in the history
Close #542
  • Loading branch information
mar10 committed Jan 10, 2016
1 parent 5d34f24 commit 801d15f
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/jquery.fancytree.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,24 @@ FancytreeNode.prototype = /** @lends FancytreeNode# */{
}
return null;
},
/**
* Return an array of selected descendant nodes.
* @param {boolean} [stopOnParents=false] only return the topmost selected
* node (useful with selectMode 3)
* @returns {FancytreeNode[]}
*/
getSelectedNodes: function(stopOnParents) {
var nodeList = [];
this.visit(function(node){
if( node.selected ) {
nodeList.push(node);
if( stopOnParents === true ){
return "skip"; // stop processing this branch
}
}
});
return nodeList;
},
/** Return true if node has children. Return undefined if not sure, i.e. the node is lazy and not yet loaded).
* @returns {boolean | undefined}
*/
Expand Down Expand Up @@ -2246,16 +2264,7 @@ Fancytree.prototype = /** @lends Fancytree# */{
* @returns {FancytreeNode[]}
*/
getSelectedNodes: function(stopOnParents) {
var nodeList = [];
this.rootNode.visit(function(node){
if( node.selected ) {
nodeList.push(node);
if( stopOnParents === true ){
return "skip"; // stop processing this branch
}
}
});
return nodeList;
return this.rootNode.getSelectedNodes(stopOnParents);
},
/** Return true if the tree control has keyboard focus
* @returns {boolean}
Expand Down

0 comments on commit 801d15f

Please # to comment.