forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.fancytree-tests.ts
95 lines (82 loc) · 2.22 KB
/
jquery.fancytree-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
///<reference path="jquery.fancytree.d.ts" />
$("#tree").fancytree({
source: [
{ title: "Node 1", key: "1" },
{
title: "Folder 2", key: "2", folder: true, children: [
{ title: "Node 2.1", key: "3" },
{ title: "Node 2.2", key: "4" },
{
foo: "bar",
baz: 17,
children: [
{ title: "Node 1", key: "1" },
{
title: "Folder 2", key: "2", folder: true, children: [
{ title: "Node 2.1", key: "3" },
{ title: "Node 2.2", key: "4" }
]
}
]
}
]
}
],
click: (ev: JQueryEventObject, node: Fancytree.EventData) => {
return true;
},
checkbox: true,
expand: () => {
console.log("expanded");
},
activate: function (event, data) {
// A node was activated: display its title:
var node = data.node;
console.log(node.title);
},
beforeSelect: function (event, data) {
// A node is about to be selected: prevent this for folders:
if (data.node.isFolder()) {
return false;
}
}
});
//$("#tree").fancytree();
var tree : Fancytree.Fancytree = $("#tree").fancytree("getTree");
var activeNode : Fancytree.FancytreeNode = tree.getRootNode();
// Sort children of active node:
activeNode.sortChildren();
// Expand all tree nodes
tree.visit(function (node) {
node.setExpanded(true);
});
// Append a new child node
activeNode.addChildren({
title: "Document using a custom icon",
icon: "customdoc1.gif"
});
tree.loadKeyPath("/1/2", function (node, status) {
if (status === "loaded") {
console.log("loaded intermiediate node " + node);
} else if (status === "ok") {
node.setActive();
}
});
var node = $.ui.fancytree.getNode($("#tree"));
alert($.ui.fancytree.version);
var f = $.ui.fancytree.debounce(50, (a : number) => { console.log(a); }, true);
f(2);
node = tree.getFirstChild();
node.setExpanded().done(function () {
alert("expand animation has finished");
});
// Get or set an option
var autoScroll = $("#tree").fancytree("option", "autoScroll");
$("#tree").fancytree("option", "autoCollapse", true);
// Disable the tree
$("#tree").fancytree("disable");
// Get the Fancytree instance for a tree widget
$("#tree").fancytree("enable");
alert("We have " + tree.count() + " nodes.");
// Use the API
node.setTitle("New title");