Okay, I think I found the answer:
I modified the _searchNode function so it will hide matching nodes greater than the level delimiter, but will show parent node(even non-matching) as long as the term matches within its children.
var clear = true;
DynaTreeNode.prototype.search = function (pattern,limit) {
if (typeof limit == "undefined") {
limit = 0;
}
if (pattern.length < 1 && !clear) {
clear = true;
this.visit(function (node) {
node.expand(true);
node.li.hidden = false;
node.expand(false);
});
} else if (pattern.length >= 1) {
clear = false;
this.visit(function (node) {
node.expand(true);
node.li.hidden = false;
});
var searchDepth = 1;
for (var i = 0; i < this.childList.length; i++) {
var hide = { hide: false };
this.childList[i]._searchNode(pattern, hide, searchDepth, limit);
}
}
},
// bottom-up node searching function
DynaTreeNode.prototype._searchNode = function (pattern, hide, searchDepth, limit) {
var level = searchDepth;
if (this.childList) {
// parent node
var hideNode = true;
var searchDepth = level+1;
for (var i = 0; i < this.childList.length; i++) {
var hideChild = { hide: false };
this.childList[i]._searchNode(pattern, hideChild, searchDepth, limit);
hideNode = hideNode && hideChild.hide;
}
if (hideNode && !this._isRightWithPattern(pattern)) {
this._hideNode();
hide.hide = true;
} else {
if (limit && level > limit) {
this._hideNode();
}
hide.hide = false;
}
} else {
// leaf
if (!this._isRightWithPattern(pattern)) {
this._hideNode();
hide.hide = true;
} else {
if (limit && level > limit) {
this._hideNode();
}
hide.hide = false;
}
}
}