Project

General

Profile

« Previous | Next » 

Revision 5663

prune the search tree - keep parents and children of matched nodes

View differences:

index.jsp
111 111
				function () {
112 112
					if ($("#" + divId + "Search").val().length >= 3) {
113 113
						$("#" + divId).jstree("search", $("#" + divId + "Search").val());
114
						// now prune
115
						prune(divId);
114 116
					}
115 117
				});
116 118

  
......
119 121
			//$("#" + divId).jstree("select_node", $(selectedNode));
120 122
		});
121 123
}
124
function prune(divId) {
125

  
126
	// show all nodes (reset)
127
	$("#" + divId).find("li").show();
128
	
129
	// get all non-matched anchor tags
130
	var nonmatches = $("#" + divId).find("a").not(".jstree-search");
131
	
132
	// get their parent nodes
133
	nonmatches = $(nonmatches).parents("li");
134

  
135
	// are there any matches under each parent node?
136
	$(nonmatches).each(
137
		function(index) {
138
			// do any chidren match?
139
			var childMatches = $(this).find("a.jstree-search");
140
			if (childMatches && childMatches.length > 0) {
141
				return true;
142
			}
143
			// parent matches?
144
			var parentMatches = $(this).parents("li").children("a.jstree-search");
145
			if (parentMatches && parentMatches.length > 0) {
146
				return true;
147
			}
148
			// hide this node if no matches under it
149
			$(this).hide();
150
		});
151
}
122 152
function initialize(source) {
123 153
	// we don't want to reload the source of the filtering request
124 154
	// but we do want to reload the other trees for active domains

Also available in: Unified diff