-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsFamilyTree.html
191 lines (188 loc) · 6.91 KB
/
jsFamilyTree.html
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="libs/bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="libs/bootstrap/css/bootstrap-responsive.css">
<script type="text/javascript" src="libs/jquery/jquery.js"></script>
<script type="text/javascript" src="libs/bootstrap/js/bootstrap.min.js"></script>
<title></title>
<script type="text/javascript" src="dist/jstree.js"></script>
<script type="text/javascript">
var current_node;
$(function() {
$('#tree').bind("before.jstree", function (e, data) {
$("#alog").append(data.func + "<br />");
}).jstree({
themes:{
"theme":"apple"
},
"plugins" :
[
"themes","json_data","ui","crrm","cookies","dnd","search","types","hotkeys","contextmenu"
],
"search" : {
"case_insensitive" : true,
"ajax" : {
"url" : "/static/v.1.0pre/_docs/_search_result.json"
}
},
"json_data" : {
"data" : [
{
"attr" : { "id" : "root_node" },
"data" : "A closed node",
"state" : "closed"
}
],
"ajax" : {
"url" : "/static/v.1.0pre/_docs/_search_data.json",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
}
}
}})
.bind("select_node.jstree", function (event, data) {
current_node = data.rslt.obj;
})
.bind("search.jstree", function (event, data) {
alert("Found " + data.rslt.nodes.length + " nodes matching '" + data.rslt.str + "'.");
});
$("#search input").keyup(function () {
var content = $("#search input").val();
$("#tree").jstree("search",content);
});
});
$(function () {
$("#mmenu li").click(function () {
switch(this.id) {
case "addson":
if (current_node.attr("class").indexOf("wife") != -1){
alert("you cannot add a offspring from a wife!");
break;
}
new_node = $("#tree").jstree( "create_node", current_node,
{"title":$("#text").val(),
"li_attr":{ "class" : "male"}
},
"inside",
function(){
$("#tree").jstree( "open_node", current_node);
}
);
$("#tree").jstree( "edit", new_node );
break;
case "adddaughter":
if (current_node.attr("class").indexOf("wife") != -1){
alert("you cannot add a offspring from a wife!");
break;
}
new_node = $("#tree").jstree( "create_node", current_node,
{"title":$("#text").val(),
"li_attr":{ "class" : "female"}
},
"inside",
function(){
$("#tree").jstree( "open_node", current_node);
}
);
$("#tree").jstree( "edit", new_node );
break;
case "addwife":
if (current_node.attr("class").indexOf("wife") != -1){
alert("you cannot add a wife from a wife!");
break;
}
if (current_node.attr("class").indexOf("female") != -1){
alert("you cannot add a wife from a female!");
break;
}
new_node = $("#tree").jstree( "create_node", current_node,
{"title":$("#text").val(),
"li_attr":{ "class" : "female wife"}
},
"inside",
function(){
$("#tree").jstree( "open_node", current_node);
}
);
$("#tree").jstree( "edit", new_node );
$(".wife").children('a').children('i').attr("class","icon-heart");
break;
case "rename":
$("#tree").jstree( "edit", current_node);
break;
case "remove":
$("#tree").jstree("delete_node", current_node );
break;
case "expand":
$("#tree").jstree("open_all");
break;
case "close":
$("#tree").jstree("close_all");
break;
case "text": break;
default:
$("#tree").jstree(this.id);
break;
}
});
});
</script>
</head>
<body>
<div class="navbar navbar-static">
<div class="navbar-inner" style="margin: 2;">
<div class="container">
<a class="brand" href="#">Family Tree</a>
<ul class="nav" role="navigation">
<li class="dropdown">
<a role="button" href="#" class="dropdown-toggle" data-toggle="dropdown">Edit</a>
<ul class="dropdown-menu" id="mmenu">
<li id="addson"><a href="#">Add son</a></li>
<li id="adddaughter"><a href="#">Add daughter</a></li>
<li id="addwife"><a href="#">Add wife</a></li>
<li class="divider"></li>
<li id="rename"><a href="#">rename</a></li>
<li class="divider"></li>
<li id="remove"><a href="#">remove node</a></li>
</ul>
</li>
</ul>
<ul class="nav" role="navigation">
<li class="dropdown">
<a role="button" href="#" class="dropdown-toggle" data-toggle="dropdown">View</a>
<ul class="dropdown-menu" id="mmenu">
<li id="expand"><a href="#">expand all</a></li>
<li id="close"><a href="#">close all</a></li>
</ul>
</li>
</ul>
<form class="navbar-search pull-right" id="search">
<input type="text" class="search-query" placeholder="Search">
</form>
</div>
</div>
</div>
<div id="tree" style="margin-top:10px">
<ul>
<li><a href="">Richard</a>
<ul>
<li><a href="">Edward IV</a></li>
<li><a href="">Clarence</a></li>
<li><a href="">Richard III</a></li>
</ul></li>
</ul>
</div>
<div class="container" style="marginh:1000px">
</div>
<!--
<footer style='text-align:center;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 20px;
color: #333;'>
© 2012 Powered By OMeGa, rve Saito, nemomojie and starjesse. All rights reserved.
</footer>
-->
</body>
</html>