Permalink
Browse files

Added search function to tree.

  • Loading branch information...
1 parent 397115e commit b19b78bd9ec10a7b0cb4286a64d015bcb5bc599a @frontierpsycho committed Sep 21, 2012
Showing with 18 additions and 2 deletions.
  1. +4 −2 canvas/static/loadtree.js
  2. +14 −0 templates/canvas/playground.html
View
6 canvas/static/loadtree.js
@@ -15,9 +15,11 @@ function loadTree(treedata, checked_nodes) {
return [feeling+"_check", 'feeling', feeling];
}
},
- plugins: ['themes', 'json_data', 'ui', 'checkbox']
+ 'search': {
+ 'show_only_matches': true
+ },
+ plugins: ['themes', 'json_data', 'ui', 'checkbox', 'search']
}).bind("loaded.jstree", function (event, data) {
- console.log(checked_nodes.length);
for(node in checked_nodes)
{
console.log(checked_nodes[node]);
View
14 templates/canvas/playground.html
@@ -15,6 +15,7 @@
{% block content %}
<div id="toolbox">
+ <input type="text" id="treeSearch" value"Search for feelings" /> <button id="searchButton">Search</button>
<form action="">
{% csrf_token %}
<div id="feelingtree"></div>
@@ -40,5 +41,18 @@
alert(this.getBBox().width);
} );
{% endfor %}
+
+ var timer;
+
+ $("#treeSearch").keyup(function() {
+ console.log("Clearing timeout...");
+ clearTimeout(timer); // Clear the timer so we don't end up with dupes.
+ var text = $(this).val();
+ timer = setTimeout(function() {
+ console.log("Executing...");
+ $("#feelingtree").jstree("search", text);
+ }, 500);
+ console.log("New timeout set.");
+ });
</script>
{% endblock %}

0 comments on commit b19b78b

Please sign in to comment.