| 119 |
ghuddy |
1 |
/*----------------------------------------------------------------------------\
|
|
|
2 |
| Cross Browser Tree Widget 1.12 |
|
|
|
3 |
|-----------------------------------------------------------------------------|
|
|
|
4 |
| Created by Emil A Eklund |
|
|
|
5 |
| (http://webfx.eae.net/contact.html#emil) |
|
|
|
6 |
| For WebFX (http://webfx.eae.net/) |
|
|
|
7 |
|-----------------------------------------------------------------------------|
|
|
|
8 |
| An object based tree widget, emulating the one found in microsoft windows, |
|
|
|
9 |
| with persistence using cookies. Works in IE 5+, Mozilla and konqueror 3. |
|
|
|
10 |
|-----------------------------------------------------------------------------|
|
|
|
11 |
| Copyright (c) 1999 - 2002 Emil A Eklund |
|
|
|
12 |
|-----------------------------------------------------------------------------|
|
|
|
13 |
| This software is provided "as is", without warranty of any kind, express or |
|
|
|
14 |
| implied, including but not limited to the warranties of merchantability, |
|
|
|
15 |
| fitness for a particular purpose and noninfringement. In no event shall the |
|
|
|
16 |
| authors or copyright holders be liable for any claim, damages or other |
|
|
|
17 |
| liability, whether in an action of contract, tort or otherwise, arising |
|
|
|
18 |
| from, out of or in connection with the software or the use or other |
|
|
|
19 |
| dealings in the software. |
|
|
|
20 |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
|
|
21 |
| This software is available under the three different licenses mentioned |
|
|
|
22 |
| below. To use this software you must chose, and qualify, for one of those. |
|
|
|
23 |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
|
|
24 |
| The WebFX Non-Commercial License http://webfx.eae.net/license.html |
|
|
|
25 |
| Permits anyone the right to use the software in a non-commercial context |
|
|
|
26 |
| free of charge. |
|
|
|
27 |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
|
|
28 |
| The WebFX Commercial license http://webfx.eae.net/commercial.html |
|
|
|
29 |
| Permits the license holder the right to use the software in a commercial |
|
|
|
30 |
| context. Such license must be specifically obtained, however it's valid for |
|
|
|
31 |
| any number of implementations of the licensed software. |
|
|
|
32 |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
|
|
33 |
| GPL - The GNU General Public License http://www.gnu.org/licenses/gpl.txt |
|
|
|
34 |
| Permits anyone the right to use and modify the software without limitations |
|
|
|
35 |
| as long as proper credits are given and the original and modified source |
|
|
|
36 |
| code are included. Requires that the final product, software derivate from |
|
|
|
37 |
| the original source or any software utilizing a GPL component, such as |
|
|
|
38 |
| this, is also licensed under the GPL license. |
|
|
|
39 |
|-----------------------------------------------------------------------------|
|
|
|
40 |
| 2001-01-10 | Original Version Posted. |
|
|
|
41 |
| 2001-03-18 | Added getSelected and get/setBehavior that can make it behave |
|
|
|
42 |
| | more like windows explorer, check usage for more information. |
|
|
|
43 |
| 2001-09-23 | Version 1.1 - New features included keyboard navigation (ie) |
|
|
|
44 |
| | and the ability to add and remove nodes dynamically and some |
|
|
|
45 |
| | other small tweaks and fixes. |
|
|
|
46 |
| 2002-01-27 | Version 1.11 - Bug fixes and improved mozilla support. |
|
|
|
47 |
| 2002-06-11 | Version 1.12 - Fixed a bug that prevented the indentation line |
|
|
|
48 |
| | from updating correctly under some circumstances. This bug |
|
|
|
49 |
| | happened when removing the last item in a subtree and items in |
|
|
|
50 |
| | siblings to the remove subtree where not correctly updated. |
|
|
|
51 |
| 2002-06-13 | Fixed a few minor bugs cased by the 1.12 bug-fix. |
|
|
|
52 |
|-----------------------------------------------------------------------------|
|
|
|
53 |
| Created 2000-12-11 | All changes are in the log above. | Updated 2002-06-11 |
|
|
|
54 |
\----------------------------------------------------------------------------*/
|
|
|
55 |
|
|
|
56 |
var webFXTreeConfig = {
|
|
|
57 |
rootIcon : 'images/foldericon.png',
|
|
|
58 |
openRootIcon : 'images/openfoldericon.png',
|
|
|
59 |
folderIcon : 'images/foldericon.png',
|
|
|
60 |
openFolderIcon : 'images/openfoldericon.png',
|
|
|
61 |
fileIcon : 'images/file.png',
|
|
|
62 |
iIcon : 'images/I.png',
|
|
|
63 |
lIcon : 'images/L.png',
|
|
|
64 |
lMinusIcon : 'images/Lminus.png',
|
|
|
65 |
lPlusIcon : 'images/Lplus.png',
|
|
|
66 |
tIcon : 'images/T.png',
|
|
|
67 |
tMinusIcon : 'images/Tminus.png',
|
|
|
68 |
tPlusIcon : 'images/Tplus.png',
|
|
|
69 |
blankIcon : 'images/blank.png',
|
|
|
70 |
defaultText : 'Tree Item',
|
|
|
71 |
defaultAction : 'javascript:void(0);',
|
|
|
72 |
defaultBehavior : 'classic'
|
|
|
73 |
};
|
|
|
74 |
|
|
|
75 |
var webFXTreeHandler = {
|
|
|
76 |
idCounter : 0,
|
|
|
77 |
idPrefix : "webfx-tree-object-",
|
|
|
78 |
all : {},
|
|
|
79 |
behavior : null,
|
|
|
80 |
selected : null,
|
|
|
81 |
onSelect : null, /* should be part of tree, not handler */
|
|
|
82 |
getId : function() { return this.idPrefix + this.idCounter++; },
|
|
|
83 |
toggle : function (oItem) { this.all[oItem.id.replace('-plus','')].toggle(); },
|
|
|
84 |
select : function (oItem) { this.all[oItem.id.replace('-icon','')].select(); },
|
|
|
85 |
focus : function (oItem) { this.all[oItem.id.replace('-anchor','')].focus(); },
|
|
|
86 |
blur : function (oItem) { this.all[oItem.id.replace('-anchor','')].blur(); },
|
|
|
87 |
keydown : function (oItem, e) { return this.all[oItem.id].keydown(e.keyCode); },
|
|
|
88 |
cookies : new WebFXCookie(),
|
|
|
89 |
insertHTMLBeforeEnd : function (oElement, sHTML) {
|
|
|
90 |
if (oElement.insertAdjacentHTML != null) {
|
|
|
91 |
oElement.insertAdjacentHTML("BeforeEnd", sHTML)
|
|
|
92 |
return;
|
|
|
93 |
}
|
|
|
94 |
var df; // DocumentFragment
|
|
|
95 |
var r = oElement.ownerDocument.createRange();
|
|
|
96 |
r.selectNodeContents(oElement);
|
|
|
97 |
r.collapse(false);
|
|
|
98 |
df = r.createContextualFragment(sHTML);
|
|
|
99 |
oElement.appendChild(df);
|
|
|
100 |
}
|
|
|
101 |
};
|
|
|
102 |
|
|
|
103 |
/*
|
|
|
104 |
* WebFXCookie class
|
|
|
105 |
*/
|
|
|
106 |
|
|
|
107 |
function WebFXCookie() {
|
|
|
108 |
if (document.cookie.length) { this.cookies = ' ' + document.cookie; }
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
WebFXCookie.prototype.setCookie = function (key, value) {
|
|
|
112 |
document.cookie = key + "=" + escape(value);
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
WebFXCookie.prototype.getCookie = function (key) {
|
|
|
116 |
if (this.cookies) {
|
|
|
117 |
var start = this.cookies.indexOf(' ' + key + '=');
|
|
|
118 |
if (start == -1) { return null; }
|
|
|
119 |
var end = this.cookies.indexOf(";", start);
|
|
|
120 |
if (end == -1) { end = this.cookies.length; }
|
|
|
121 |
end -= start;
|
|
|
122 |
var cookie = this.cookies.substr(start,end);
|
|
|
123 |
return unescape(cookie.substr(cookie.indexOf('=') + 1, cookie.length - cookie.indexOf('=') + 1));
|
|
|
124 |
}
|
|
|
125 |
else { return null; }
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/*
|
|
|
129 |
* WebFXTreeAbstractNode class
|
|
|
130 |
*/
|
|
|
131 |
|
|
|
132 |
function WebFXTreeAbstractNode(sText, sAction) {
|
|
|
133 |
this.childNodes = [];
|
|
|
134 |
this.id = webFXTreeHandler.getId();
|
|
|
135 |
this.text = sText || webFXTreeConfig.defaultText;
|
|
|
136 |
this.action = sAction || webFXTreeConfig.defaultAction;
|
|
|
137 |
this._last = false;
|
|
|
138 |
webFXTreeHandler.all[this.id] = this;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
/*
|
|
|
142 |
* To speed thing up if you're adding multiple nodes at once (after load)
|
|
|
143 |
* use the bNoIdent parameter to prevent automatic re-indentation and call
|
|
|
144 |
* the obj.ident() method manually once all nodes has been added.
|
|
|
145 |
*/
|
|
|
146 |
|
|
|
147 |
WebFXTreeAbstractNode.prototype.add = function (node, bNoIdent) {
|
|
|
148 |
node.parentNode = this;
|
|
|
149 |
this.childNodes[this.childNodes.length] = node;
|
|
|
150 |
var root = this;
|
|
|
151 |
if (this.childNodes.length >=2) {
|
|
|
152 |
this.childNodes[this.childNodes.length -2]._last = false;
|
|
|
153 |
}
|
|
|
154 |
while (root.parentNode) { root = root.parentNode; }
|
|
|
155 |
if (root.rendered) {
|
|
|
156 |
if (this.childNodes.length >= 2) {
|
|
|
157 |
document.getElementById(this.childNodes[this.childNodes.length -2].id + '-plus').src = ((this.childNodes[this.childNodes.length -2].folder)?((this.childNodes[this.childNodes.length -2].open)?webFXTreeConfig.tMinusIcon:webFXTreeConfig.tPlusIcon):webFXTreeConfig.tIcon);
|
|
|
158 |
if (this.childNodes[this.childNodes.length -2].folder) {
|
|
|
159 |
this.childNodes[this.childNodes.length -2].plusIcon = webFXTreeConfig.tPlusIcon;
|
|
|
160 |
this.childNodes[this.childNodes.length -2].minusIcon = webFXTreeConfig.tMinusIcon;
|
|
|
161 |
}
|
|
|
162 |
this.childNodes[this.childNodes.length -2]._last = false;
|
|
|
163 |
}
|
|
|
164 |
this._last = true;
|
|
|
165 |
var foo = this;
|
|
|
166 |
while (foo.parentNode) {
|
|
|
167 |
for (var i = 0; i < foo.parentNode.childNodes.length; i++) {
|
|
|
168 |
if (foo.id == foo.parentNode.childNodes[i].id) { break; }
|
|
|
169 |
}
|
|
|
170 |
if (++i == foo.parentNode.childNodes.length) { foo.parentNode._last = true; }
|
|
|
171 |
else { foo.parentNode._last = false; }
|
|
|
172 |
foo = foo.parentNode;
|
|
|
173 |
}
|
|
|
174 |
webFXTreeHandler.insertHTMLBeforeEnd(document.getElementById(this.id + '-cont'), node.toString());
|
|
|
175 |
if ((!this.folder) && (!this.openIcon)) {
|
|
|
176 |
this.icon = webFXTreeConfig.folderIcon;
|
|
|
177 |
this.openIcon = webFXTreeConfig.openFolderIcon;
|
|
|
178 |
}
|
|
|
179 |
if (!this.folder) { this.folder = true; this.collapse(true); }
|
|
|
180 |
if (!bNoIdent) { this.indent(); }
|
|
|
181 |
}
|
|
|
182 |
return node;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
WebFXTreeAbstractNode.prototype.toggle = function() {
|
|
|
186 |
if (this.folder) {
|
|
|
187 |
if (this.open) { this.collapse(); }
|
|
|
188 |
else { this.expand(); }
|
|
|
189 |
} }
|
|
|
190 |
|
|
|
191 |
WebFXTreeAbstractNode.prototype.select = function() {
|
|
|
192 |
document.getElementById(this.id + '-anchor').focus();
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
WebFXTreeAbstractNode.prototype.deSelect = function() {
|
|
|
196 |
document.getElementById(this.id + '-anchor').className = '';
|
|
|
197 |
webFXTreeHandler.selected = null;
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
WebFXTreeAbstractNode.prototype.focus = function() {
|
|
|
201 |
if ((webFXTreeHandler.selected) && (webFXTreeHandler.selected != this)) { webFXTreeHandler.selected.deSelect(); }
|
|
|
202 |
webFXTreeHandler.selected = this;
|
|
|
203 |
if ((this.openIcon) && (webFXTreeHandler.behavior != 'classic')) { document.getElementById(this.id + '-icon').src = this.openIcon; }
|
|
|
204 |
document.getElementById(this.id + '-anchor').className = 'selected';
|
|
|
205 |
document.getElementById(this.id + '-anchor').focus();
|
|
|
206 |
if (webFXTreeHandler.onSelect) { webFXTreeHandler.onSelect(this); }
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
WebFXTreeAbstractNode.prototype.blur = function() {
|
|
|
210 |
if ((this.openIcon) && (webFXTreeHandler.behavior != 'classic')) { document.getElementById(this.id + '-icon').src = this.icon; }
|
|
|
211 |
document.getElementById(this.id + '-anchor').className = 'selected-inactive';
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
WebFXTreeAbstractNode.prototype.doExpand = function() {
|
|
|
215 |
if (webFXTreeHandler.behavior == 'classic') { document.getElementById(this.id + '-icon').src = this.openIcon; }
|
|
|
216 |
if (this.childNodes.length) { document.getElementById(this.id + '-cont').style.display = 'block'; }
|
|
|
217 |
this.open = true;
|
|
|
218 |
webFXTreeHandler.cookies.setCookie(this.id.substr(18,this.id.length - 18), '1');
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
WebFXTreeAbstractNode.prototype.doCollapse = function() {
|
|
|
222 |
if (webFXTreeHandler.behavior == 'classic') { document.getElementById(this.id + '-icon').src = this.icon; }
|
|
|
223 |
if (this.childNodes.length) { document.getElementById(this.id + '-cont').style.display = 'none'; }
|
|
|
224 |
this.open = false;
|
|
|
225 |
webFXTreeHandler.cookies.setCookie(this.id.substr(18,this.id.length - 18), '0');
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
WebFXTreeAbstractNode.prototype.expandAll = function() {
|
|
|
229 |
this.expandChildren();
|
|
|
230 |
if ((this.folder) && (!this.open)) { this.expand(); }
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
WebFXTreeAbstractNode.prototype.expandChildren = function() {
|
|
|
234 |
for (var i = 0; i < this.childNodes.length; i++) {
|
|
|
235 |
this.childNodes[i].expandAll();
|
|
|
236 |
} }
|
|
|
237 |
|
|
|
238 |
WebFXTreeAbstractNode.prototype.collapseAll = function() {
|
|
|
239 |
this.collapseChildren();
|
|
|
240 |
if ((this.folder) && (this.open)) { this.collapse(true); }
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
WebFXTreeAbstractNode.prototype.collapseChildren = function() {
|
|
|
244 |
for (var i = 0; i < this.childNodes.length; i++) {
|
|
|
245 |
this.childNodes[i].collapseAll();
|
|
|
246 |
} }
|
|
|
247 |
|
|
|
248 |
WebFXTreeAbstractNode.prototype.indent = function(lvl, del, last, level, nodesLeft) {
|
|
|
249 |
/*
|
|
|
250 |
* Since we only want to modify items one level below ourself,
|
|
|
251 |
* and since the rightmost indentation position is occupied by
|
|
|
252 |
* the plus icon we set this to -2
|
|
|
253 |
*/
|
|
|
254 |
if (lvl == null) { lvl = -2; }
|
|
|
255 |
var state = 0;
|
|
|
256 |
for (var i = this.childNodes.length - 1; i >= 0 ; i--) {
|
|
|
257 |
state = this.childNodes[i].indent(lvl + 1, del, last, level);
|
|
|
258 |
if (state) { return; }
|
|
|
259 |
}
|
|
|
260 |
if (del) {
|
|
|
261 |
if ((level >= this._level) && (document.getElementById(this.id + '-plus'))) {
|
|
|
262 |
if (this.folder) {
|
|
|
263 |
document.getElementById(this.id + '-plus').src = (this.open)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.lPlusIcon;
|
|
|
264 |
this.plusIcon = webFXTreeConfig.lPlusIcon;
|
|
|
265 |
this.minusIcon = webFXTreeConfig.lMinusIcon;
|
|
|
266 |
}
|
|
|
267 |
else if (nodesLeft) { document.getElementById(this.id + '-plus').src = webFXTreeConfig.lIcon; }
|
|
|
268 |
return 1;
|
|
|
269 |
} }
|
|
|
270 |
var foo = document.getElementById(this.id + '-indent-' + lvl);
|
|
|
271 |
if (foo) {
|
|
|
272 |
if ((foo._last) || ((del) && (last))) { foo.src = webFXTreeConfig.blankIcon; }
|
|
|
273 |
else { foo.src = webFXTreeConfig.iIcon; }
|
|
|
274 |
}
|
|
|
275 |
return 0;
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
/*
|
|
|
279 |
* WebFXTree class
|
|
|
280 |
*/
|
|
|
281 |
|
|
|
282 |
function WebFXTree(sText, sAction, sBehavior, sIcon, sOpenIcon) {
|
|
|
283 |
this.base = WebFXTreeAbstractNode;
|
|
|
284 |
this.base(sText, sAction);
|
|
|
285 |
this.icon = sIcon || webFXTreeConfig.rootIcon;
|
|
|
286 |
this.openIcon = sOpenIcon || webFXTreeConfig.openRootIcon;
|
|
|
287 |
/* Defaults to open */
|
|
|
288 |
this.open = (webFXTreeHandler.cookies.getCookie(this.id.substr(18,this.id.length - 18)) == '0')?false:true;
|
|
|
289 |
this.folder = true;
|
|
|
290 |
this.rendered = false;
|
|
|
291 |
this.onSelect = null;
|
|
|
292 |
if (!webFXTreeHandler.behavior) { webFXTreeHandler.behavior = sBehavior || webFXTreeConfig.defaultBehavior; }
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
WebFXTree.prototype = new WebFXTreeAbstractNode;
|
|
|
296 |
|
|
|
297 |
WebFXTree.prototype.setBehavior = function (sBehavior) {
|
|
|
298 |
webFXTreeHandler.behavior = sBehavior;
|
|
|
299 |
};
|
|
|
300 |
|
|
|
301 |
WebFXTree.prototype.getBehavior = function (sBehavior) {
|
|
|
302 |
return webFXTreeHandler.behavior;
|
|
|
303 |
};
|
|
|
304 |
|
|
|
305 |
WebFXTree.prototype.getSelected = function() {
|
|
|
306 |
if (webFXTreeHandler.selected) { return webFXTreeHandler.selected; }
|
|
|
307 |
else { return null; }
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
WebFXTree.prototype.remove = function() { }
|
|
|
311 |
|
|
|
312 |
WebFXTree.prototype.expand = function() {
|
|
|
313 |
this.doExpand();
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
WebFXTree.prototype.collapse = function(b) {
|
|
|
317 |
if (!b) { this.focus(); }
|
|
|
318 |
this.doCollapse();
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
WebFXTree.prototype.getFirst = function() {
|
|
|
322 |
return null;
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
WebFXTree.prototype.getLast = function() {
|
|
|
326 |
return null;
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
WebFXTree.prototype.getNextSibling = function() {
|
|
|
330 |
return null;
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
WebFXTree.prototype.getPreviousSibling = function() {
|
|
|
334 |
return null;
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
WebFXTree.prototype.keydown = function(key) {
|
|
|
338 |
if (key == 39) {
|
|
|
339 |
if (!this.open) { this.expand(); }
|
|
|
340 |
else if (this.childNodes.length) { this.childNodes[0].select(); }
|
|
|
341 |
return false;
|
|
|
342 |
}
|
|
|
343 |
if (key == 37) { this.collapse(); return false; }
|
|
|
344 |
if ((key == 40) && (this.open) && (this.childNodes.length)) { this.childNodes[0].select(); return false; }
|
|
|
345 |
return true;
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
WebFXTree.prototype.toString = function() {
|
|
|
349 |
var str = "<div id=\"" + this.id + "\" ondblclick=\"webFXTreeHandler.toggle(this);\" class=\"webfx-tree-item\" onkeydown=\"return webFXTreeHandler.keydown(this, event)\">";
|
|
|
350 |
str += "<img id=\"" + this.id + "-icon\" class=\"webfx-tree-icon\" src=\"" + ((webFXTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "\" onclick=\"webFXTreeHandler.select(this);\"><a href=\"" + this.action + "\" id=\"" + this.id + "-anchor\" onfocus=\"webFXTreeHandler.focus(this);\" onblur=\"webFXTreeHandler.blur(this);\">" + this.text + "</a></div>";
|
|
|
351 |
str += "<div id=\"" + this.id + "-cont\" class=\"webfx-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">";
|
|
|
352 |
for (var i = 0; i < this.childNodes.length; i++) {
|
|
|
353 |
str += this.childNodes[i].toString(i, this.childNodes.length);
|
|
|
354 |
}
|
|
|
355 |
str += "</div>";
|
|
|
356 |
this.rendered = true;
|
|
|
357 |
return str;
|
|
|
358 |
};
|
|
|
359 |
|
|
|
360 |
/*
|
|
|
361 |
* WebFXTreeItem class
|
|
|
362 |
*/
|
|
|
363 |
|
|
|
364 |
function WebFXTreeItem(sText, sAction, eParent, sIcon, sOpenIcon) {
|
|
|
365 |
this.base = WebFXTreeAbstractNode;
|
|
|
366 |
this.base(sText, sAction);
|
|
|
367 |
/* Defaults to close */
|
|
|
368 |
this.open = (webFXTreeHandler.cookies.getCookie(this.id.substr(18,this.id.length - 18)) == '1')?true:false;
|
|
|
369 |
if (sIcon) { this.icon = sIcon; }
|
|
|
370 |
if (sOpenIcon) { this.openIcon = sOpenIcon; }
|
|
|
371 |
if (eParent) { eParent.add(this); }
|
|
|
372 |
}
|
|
|
373 |
|
|
|
374 |
WebFXTreeItem.prototype = new WebFXTreeAbstractNode;
|
|
|
375 |
|
|
|
376 |
WebFXTreeItem.prototype.remove = function() {
|
|
|
377 |
var iconSrc = document.getElementById(this.id + '-plus').src;
|
|
|
378 |
var parentNode = this.parentNode;
|
|
|
379 |
var prevSibling = this.getPreviousSibling(true);
|
|
|
380 |
var nextSibling = this.getNextSibling(true);
|
|
|
381 |
var folder = this.parentNode.folder;
|
|
|
382 |
var last = ((nextSibling) && (nextSibling.parentNode) && (nextSibling.parentNode.id == parentNode.id))?false:true;
|
|
|
383 |
this.getPreviousSibling().focus();
|
|
|
384 |
this._remove();
|
|
|
385 |
if (parentNode.childNodes.length == 0) {
|
|
|
386 |
document.getElementById(parentNode.id + '-cont').style.display = 'none';
|
|
|
387 |
parentNode.doCollapse();
|
|
|
388 |
parentNode.folder = false;
|
|
|
389 |
parentNode.open = false;
|
|
|
390 |
}
|
|
|
391 |
if (!nextSibling || last) { parentNode.indent(null, true, last, this._level, parentNode.childNodes.length); }
|
|
|
392 |
if ((prevSibling == parentNode) && !(parentNode.childNodes.length)) {
|
|
|
393 |
prevSibling.folder = false;
|
|
|
394 |
prevSibling.open = false;
|
|
|
395 |
iconSrc = document.getElementById(prevSibling.id + '-plus').src;
|
|
|
396 |
iconSrc = iconSrc.replace('minus', '').replace('plus', '');
|
|
|
397 |
document.getElementById(prevSibling.id + '-plus').src = iconSrc;
|
|
|
398 |
document.getElementById(prevSibling.id + '-icon').src = webFXTreeConfig.fileIcon;
|
|
|
399 |
}
|
|
|
400 |
if (document.getElementById(prevSibling.id + '-plus')) {
|
|
|
401 |
if (parentNode == prevSibling.parentNode) {
|
|
|
402 |
iconSrc = iconSrc.replace('minus', '').replace('plus', '');
|
|
|
403 |
document.getElementById(prevSibling.id + '-plus').src = iconSrc;
|
|
|
404 |
} } }
|
|
|
405 |
|
|
|
406 |
WebFXTreeItem.prototype._remove = function() {
|
|
|
407 |
for (var i = this.childNodes.length - 1; i >= 0; i--) {
|
|
|
408 |
this.childNodes[i]._remove();
|
|
|
409 |
}
|
|
|
410 |
for (var i = 0; i < this.parentNode.childNodes.length; i++) {
|
|
|
411 |
if (this == this.parentNode.childNodes[i]) {
|
|
|
412 |
for (var j = i; j < this.parentNode.childNodes.length; j++) {
|
|
|
413 |
this.parentNode.childNodes[j] = this.parentNode.childNodes[j+1];
|
|
|
414 |
}
|
|
|
415 |
this.parentNode.childNodes.length -= 1;
|
|
|
416 |
if (i + 1 == this.parentNode.childNodes.length) { this.parentNode._last = true; }
|
|
|
417 |
break;
|
|
|
418 |
} }
|
|
|
419 |
webFXTreeHandler.all[this.id] = null;
|
|
|
420 |
var tmp = document.getElementById(this.id);
|
|
|
421 |
if (tmp) { tmp.parentNode.removeChild(tmp); }
|
|
|
422 |
tmp = document.getElementById(this.id + '-cont');
|
|
|
423 |
if (tmp) { tmp.parentNode.removeChild(tmp); }
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
WebFXTreeItem.prototype.expand = function() {
|
|
|
427 |
this.doExpand();
|
|
|
428 |
document.getElementById(this.id + '-plus').src = this.minusIcon;
|
|
|
429 |
}
|
|
|
430 |
|
|
|
431 |
WebFXTreeItem.prototype.collapse = function(b) {
|
|
|
432 |
if (!b) { this.focus(); }
|
|
|
433 |
this.doCollapse();
|
|
|
434 |
document.getElementById(this.id + '-plus').src = this.plusIcon;
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
WebFXTreeItem.prototype.getFirst = function() {
|
|
|
438 |
return this.childNodes[0];
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
WebFXTreeItem.prototype.getLast = function() {
|
|
|
442 |
if (this.childNodes[this.childNodes.length - 1].open) { return this.childNodes[this.childNodes.length - 1].getLast(); }
|
|
|
443 |
else { return this.childNodes[this.childNodes.length - 1]; }
|
|
|
444 |
}
|
|
|
445 |
|
|
|
446 |
WebFXTreeItem.prototype.getNextSibling = function() {
|
|
|
447 |
for (var i = 0; i < this.parentNode.childNodes.length; i++) {
|
|
|
448 |
if (this == this.parentNode.childNodes[i]) { break; }
|
|
|
449 |
}
|
|
|
450 |
if (++i == this.parentNode.childNodes.length) { return this.parentNode.getNextSibling(); }
|
|
|
451 |
else { return this.parentNode.childNodes[i]; }
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
WebFXTreeItem.prototype.getPreviousSibling = function(b) {
|
|
|
455 |
for (var i = 0; i < this.parentNode.childNodes.length; i++) {
|
|
|
456 |
if (this == this.parentNode.childNodes[i]) { break; }
|
|
|
457 |
}
|
|
|
458 |
if (i == 0) { return this.parentNode; }
|
|
|
459 |
else {
|
|
|
460 |
if ((this.parentNode.childNodes[--i].open) || (b && this.parentNode.childNodes[i].folder)) { return this.parentNode.childNodes[i].getLast(); }
|
|
|
461 |
else { return this.parentNode.childNodes[i]; }
|
|
|
462 |
} }
|
|
|
463 |
|
|
|
464 |
WebFXTreeItem.prototype.keydown = function(key) {
|
|
|
465 |
if ((key == 39) && (this.folder)) {
|
|
|
466 |
if (!this.open) { this.expand(); }
|
|
|
467 |
else { this.getFirst().select(); }
|
|
|
468 |
return false;
|
|
|
469 |
}
|
|
|
470 |
else if (key == 37) {
|
|
|
471 |
if (this.open) { this.collapse(); }
|
|
|
472 |
else { this.parentNode.select(); }
|
|
|
473 |
return false;
|
|
|
474 |
}
|
|
|
475 |
else if (key == 40) {
|
|
|
476 |
if (this.open) { this.getFirst().select(); }
|
|
|
477 |
else {
|
|
|
478 |
var sib = this.getNextSibling();
|
|
|
479 |
if (sib) { sib.select(); }
|
|
|
480 |
}
|
|
|
481 |
return false;
|
|
|
482 |
}
|
|
|
483 |
else if (key == 38) { this.getPreviousSibling().select(); return false; }
|
|
|
484 |
return true;
|
|
|
485 |
}
|
|
|
486 |
|
|
|
487 |
WebFXTreeItem.prototype.toString = function (nItem, nItemCount) {
|
|
|
488 |
var foo = this.parentNode;
|
|
|
489 |
var indent = '';
|
|
|
490 |
if (nItem + 1 == nItemCount) { this.parentNode._last = true; }
|
|
|
491 |
var i = 0;
|
|
|
492 |
while (foo.parentNode) {
|
|
|
493 |
foo = foo.parentNode;
|
|
|
494 |
indent = "<img id=\"" + this.id + "-indent-" + i + "\" src=\"" + ((foo._last)?webFXTreeConfig.blankIcon:webFXTreeConfig.iIcon) + "\">" + indent;
|
|
|
495 |
i++;
|
|
|
496 |
}
|
|
|
497 |
this._level = i;
|
|
|
498 |
if (this.childNodes.length) { this.folder = 1; }
|
|
|
499 |
else { this.open = false; }
|
|
|
500 |
if ((this.folder) || (webFXTreeHandler.behavior != 'classic')) {
|
|
|
501 |
if (!this.icon) { this.icon = webFXTreeConfig.folderIcon; }
|
|
|
502 |
if (!this.openIcon) { this.openIcon = webFXTreeConfig.openFolderIcon; }
|
|
|
503 |
}
|
|
|
504 |
else if (!this.icon) { this.icon = webFXTreeConfig.fileIcon; }
|
|
|
505 |
var label = this.text.replace(/</g, '<').replace(/>/g, '>');
|
|
|
506 |
var str = "<div id=\"" + this.id + "\" ondblclick=\"webFXTreeHandler.toggle(this);\" class=\"webfx-tree-item\" onkeydown=\"return webFXTreeHandler.keydown(this, event)\">";
|
|
|
507 |
str += indent;
|
|
|
508 |
str += "<img id=\"" + this.id + "-plus\" src=\"" + ((this.folder)?((this.open)?((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon):((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon)):((this.parentNode._last)?webFXTreeConfig.lIcon:webFXTreeConfig.tIcon)) + "\" onclick=\"webFXTreeHandler.toggle(this);\">"
|
|
|
509 |
str += "<img id=\"" + this.id + "-icon\" class=\"webfx-tree-icon\" src=\"" + ((webFXTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "\" onclick=\"webFXTreeHandler.select(this);\"><a href=\"" + this.action + "\" id=\"" + this.id + "-anchor\" onfocus=\"webFXTreeHandler.focus(this);\" onblur=\"webFXTreeHandler.blur(this);\">" + label + "</a></div>";
|
|
|
510 |
str += "<div id=\"" + this.id + "-cont\" class=\"webfx-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">";
|
|
|
511 |
for (var i = 0; i < this.childNodes.length; i++) {
|
|
|
512 |
str += this.childNodes[i].toString(i,this.childNodes.length);
|
|
|
513 |
}
|
|
|
514 |
str += "</div>";
|
|
|
515 |
this.plusIcon = ((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon);
|
|
|
516 |
this.minusIcon = ((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon);
|
|
|
517 |
return str;
|
|
|
518 |
}
|