1
|
$(function() {
|
2
|
altair_tree.tree_a();
|
3
|
altair_tree.tree_b();
|
4
|
altair_tree.tree_filter();
|
5
|
});
|
6
|
|
7
|
altair_tree = {
|
8
|
tree_a: function() {
|
9
|
$("#tA").fancytree({
|
10
|
checkbox: true,
|
11
|
selectMode: 1,
|
12
|
imagePath: "assets/icons/others/",
|
13
|
extensions: ["dnd", "wide"],
|
14
|
autoScroll: true,
|
15
|
activate: function(event, data) {
|
16
|
var node = data.node;
|
17
|
// Use <a> href and target attributes to load the content:
|
18
|
if( node.data.href ){
|
19
|
// Open target
|
20
|
window.open(node.data.href, node.data.target);
|
21
|
}
|
22
|
}
|
23
|
});
|
24
|
},
|
25
|
tree_b: function() {
|
26
|
$("#tB").fancytree({
|
27
|
checkbox: true,
|
28
|
selectMode: 3,
|
29
|
imagePath: "assets/icons/others/",
|
30
|
extensions: ["dnd", "wide"],
|
31
|
autoScroll: true,
|
32
|
activate: function(event, data) {
|
33
|
var node = data.node;
|
34
|
// Use <a> href and target attributes to load the content:
|
35
|
if( node.data.href ){
|
36
|
// Open target
|
37
|
window.open(node.data.href, node.data.target);
|
38
|
}
|
39
|
}
|
40
|
});
|
41
|
},
|
42
|
tree_filter: function() {
|
43
|
// filter
|
44
|
var $tFilter = $("#tFilter");
|
45
|
$tFilter.fancytree({
|
46
|
extensions: ["filter"],
|
47
|
quicksearch: true,
|
48
|
source: {
|
49
|
url: "data/fancytree/ajax-tree-local.json"
|
50
|
},
|
51
|
filter: {
|
52
|
autoApply: true, // Re-apply last filter if lazy data is loaded
|
53
|
counter: true, // Show a badge with number of matching child nodes near parent icons
|
54
|
fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar'
|
55
|
hideExpandedCounter: true, // Hide counter badge, when parent is expanded
|
56
|
highlight: true, // Highlight matches by wrapping inside <mark> tags
|
57
|
mode: "dimm" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
|
58
|
},
|
59
|
activate: function(event, data) {
|
60
|
// alert("activate " + data.node);
|
61
|
},
|
62
|
lazyLoad: function(event, data) {
|
63
|
data.result = {
|
64
|
url: "data/fancytree/ajax-sub2.json"
|
65
|
}
|
66
|
}
|
67
|
});
|
68
|
var tree = $tFilter.fancytree("getTree");
|
69
|
|
70
|
|
71
|
$("#filter_input").keyup(function(e){
|
72
|
var n,
|
73
|
opts = {
|
74
|
autoExpand: $("#autoExpand").is(":checked"),
|
75
|
leavesOnly: $("#leavesOnly").is(":checked")
|
76
|
},
|
77
|
match = $(this).val();
|
78
|
|
79
|
if(e && e.which === $.ui.keyCode.ESCAPE || $.trim(match) === ""){
|
80
|
$("#tree_filter_reset").click();
|
81
|
return;
|
82
|
}
|
83
|
|
84
|
if($("#tree_filter_regex").is(":checked")) {
|
85
|
// Pass function to perform match
|
86
|
n = tree.filterNodes(function(node) {
|
87
|
return new RegExp(match, "i").test(node.title);
|
88
|
}, opts);
|
89
|
} else {
|
90
|
// Pass a string to perform case insensitive matching
|
91
|
n = tree.filterNodes(match, opts);
|
92
|
}
|
93
|
$("#tree_filter_reset").attr("disabled", false);
|
94
|
|
95
|
});
|
96
|
|
97
|
// reset filter
|
98
|
$("#tree_filter_reset").click(function(e){
|
99
|
$("#filter_input").val("");
|
100
|
tree.clearFilter();
|
101
|
}).attr("disabled", true);
|
102
|
|
103
|
$("#filter_switches").find("input:checkbox").on('ifChanged', function(e){
|
104
|
var id = $(this).attr("id"),
|
105
|
flag = $(this).is(":checked");
|
106
|
|
107
|
switch( id ) {
|
108
|
case "autoExpand":
|
109
|
case "regex":
|
110
|
case "leavesOnly":
|
111
|
// Re-apply filter only
|
112
|
break;
|
113
|
case "hideMode":
|
114
|
tree.options.filter.mode = flag ? "hide" : "dimm";
|
115
|
break;
|
116
|
case "counter":
|
117
|
case "fuzzy":
|
118
|
case "hideExpandedCounter":
|
119
|
case "highlight":
|
120
|
tree.options.filter[id] = flag;
|
121
|
break;
|
122
|
}
|
123
|
tree.clearFilter();
|
124
|
$("#filter_input").keyup();
|
125
|
});
|
126
|
|
127
|
// activate filters
|
128
|
$("#counter,#hideExpandedCounter,#highlight").iCheck('check');
|
129
|
|
130
|
}
|
131
|
};
|