My favorites
▼
|
Sign in
dynatree
Dynatree is a JavaScript dynamic tree view plugin for jQuery with support for persistence, keyboard, checkboxes, drag'n'drop, and lazy loading.
Project Home
Downloads
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
446
attachment: treeview.html
(9.0 KB)
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"-->
<title>Dynatree - Example</title>
<script src="./jquery/jquery.cookie.js" type="text/javascript"></script>
<style type="text/css"></style>
<script src="./jquery/jquery.js" type="text/javascript"></script>
<script src="./jquery/jquery-ui.custom.js" type="text/javascript"></script>
<link href="./src/skin/ui.dynatree.css" rel="stylesheet" type="text/css" id="skinSheet">
<script src="./src/jquery.dynatree.js" type="text/javascript"></script>
<style type="text/css">
#trash.drophover {
border: 1px solid green;
}
</style>
<style type="text/css">
ul.dynatree-container span.td {
display: inline;
border-size: 0px;
background-color: white;
overflow: hidden;
}
ul.dynatree-container span.td:nth-child(1) {
}
ul.dynatree-container span.td:nth-child(2) {
color: grey;
}
</style>
<script type="text/javascript"><!--
function editNode(node){
var prevTitle = node.data.title,
tree = node.tree;
// Disable dynatree mouse- and key handling
tree.$widget.unbind();
// Replace node with <input>
$(".dynatree-title", node.span).html("<input id='editNode' value='" + prevTitle + "'>");
// Focus <input> and bind keyboard handler
$("input#editNode")
.focus()
.keydown(function(event){
switch( event.which ) {
case 27: // [esc]
// discard changes on [esc]
$("input#editNode").val(prevTitle);
$(this).blur();
break;
case 13: // [enter]
// simulate blur to accept new value
$(this).blur();
break;
}
}).blur(function(event){
// Accept new value, when user leaves <input>
var title = $("input#editNode").val();
node.setTitle(title);
// Re-enable mouse and keyboard handlling
tree.$widget.bind();
node.focus();
});
}
$(function(){
// --- Initialize first Dynatree -------------------------------------------
$("#tree").dynatree({
clickFolderMode: 1, // 1:activate only
initAjax: {
url: "dircache/root.json"
},
onLazyRead: function(node){
var fileName= "dircache/" + node.data.key + ".json";
node.appendAjax({
url: fileName,
success: function(node) {
var cmp = function(a, b) {
a = a.data.title.toLowerCase();
b = b.data.title.toLowerCase();
return a > b ? 1 : a < b ? -1 : 0;
};
node.sortChildren(cmp, true);
}
});
},
onActivate: function(node) {
if(node.data.isFolder) {
node.deactivate();
} else {
var path= (node.data.key).replace(/@/g, "//");;
var url= 'http://www.wothke.ch/tinyrsid/PlainPlaySid.php?sid=/' + path;
var ifrm = document.getElementById('ifrm');
ifrm.src= url;
var n2 = $("#tree2").dynatree("getActiveNode");
if( n2 ){
n2.deactivate();
}
}
// $("#echoActive").text(node.data.title + "(" + node.data.key + ")");
},
onDeactivate: function(node) {
// $("#echoActive").text("-");
},
dnd: {
onDragStart: function(node) {
/** This function MUST be defined to enable dragging for the tree.
* Return false to cancel dragging of node.
*/
if(node.data.isFolder)
return false;
return true;
},
onDragStop: function(node) {
}
}
});
// --- Initialize second Dynatree ------------------------------------------
$("#tree2").dynatree({
clickFolderMode: 1, // 1:activate only
initAjax: {
url: "empty.json"
},
onActivate: function(node) {
if(node.data.isFolder) {
node.deactivate();
} else {
var path= (node.data.filePath).replace(/@/g, "//");;
var url= 'http://www.wothke.ch/tinyrsid/PlainPlaySid.php?sid=/' + path;
var ifrm = document.getElementById('ifrm');
ifrm.src= url;
var n2 = $("#tree").dynatree("getActiveNode");
if( n2 ){
n2.deactivate();
}
}
},
onDeactivate: function(node) {
$("#echoActive2").text("-");
},
onLazyRead: function(node){
},
onCustomRender: function(node) {
// Render title as columns
if(!node.data.isFolder){
return false; // Default rendering
}
var cols = [node.data.title, " (by: "+node.data.creator+")"];
var html = "<a class='dynatree-title' href='#'>";
for(var i=0; i<cols.length; i++){
html += "<span class='td'>" + cols[i] + "</span>";
}
return html + "</a>";
},
onClick: function(node, event) {
if( node.data.isFolder ){
editNode(node);
return false;
}
},
dnd: {
autoExpandMS: 1000,
preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
onDragStart: function(node) {
if(node.data.isFolder)
return false;
return true;
},
onDragEnter: function(node, sourceNode) {
// make sure new entries cannot be dropped on existing playlist entries
if(sourceNode) {
var playListRoot= $("#tree2").dynatree("getTree").selectKey("playlistId");
if (node == playListRoot) {
return "over";
}
return ["before", "after"];; // disallow dropping on existing playlist entries
} else {
return false; // ignore non-dynatree droppables
}
},
onDragOver: function(node, sourceNode, hitMode) {
// problem: handling of the main "Playlist" node does not always work consistently when moving
// items within the playlist: sometimes it is possible to drag over the node and sometimes
// it is not - whenever it is possible the UI gets stuck when a respective drop is performed
// (similar situations also may occur with entries within the list)
if(sourceNode) {
var playListRoot= $("#tree2").dynatree("getTree").selectKey("playlistId");
if (node.data.key == playListRoot.data.key) {
if ((hitMode == "before") || (hitMode == "after")) {
return false; // disallow dropping outside "playlist"
} else {
return true; // allow dropping on main "playlist" node
}
}
if(hitMode == "over"){
return false; // disallow dropping on existing playlist enties
}
return true; // allow dropping between existing playlist entries
} else {
return false; // ignore non-dynatree droppables
}
},
onDrop: function(node, sourceNode, hitMode) {
// manage dropping within a flat "playlist" (see restrictions above)
var copynode;
if(sourceNode) {
var filePath= sourceNode.data.filePath; // moved nodes
if (!filePath) filePath= sourceNode.data.key; // newly dropped nodes
var newKey;
copynode = sourceNode.toDict(true, function(dict){
delete dict.key; // Remove key, so a new one will be created
dict.filePath= filePath;
});
var playListRoot= $("#tree2").dynatree("getTree").selectKey("playlistId");
var existingItem= $("#tree2").dynatree("getTree").selectKey(sourceNode.data.key);
if (existingItem) {
playListRoot.removeChild(existingItem);
}
if(hitMode == "over"){ // should only work for main "playlist" node (see onDragOver)
playListRoot.addChild(copynode);
playListRoot.expand(true);
}else if(hitMode == "before"){
node.parent.addChild(copynode, node);
}else if(hitMode == "after"){
node.parent.addChild(copynode, node.getNextSibling()); // Add after this
}
}
},
onDragLeave: function(node, sourceNode) {
}
}
});
// ---- handle the dropping of items into the trash -------------
$("#trash").droppable({
hoverClass: "drophover",
addClasses: true,
over: function(event, ui) {
},
drop: function(event, ui) {
var source = ui.helper.data("dtSourceNode") || ui.draggable;
var movedItem= $("#tree2").dynatree("getTree").selectKey(source.data.key);
if (movedItem) {
$("#tree2").dynatree("getTree").activateKey("playlistId");
var playListRoot= $("#tree2").dynatree("getTree").selectKey("playlistId");
playListRoot.removeChild(movedItem); // trash item
playListRoot.focus();
}
}
});
});
--></script>
</head>
<body class="example">
<h1>Example: Standard jQuery drag-and-drop</h1>
<p class="description">
This sample uses the standard jQuery draggable and droppable.
</p>
<table>
<thead>
<tr>
<th>
<p>This tree allows dragging.</p>
</th>
<th>
<p>This tree allows dropping.</p>
</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td>
<div id="tree"></div>
</td>
<td>
<div id="tree2" ></div>
<div id="trash" class="ui-widget-content ui-droppable">
<span style="vertical-align:top;">
<img width=20 height=20 src="trash_icon.gif"/>
</span>
<span style="vertical-align:top;">
drag here to remove
</span>
</div>
</td>
</tr>
<tr>
<td>
<div>Active node: <span id="echoActive">-</span></div>
</td>
<td>
<div>Active node: <span id="echoActive2">-</span></div>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</body></html>
Powered by
Google Project Hosting