xtree.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. /*----------------------------------------------------------------------------\
  2. | Cross Browser Tree Widget 1.16 |
  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. | Dependencies: xtree.css (To set up the CSS of the tree classes) |
  41. |-----------------------------------------------------------------------------|
  42. | 2001-01-10 | Original Version Posted. |
  43. | 2001-03-18 | Added getSelected and get/setBehavior that can make it behave |
  44. | | more like windows explorer, check usage for more information. |
  45. | 2001-09-23 | Version 1.1 - New features included keyboard navigation (ie) |
  46. | | and the ability to add and remove nodes dynamically and some |
  47. | | other small tweaks and fixes. |
  48. | 2002-01-27 | Version 1.11 - Bug fixes and improved mozilla support. |
  49. | 2002-06-11 | Version 1.12 - Fixed a bug that prevented the indentation line |
  50. | | from updating correctly under some circumstances. This bug |
  51. | | happened when removing the last item in a subtree and items in |
  52. | | siblings to the remove subtree where not correctly updated. |
  53. | 2002-06-13 | Fixed a few minor bugs cased by the 1.12 bug-fix. |
  54. | 2002-08-20 | Added usePersistence flag to allow disable of cookies. |
  55. | 2002-10-23 | (1.14) Fixed a plus icon issue |
  56. | 2002-10-29 | (1.15) Last changes broke more than they fixed. This version |
  57. | | is based on 1.13 and fixes the bugs 1.14 fixed withou breaking |
  58. | | lots of other things. |
  59. | 2003-02-15 | The selected node can now be made visible even when the tree |
  60. | | control loses focus. It uses a new class declaration in the |
  61. | | css file '.webfx-tree-item a.selected-inactive', by default it |
  62. | | puts a light-gray rectangle around the selected node. |
  63. |-----------------------------------------------------------------------------|
  64. | Created 2000-12-11 | All changes are in the log above. | Updated 2003-02-15 |
  65. \----------------------------------------------------------------------------*/
  66. var webFXTreeConfig = {
  67. rootIcon : '/GDZJ/images/system/xtree_folder_close.gif',
  68. openRootIcon : '/GDZJ/images/system/xtree_folder_open.gif',
  69. folderIcon : '/GDZJ/images/system/xtree_folder_close.gif',
  70. openFolderIcon : '/GDZJ/images/system/xtree_folder_open.gif',
  71. fileIcon : '/GDZJ/images/system/Leaf.gif',
  72. iIcon : '/GDZJ/images/system/I.png',
  73. lIcon : '/GDZJ/images/system/L.png',
  74. lMinusIcon : '/GDZJ/images/system/Lminus.png',
  75. lPlusIcon : '/GDZJ/images/system/Lplus.png',
  76. tIcon : '/GDZJ/images/system/T.png',
  77. tMinusIcon : '/GDZJ/images/system/Tminus.png',
  78. tPlusIcon : '/GDZJ/images/system/Tplus.png',
  79. blankIcon : '/GDZJ/images/system/xtree_blank.gif',
  80. defaultText : 'Tree Item',
  81. defaultAction : 'javascript:void(0);',
  82. defaultBehavior : 'classic',
  83. usePersistence : true
  84. };
  85. var webFXTreeHandler = {
  86. idCounter : 0,
  87. idPrefix : "webfx-tree-object-",
  88. all : {},
  89. behavior : null,
  90. selected : null,
  91. onSelect : null, /* should be part of tree, not handler */
  92. getId : function() {
  93. return this.idPrefix + this.idCounter++;
  94. },
  95. toggle : function(oItem) {
  96. this.all[oItem.id.replace('-plus', '')].toggle();
  97. },
  98. select : function(oItem) {
  99. this.all[oItem.id.replace('-icon', '')].select();
  100. },
  101. focus : function(oItem) {
  102. this.all[oItem.id.replace('-anchor', '')].focus();
  103. },
  104. blur : function(oItem) {
  105. this.all[oItem.id.replace('-anchor', '')].blur();
  106. },
  107. keydown : function(oItem, e) {
  108. return this.all[oItem.id].keydown(e.keyCode);
  109. },
  110. cookies : new WebFXCookie(),
  111. insertHTMLBeforeEnd : function(oElement, sHTML) {
  112. if (oElement.insertAdjacentHTML != null) {
  113. oElement.insertAdjacentHTML("BeforeEnd", sHTML)
  114. return;
  115. }
  116. var df; // DocumentFragment
  117. var r = oElement.ownerDocument.createRange();
  118. r.selectNodeContents(oElement);
  119. r.collapse(false);
  120. df = r.createContextualFragment(sHTML);
  121. oElement.appendChild(df);
  122. }
  123. };
  124. /*
  125. * WebFXCookie class
  126. */
  127. function WebFXCookie() {
  128. if (document.cookie.length) {
  129. this.cookies = ' ' + document.cookie;
  130. }
  131. }
  132. WebFXCookie.prototype.setCookie = function(key, value) {
  133. document.cookie = key + "=" + escape(value);
  134. }
  135. WebFXCookie.prototype.getCookie = function(key) {
  136. if (this.cookies) {
  137. var start = this.cookies.indexOf(' ' + key + '=');
  138. if (start == -1) {
  139. return null;
  140. }
  141. var end = this.cookies.indexOf(";", start);
  142. if (end == -1) {
  143. end = this.cookies.length;
  144. }
  145. end -= start;
  146. var cookie = this.cookies.substr(start, end);
  147. return unescape(cookie.substr(cookie.indexOf('=') + 1, cookie.length
  148. - cookie.indexOf('=') + 1));
  149. } else {
  150. return null;
  151. }
  152. }
  153. /*
  154. * WebFXTreeAbstractNode class
  155. */
  156. function WebFXTreeAbstractNode(sText, sAction) {
  157. this.childNodes = [];
  158. this.id = webFXTreeHandler.getId();
  159. this.text = sText || webFXTreeConfig.defaultText;
  160. this.action = sAction || webFXTreeConfig.defaultAction;
  161. this._last = false;
  162. webFXTreeHandler.all[this.id] = this;
  163. }
  164. /*
  165. * To speed thing up if you're adding multiple nodes at once (after load) use
  166. * the bNoIdent parameter to prevent automatic re-indentation and call the
  167. * obj.ident() method manually once all nodes has been added.
  168. */
  169. WebFXTreeAbstractNode.prototype.add = function(node, bNoIdent) {
  170. node.parentNode = this;
  171. this.childNodes[this.childNodes.length] = node;
  172. var root = this;
  173. if (this.childNodes.length >= 2) {
  174. this.childNodes[this.childNodes.length - 2]._last = false;
  175. }
  176. while (root.parentNode) {
  177. root = root.parentNode;
  178. }
  179. if (root.rendered) {
  180. if (this.childNodes.length >= 2) {
  181. document
  182. .getElementById(this.childNodes[this.childNodes.length - 2].id
  183. + '-plus').src = ((this.childNodes[this.childNodes.length
  184. - 2].folder)
  185. ? ((this.childNodes[this.childNodes.length - 2].open)
  186. ? webFXTreeConfig.tMinusIcon
  187. : webFXTreeConfig.tPlusIcon)
  188. : webFXTreeConfig.tIcon);
  189. this.childNodes[this.childNodes.length - 2].plusIcon = webFXTreeConfig.tPlusIcon;
  190. this.childNodes[this.childNodes.length - 2].minusIcon = webFXTreeConfig.tMinusIcon;
  191. this.childNodes[this.childNodes.length - 2]._last = false;
  192. }
  193. this._last = true;
  194. var foo = this;
  195. while (foo.parentNode) {
  196. for (var i = 0; i < foo.parentNode.childNodes.length; i++) {
  197. if (foo.id == foo.parentNode.childNodes[i].id) {
  198. break;
  199. }
  200. }
  201. if (i == foo.parentNode.childNodes.length - 1) {
  202. foo.parentNode._last = true;
  203. } else {
  204. foo.parentNode._last = false;
  205. }
  206. foo = foo.parentNode;
  207. }
  208. webFXTreeHandler.insertHTMLBeforeEnd(document.getElementById(this.id
  209. + '-cont'), node.toString());
  210. if ((!this.folder) && (!this.openIcon)) {
  211. this.icon = webFXTreeConfig.folderIcon;
  212. this.openIcon = webFXTreeConfig.openFolderIcon;
  213. }
  214. if (!this.folder) {
  215. this.folder = true;
  216. this.collapse(true);
  217. }
  218. if (!bNoIdent) {
  219. this.indent();
  220. }
  221. }
  222. return node;
  223. }
  224. WebFXTreeAbstractNode.prototype.toggle = function() {
  225. if (this.folder) {
  226. if (this.open) {
  227. this.collapse();
  228. } else {
  229. this.expand();
  230. }
  231. }
  232. }
  233. WebFXTreeAbstractNode.prototype.select = function() {
  234. document.getElementById(this.id + '-anchor').focus();
  235. }
  236. WebFXTreeAbstractNode.prototype.deSelect = function() {
  237. document.getElementById(this.id + '-anchor').className = '';
  238. webFXTreeHandler.selected = null;
  239. }
  240. WebFXTreeAbstractNode.prototype.focus = function() {
  241. if ((webFXTreeHandler.selected) && (webFXTreeHandler.selected != this)) {
  242. webFXTreeHandler.selected.deSelect();
  243. }
  244. webFXTreeHandler.selected = this;
  245. if ((this.openIcon) && (webFXTreeHandler.behavior != 'classic')) {
  246. document.getElementById(this.id + '-icon').src = this.openIcon;
  247. }
  248. document.getElementById(this.id + '-anchor').className = 'selected';
  249. document.getElementById(this.id + '-anchor').focus();
  250. if (webFXTreeHandler.onSelect) {
  251. webFXTreeHandler.onSelect(this);
  252. }
  253. }
  254. WebFXTreeAbstractNode.prototype.blur = function() {
  255. if ((this.openIcon) && (webFXTreeHandler.behavior != 'classic')) {
  256. document.getElementById(this.id + '-icon').src = this.icon;
  257. }
  258. document.getElementById(this.id + '-anchor').className = 'selected-inactive';
  259. }
  260. WebFXTreeAbstractNode.prototype.doExpand = function() {
  261. if (webFXTreeHandler.behavior == 'classic') {
  262. document.getElementById(this.id + '-icon').src = this.openIcon;
  263. if (document.getElementById(this.id + '-Folder').className == "l1folderclose") {
  264. document.getElementById(this.id + '-anchor').className = "l1folderopen";
  265. document.getElementById(this.id + '-Folder').className = "l1folderopen";
  266. document.getElementById(this.id + '-Folder-top').className = "l1folderopen";
  267. }
  268. }
  269. if (this.childNodes.length) {
  270. document.getElementById(this.id + '-cont').style.display = 'block';
  271. }
  272. this.open = true;
  273. if (webFXTreeConfig.usePersistence) {
  274. webFXTreeHandler.cookies.setCookie(this.id.substr(18, this.id.length
  275. - 18), '1');
  276. }
  277. }
  278. WebFXTreeAbstractNode.prototype.doCollapse = function() {
  279. if (webFXTreeHandler.behavior == 'classic') {
  280. document.getElementById(this.id + '-icon').src = this.icon;
  281. if (document.getElementById(this.id + '-Folder').className == "l1folderopen") {
  282. document.getElementById(this.id + '-anchor').className = "l1folderclose";
  283. document.getElementById(this.id + '-Folder').className = "l1folderclose";
  284. document.getElementById(this.id + '-Folder-top').className = "l1folderclose";
  285. }
  286. }
  287. if (this.childNodes.length) {
  288. document.getElementById(this.id + '-cont').style.display = 'none';
  289. }
  290. this.open = false;
  291. if (webFXTreeConfig.usePersistence) {
  292. webFXTreeHandler.cookies.setCookie(this.id.substr(18, this.id.length
  293. - 18), '0');
  294. }
  295. }
  296. WebFXTreeAbstractNode.prototype.expandAll = function() {
  297. this.expandChildren();
  298. if ((this.folder) && (!this.open)) {
  299. this.expand();
  300. }
  301. }
  302. WebFXTreeAbstractNode.prototype.expandChildren = function() {
  303. for (var i = 0; i < this.childNodes.length; i++) {
  304. this.childNodes[i].expandAll();
  305. }
  306. }
  307. WebFXTreeAbstractNode.prototype.collapseAll = function() {
  308. this.collapseChildren();
  309. if ((this.folder) && (this.open)) {
  310. this.collapse(true);
  311. }
  312. }
  313. WebFXTreeAbstractNode.prototype.collapseChildren = function() {
  314. for (var i = 0; i < this.childNodes.length; i++) {
  315. this.childNodes[i].collapseAll();
  316. }
  317. }
  318. WebFXTreeAbstractNode.prototype.indent = function(lvl, del, last, level,
  319. nodesLeft) {
  320. /*
  321. * Since we only want to modify items one level below ourself, and since the
  322. * rightmost indentation position is occupied by the plus icon we set this
  323. * to -2
  324. */
  325. if (lvl == null) {
  326. lvl = -2;
  327. }
  328. var state = 0;
  329. for (var i = this.childNodes.length - 1; i >= 0; i--) {
  330. state = this.childNodes[i].indent(lvl + 1, del, last, level);
  331. if (state) {
  332. return;
  333. }
  334. }
  335. if (del) {
  336. if ((level >= this._level)
  337. && (document.getElementById(this.id + '-plus'))) {
  338. if (this.folder) {
  339. document.getElementById(this.id + '-plus').src = (this.open)
  340. ? webFXTreeConfig.lMinusIcon
  341. : webFXTreeConfig.lPlusIcon;
  342. this.plusIcon = webFXTreeConfig.lPlusIcon;
  343. this.minusIcon = webFXTreeConfig.lMinusIcon;
  344. } else if (nodesLeft) {
  345. document.getElementById(this.id + '-plus').src = webFXTreeConfig.lIcon;
  346. }
  347. return 1;
  348. }
  349. }
  350. var foo = document.getElementById(this.id + '-indent-' + lvl);
  351. if (foo) {
  352. if ((foo._last) || ((del) && (last))) {
  353. foo.src = webFXTreeConfig.blankIcon;
  354. } else {
  355. foo.src = webFXTreeConfig.iIcon;
  356. }
  357. }
  358. return 0;
  359. }
  360. /*
  361. * WebFXTree class
  362. */
  363. function WebFXTree(sText, sAction, sBehavior, sIcon, sOpenIcon) {
  364. this.base = WebFXTreeAbstractNode;
  365. this.base(sText, sAction);
  366. this.icon = sIcon || webFXTreeConfig.rootIcon;
  367. this.openIcon = sOpenIcon || webFXTreeConfig.openRootIcon;
  368. /* Defaults to open */
  369. if (webFXTreeConfig.usePersistence) {
  370. this.open = (webFXTreeHandler.cookies.getCookie(this.id.substr(18,
  371. this.id.length - 18)) == '0') ? false : true;
  372. } else {
  373. this.open = true;
  374. }
  375. this.folder = true;
  376. this.rendered = false;
  377. this.onSelect = null;
  378. if (!webFXTreeHandler.behavior) {
  379. webFXTreeHandler.behavior = sBehavior
  380. || webFXTreeConfig.defaultBehavior;
  381. }
  382. }
  383. WebFXTree.prototype = new WebFXTreeAbstractNode;
  384. WebFXTree.prototype.setBehavior = function(sBehavior) {
  385. webFXTreeHandler.behavior = sBehavior;
  386. };
  387. WebFXTree.prototype.getBehavior = function(sBehavior) {
  388. return webFXTreeHandler.behavior;
  389. };
  390. WebFXTree.prototype.getSelected = function() {
  391. if (webFXTreeHandler.selected) {
  392. return webFXTreeHandler.selected;
  393. } else {
  394. return null;
  395. }
  396. }
  397. WebFXTree.prototype.remove = function() {
  398. }
  399. WebFXTree.prototype.expand = function() {
  400. this.doExpand();
  401. }
  402. WebFXTree.prototype.collapse = function(b) {
  403. if (!b) {
  404. this.focus();
  405. }
  406. this.doCollapse();
  407. }
  408. WebFXTree.prototype.getFirst = function() {
  409. return null;
  410. }
  411. WebFXTree.prototype.getLast = function() {
  412. return null;
  413. }
  414. WebFXTree.prototype.getNextSibling = function() {
  415. return null;
  416. }
  417. WebFXTree.prototype.getPreviousSibling = function() {
  418. return null;
  419. }
  420. WebFXTree.prototype.keydown = function(key) {
  421. if (key == 39) {
  422. if (!this.open) {
  423. this.expand();
  424. } else if (this.childNodes.length) {
  425. this.childNodes[0].select();
  426. }
  427. return false;
  428. }
  429. if (key == 37) {
  430. this.collapse();
  431. return false;
  432. }
  433. if ((key == 40) && (this.open) && (this.childNodes.length)) {
  434. this.childNodes[0].select();
  435. return false;
  436. }
  437. return true;
  438. }
  439. WebFXTree.prototype.toString = function() {
  440. var str = "";
  441. for (var i = 0; i < this.childNodes.length; i++) {
  442. str += this.childNodes[i].toString(i, this.childNodes.length);
  443. }
  444. this.rendered = true;
  445. str += "<table width=\"100%\" height=\"1\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
  446. str += "<tr>";
  447. str += "<td height=\"1\" class=\"line\"></td>";
  448. str += "</tr>";
  449. str += "</table>";
  450. return str;
  451. };
  452. /*
  453. * WebFXTreeItem class
  454. */
  455. function WebFXTreeItem(sText, sAction, isOpen, eParent, sIcon, sOpenIcon) {
  456. this.base = WebFXTreeAbstractNode;
  457. this.base(sText, sAction);
  458. /* Defaults to close */
  459. if (webFXTreeConfig.usePersistence) {
  460. this.open = (webFXTreeHandler.cookies.getCookie(this.id.substr(18,
  461. this.id.length - 18)) == '1') ? true : false;
  462. } else {
  463. this.open = false;
  464. }
  465. this.open = isOpen;
  466. if (sIcon) {
  467. this.icon = sIcon;
  468. }
  469. if (sOpenIcon) {
  470. this.openIcon = sOpenIcon;
  471. }
  472. if (eParent) {
  473. eParent.add(this);
  474. }
  475. }
  476. WebFXTreeItem.prototype = new WebFXTreeAbstractNode;
  477. WebFXTreeItem.prototype.remove = function() {
  478. var iconSrc = document.getElementById(this.id + '-plus').src;
  479. var parentNode = this.parentNode;
  480. var prevSibling = this.getPreviousSibling(true);
  481. var nextSibling = this.getNextSibling(true);
  482. var folder = this.parentNode.folder;
  483. var last = ((nextSibling) && (nextSibling.parentNode) && (nextSibling.parentNode.id == parentNode.id))
  484. ? false
  485. : true;
  486. this.getPreviousSibling().focus();
  487. this._remove();
  488. if (parentNode.childNodes.length == 0) {
  489. document.getElementById(parentNode.id + '-cont').style.display = 'none';
  490. parentNode.doCollapse();
  491. parentNode.folder = false;
  492. parentNode.open = false;
  493. }
  494. if (!nextSibling || last) {
  495. parentNode.indent(null, true, last, this._level,
  496. parentNode.childNodes.length);
  497. }
  498. if ((prevSibling == parentNode) && !(parentNode.childNodes.length)) {
  499. prevSibling.folder = false;
  500. prevSibling.open = false;
  501. iconSrc = document.getElementById(prevSibling.id + '-plus').src;
  502. iconSrc = iconSrc.replace('minus', '').replace('plus', '');
  503. document.getElementById(prevSibling.id + '-plus').src = iconSrc;
  504. document.getElementById(prevSibling.id + '-icon').src = webFXTreeConfig.fileIcon;
  505. }
  506. if (document.getElementById(prevSibling.id + '-plus')) {
  507. if (parentNode == prevSibling.parentNode) {
  508. iconSrc = iconSrc.replace('minus', '').replace('plus', '');
  509. document.getElementById(prevSibling.id + '-plus').src = iconSrc;
  510. }
  511. }
  512. }
  513. WebFXTreeItem.prototype._remove = function() {
  514. for (var i = this.childNodes.length - 1; i >= 0; i--) {
  515. this.childNodes[i]._remove();
  516. }
  517. for (var i = 0; i < this.parentNode.childNodes.length; i++) {
  518. if (this == this.parentNode.childNodes[i]) {
  519. for (var j = i; j < this.parentNode.childNodes.length; j++) {
  520. this.parentNode.childNodes[j] = this.parentNode.childNodes[j
  521. + 1];
  522. }
  523. this.parentNode.childNodes.length -= 1;
  524. if (i + 1 == this.parentNode.childNodes.length) {
  525. this.parentNode._last = true;
  526. }
  527. break;
  528. }
  529. }
  530. webFXTreeHandler.all[this.id] = null;
  531. var tmp = document.getElementById(this.id);
  532. if (tmp) {
  533. tmp.parentNode.removeChild(tmp);
  534. }
  535. tmp = document.getElementById(this.id + '-cont');
  536. if (tmp) {
  537. tmp.parentNode.removeChild(tmp);
  538. }
  539. }
  540. WebFXTreeItem.prototype.expand = function() {
  541. this.doExpand();
  542. // document.getElementById(this.id + '-plus').src = this.minusIcon;
  543. }
  544. WebFXTreeItem.prototype.collapse = function(b) {
  545. if (!b) {
  546. this.focus();
  547. }
  548. this.doCollapse();
  549. // document.getElementById(this.id + '-plus').src = this.plusIcon;
  550. }
  551. WebFXTreeItem.prototype.getFirst = function() {
  552. return this.childNodes[0];
  553. }
  554. WebFXTreeItem.prototype.getLast = function() {
  555. if (this.childNodes[this.childNodes.length - 1].open) {
  556. return this.childNodes[this.childNodes.length - 1].getLast();
  557. } else {
  558. return this.childNodes[this.childNodes.length - 1];
  559. }
  560. }
  561. WebFXTreeItem.prototype.getNextSibling = function() {
  562. for (var i = 0; i < this.parentNode.childNodes.length; i++) {
  563. if (this == this.parentNode.childNodes[i]) {
  564. break;
  565. }
  566. }
  567. if (++i == this.parentNode.childNodes.length) {
  568. return this.parentNode.getNextSibling();
  569. } else {
  570. return this.parentNode.childNodes[i];
  571. }
  572. }
  573. WebFXTreeItem.prototype.getPreviousSibling = function(b) {
  574. for (var i = 0; i < this.parentNode.childNodes.length; i++) {
  575. if (this == this.parentNode.childNodes[i]) {
  576. break;
  577. }
  578. }
  579. if (i == 0) {
  580. return this.parentNode;
  581. } else {
  582. if ((this.parentNode.childNodes[--i].open)
  583. || (b && this.parentNode.childNodes[i].folder)) {
  584. return this.parentNode.childNodes[i].getLast();
  585. } else {
  586. return this.parentNode.childNodes[i];
  587. }
  588. }
  589. }
  590. WebFXTreeItem.prototype.keydown = function(key) {
  591. if ((key == 39) && (this.folder)) {
  592. if (!this.open) {
  593. this.expand();
  594. } else {
  595. this.getFirst().select();
  596. }
  597. return false;
  598. } else if (key == 37) {
  599. if (this.open) {
  600. this.collapse();
  601. } else {
  602. this.parentNode.select();
  603. }
  604. return false;
  605. } else if (key == 40) {
  606. if (this.open) {
  607. this.getFirst().select();
  608. } else {
  609. var sib = this.getNextSibling();
  610. if (sib) {
  611. sib.select();
  612. }
  613. }
  614. return false;
  615. } else if (key == 38) {
  616. this.getPreviousSibling().select();
  617. return false;
  618. }
  619. return true;
  620. }
  621. WebFXTreeItem.prototype.toString = function(nItem, nItemCount) {
  622. var foo = this.parentNode;
  623. var indent = '';
  624. if (nItem + 1 == nItemCount) {
  625. this.parentNode._last = true;
  626. }
  627. var i = 0;
  628. if (this.childNodes.length) {
  629. this.folder = 1;
  630. } else {
  631. this.open = false;
  632. }
  633. if ((this.folder) || (webFXTreeHandler.behavior != 'classic')) {
  634. if (!this.icon) {
  635. this.icon = webFXTreeConfig.folderIcon;
  636. }
  637. if (!this.openIcon) {
  638. this.openIcon = webFXTreeConfig.openFolderIcon;
  639. }
  640. } else {
  641. if (!this.icon) {
  642. this.icon = webFXTreeConfig.folderIcon;
  643. }
  644. if (!this.openIcon) {
  645. this.openIcon = webFXTreeConfig.openFolderIcon;
  646. }
  647. }
  648. // var label = this.text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
  649. var label = this.text;
  650. var classFolder = "l1folderclose";
  651. var classItem = "l1item";
  652. var classItema = "l1itema";
  653. if (this.folder == 1 && this.open == true) {
  654. classFolder = "l1folderopen";
  655. }
  656. if (this.parentNode && this.parentNode.parentNode) {
  657. classFolder = "l2folderopen";
  658. }
  659. if (this.parentNode && this.parentNode.parentNode
  660. && this.parentNode.parentNode.parentNode) {
  661. classItem = "l2item";
  662. classItema = "l2itema";
  663. }
  664. var str = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >"
  665. if (this.folder == 1 && !this.parentNode.parentNode) {
  666. str += "<tr>";
  667. str += "<td height=\"1\" class=\"line\"></td>";
  668. str += "</tr>";
  669. }
  670. if (nItem == 0 && this.parentNode.parentNode
  671. && !this.parentNode.parentNode.parentNode) {
  672. str += "<tr>";
  673. str += "<td height=\"1\" class=\"line\"></td>";
  674. str += "</tr>";
  675. }
  676. if (nItem == 0 && this.parentNode && this.parentNode.parentNode
  677. && this.parentNode.parentNode.parentNode) {
  678. str += "<tr>";
  679. str += "<td height=\"1\" class=\"l2line\"></td>";
  680. str += "</tr>";
  681. }
  682. if (this.folder == 1) {
  683. str += "<tr>";
  684. str += "<td id=\"" + this.id + "-Folder-top\" height=\"3\" class=\""
  685. + classFolder + "\"></td>";
  686. str += "</tr>";
  687. } else {
  688. str += "<tr>";
  689. str += "<td height=\"3\" class=\"" + classItem + "\"></td>";
  690. str += "</tr>";
  691. }
  692. var space = "&nbsp;&nbsp;";
  693. if (this.folder == 1) {
  694. str += "<tr id=\""
  695. + this.id
  696. + "\" onclick=\"webFXTreeHandler.toggle(this);\" onkeydown=\"return webFXTreeHandler.keydown(this, event)\">";
  697. str += "<td id=\"" + this.id
  698. + "-Folder\" height=\"18\" nowrap class=\"" + classFolder
  699. + "\">";
  700. if (this.parentNode && this.parentNode.parentNode)
  701. str += space;
  702. if (this.parentNode && this.parentNode.parentNode
  703. && this.parentNode.parentNode.parentNode)
  704. str += space;
  705. str += "<a href=\""
  706. + this.action
  707. + "\" class=\""
  708. + classFolder
  709. + "\" target='mainFrame' id=\""
  710. + this.id
  711. + "-anchor\" onblur=\"webFXTreeHandler.blur(this);\"><img id=\""
  712. + this.id
  713. + "-icon\" src=\""
  714. + ((webFXTreeHandler.behavior == 'classic' && this.open)
  715. ? this.openIcon
  716. : this.icon) + "\" border=\"0\" align=\"absmiddle\">"
  717. + label + "</a></td>";
  718. } else {
  719. str += "<tr id=\""
  720. + this.id
  721. + " onclick=\"webFXTreeHandler.toggle(this);webFXTreeHandler.select(this);\" class=\""
  722. + classItema
  723. + "\" onkeydown=\"return webFXTreeHandler.keydown(this, event)\"\">";
  724. str += "<td height=\"18\" nowrap>";
  725. if (this.parentNode && this.parentNode.parentNode)
  726. str += space;
  727. if (this.parentNode && this.parentNode.parentNode
  728. && this.parentNode.parentNode.parentNode)
  729. str += space;
  730. str += "<img id=\""
  731. + this.id
  732. + "-icon\" src=\""
  733. + webFXTreeConfig.blankIcon
  734. + "\" border=\"0\" align=\"absmiddle\">"
  735. + "<a href=\""
  736. + this.action
  737. + "\" target='mainFrame' id=\""
  738. + this.id
  739. + "-anchor\" onfocus=\"webFXTreeHandler.focus(this);\" onblur=\"webFXTreeHandler.blur(this);\">"
  740. + label + "</a></td>";
  741. }
  742. str += "</tr>";
  743. str += "<tr id=\"" + this.id + "-cont\" style=\"display: "
  744. + ((this.open) ? 'block' : 'none') + ";\">";
  745. str += "<td>";
  746. for (var i = 0; i < this.childNodes.length; i++) {
  747. str += this.childNodes[i].toString(i, this.childNodes.length);
  748. }
  749. str += "</td>";
  750. str += "</tr>";
  751. str += "</table>";
  752. return str;
  753. }