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
416
attachment: jquery.dynatree.patch
(6.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
Index: web/lib/dynatree/1.2.4/dist/jquery.dynatree-1.2.4.js
===================================================================
--- web/lib/dynatree/1.2.4/dist/jquery.dynatree-1.2.4.js (revision )
+++ web/lib/dynatree/1.2.4/dist/jquery.dynatree.js (revision )
@@ -461,17 +461,23 @@
}
}
},
- /** Return '/id1/id2/id3'. */
- getKeyPath: function(excludeSelf) {
+
+ getPath: function(attribute, excludeSelf, pathSeparator) {
+ pathSeparator = pathSeparator || this.tree.options.pathSeparator;
var path = [];
this.visitParents(function(node){
if(node.parent){
- path.unshift(node.data.key);
+ path.unshift(node.data[attribute]);
}
}, !excludeSelf);
- return "/" + path.join(this.tree.options.keyPathSeparator);
+ return pathSeparator + path.join(pathSeparator);
},
+ /** Return '/id1/id2/id3'. */
+ getKeyPath: function(excludeSelf) {
+ return this.getPath("key", excludeSelf, this.tree.options.pathSeparator);
+ },
+
getParent: function() {
return this.parent;
},
@@ -1531,41 +1537,40 @@
// }
},
- /**
- * Make sure the node with a given key path is available in the tree.
- */
- _loadKeyPath: function(keyPath, callback) {
+ _loadPath: function(attr, path, callback, pathSeparator) {
+ pathSeparator = pathSeparator || this.options.pathSeparator;
+
var tree = this.tree;
- tree.logDebug("%s._loadKeyPath(%s)", this, keyPath);
- if(keyPath === ""){
- throw "Key path must not be empty";
+ tree.logDebug("%o._loadPath(%s, %s)", this, attr, path);
+ if(attr === ""){
+ throw "Path must not be empty";
}
- var segList = keyPath.split(tree.options.keyPathSeparator);
+ var segList = path.split(pathSeparator);
if(segList[0] === ""){
- throw "Key path must be relative (don't start with '/')";
+ throw "Path must be relative (don't start with '" + pathSeparator + "')";
}
var seg = segList.shift();
if(this.childList){
for(var i=0, l=this.childList.length; i < l; i++){
var child = this.childList[i];
- if( child.data.key === seg ){
+ if( child.data[attr] == seg ){
if(segList.length === 0) {
// Found the end node
callback.call(tree, child, "ok");
}else if(child.data.isLazy && (child.childList === null || child.childList === undefined)){
- tree.logDebug("%s._loadKeyPath(%s) -> reloading %s...", this, keyPath, child);
+ tree.logDebug("%o._loadPath(%s, %s) -> reloading %s...", this, attr, path, child.data);
var self = this;
// Note: this line gives a JSLint warning (Don't make functions within a loop)
/*jshint loopfunc:true */
child.reloadChildren(function(node, isOk){
- // After loading, look for direct child with that key
+ // After loading, look for direct child with that attribute
if(isOk){
- tree.logDebug("%s._loadKeyPath(%s) -> reloaded %s.", node, keyPath, node);
+ tree.logDebug("%o._loadPath(%s, %s) -> reloaded %s.", node, attr, path, node);
callback.call(tree, child, "loaded");
- node._loadKeyPath(segList.join(tree.options.keyPathSeparator), callback);
+ node._loadPath(attr, segList.join(pathSeparator), callback, pathSeparator);
}else{
- tree.logWarning("%s._loadKeyPath(%s) -> reloadChildren() failed.", self, keyPath);
+ tree.logWarning("%o._loadPath(%s, %s) -> reloadChildren() failed.", self, attr, path);
callback.call(tree, child, "error");
}
});
@@ -1573,20 +1578,27 @@
// See also http://stackoverflow.com/questions/3037598/how-to-get-around-the-jslint-error-dont-make-functions-within-a-loop
} else {
callback.call(tree, child, "loaded");
- // Look for direct child with that key
- child._loadKeyPath(segList.join(tree.options.keyPathSeparator), callback);
+ // Look for direct child with that attribute
+ child._loadPath(attr, segList.join(pathSeparator), callback, pathSeparator);
}
return;
}
}
}
- // Could not find key
+ // Could not find attribute
// Callback params: child: undefined, the segment, isEndNode (segList.length === 0)
callback.call(tree, undefined, "notfound", seg, segList.length === 0);
tree.logWarning("Node not found: " + seg);
return;
},
+ /**
+ * Make sure the node with a given key path is available in the tree.
+ */
+ _loadKeyPath: function(keyPath, callback) {
+ this._loadPath("key", keyPath, callback);
+ },
+
resetLazy: function() {
// Discard lazy content.
if( this.parent === null ){
@@ -2476,8 +2488,10 @@
return dtnode;
},
- loadKeyPath: function(keyPath, callback) {
- var segList = keyPath.split(this.options.keyPathSeparator);
+ loadPath: function(attr, path, callback, pathSeparator) {
+ pathSeparator = pathSeparator || this.options.pathSeparator;
+ var segList = path.split(pathSeparator);
+
// Remove leading '/'
if(segList[0] === ""){
segList.shift();
@@ -2487,10 +2501,14 @@
this.logDebug("Removed leading root key.");
segList.shift();
}
- keyPath = segList.join(this.options.keyPathSeparator);
- return this.tnRoot._loadKeyPath(keyPath, callback);
+ path = segList.join(pathSeparator);
+ return this.tnRoot._loadPath(attr, path, callback, pathSeparator);
},
+ loadKeyPath: function(keyPath, callback) {
+ return this.loadPath("key", keyPath, callback);
+ },
+
selectKey: function(key, select) {
var dtnode = this.getNodeByKey(key);
if( !dtnode ){
@@ -3180,7 +3198,7 @@
},
generateIds: false, // Generate id attributes like <span id='dynatree-id-KEY'>
idPrefix: "dynatree-id-", // Used to generate node id's like <span id="dynatree-id-<key>">.
- keyPathSeparator: "/", // Used by node.getKeyPath() and tree.loadKeyPath().
+ pathSeparator: "/", // Used by node.getPath() and tree.loadPath().
// cookieId: "dynatree-cookie", // Choose a more unique name, to allow multiple trees.
cookieId: "dynatree", // Choose a more unique name, to allow multiple trees.
cookie: {
Powered by
Google Project Hosting