if ($.fn.combotree) {
$.extend($.fn.combotree.defaults.keyHandler, {
query: function (q) {
var t = $(this).combotree('tree');
var nodes = t.tree('getChildren');
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if (node.text.toLowerCase().indexOf(q.toLowerCase()) >= 0) {
$(node.target).parents().show();
$(node.target).show();
} else {
$(node.target).hide();
}
}
var opts = $(this).combotree('options');
if (!opts.hasSetEvents) {
opts.hasSetEvents = true;
var onShowPanel = opts.onShowPanel;
opts.onShowPanel = function () {
var nodes = t.tree('getChildren');
for (var i = 0; i < nodes.length; i++) {
$(nodes[i].target).show();
}
onShowPanel.call(this);
};
$(this).combo('options').onShowPanel = opts.onShowPanel;
}
}
});
$.extend($.fn.combotree.methods, {
getSelectedItem: function (jq) {
var tree = jq.combotree("tree");
var opts = jq.combotree("options");
var panel = jq.combotree("panel");
var ret = [];
panel.find(".tree-node-selected").each(function () {
var row =tree.tree("getNode",this);
ret.push(row);
});
return opts.multiple ? ret : ret[0];
},
getSelectedItem_Ensure: function (jq) {
var item = jq.combotree("getSelectedItem");
var text = jq.combotree("getText");
var opts = jq.combotree("options");
if(opts.multiple)
return item;
if (!item)
return item;
if (item.text != text)
return null;
return item;
}
});
}
$.extend($.fn.combotree.defaults, {
onShowPanel: function () {
var _c = $(this).combo("panel");
var _d = _c.find(".tree-node-selected");
if (_d.length) {
if (_d.position().top <= 0) {
var h = _c.scrollTop() + _d.position().top;
_c.scrollTop(h);
} else {
if (_d.position().top + _d.outerHeight() > _c.height()) {
var h = _c.scrollTop() + _d.position().top + _d.outerHeight() - _c.height();
_c.scrollTop(h);
}
}
}
}
});