|
1 /* |
|
2 * Enano - an open source wiki-like CMS |
|
3 * Copyright (C) 2006-2007 Dan Fuhry |
|
4 * |
|
5 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
6 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
7 * |
|
8 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
9 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
10 * |
|
11 * Some code found in this script is not licensed under the GNU General Public License; however, it is believed that the license terms shown |
|
12 * below are GPL-compatible. If you believe that this is not the case, please drop a note to support@enano.homelinux.org. |
|
13 */ |
|
14 |
|
15 /* |
|
16 * Title: Tigra Tree |
|
17 * Description: See the demo at url |
|
18 * URL: http://www.softcomplex.com/products/tigra_tree_menu/ |
|
19 * Version: 1.1 |
|
20 * Date: 11-12-2002 (mm-dd-yyyy) |
|
21 * Notes: This script is free. Visit official site for further details. |
|
22 * |
|
23 * There is no license fee or royalty fee to be paid at any time for using the Tigra Tree Menu v1.x |
|
24 * You may include the source code or modified source code within your own projects for either personal |
|
25 * or commercial use but excluding the restrictions outlined below. The following restrictions apply to |
|
26 * all parts of the component, including all source code, samples and documentation. |
|
27 * |
|
28 * - Header block of script file (tree.js) CAN NOT be modified or removed. |
|
29 * - The above items CAN NOT be sold as are, either individually or together. |
|
30 * - The above items CAN NOT be modified and then sold as a library component, either individually or together. |
|
31 */ |
|
32 |
|
33 var ck = readCookie('admin_menu_state'); |
|
34 if(ck) |
|
35 { |
|
36 var ck = parseInt(ck); |
|
37 } |
|
38 else |
|
39 { |
|
40 ck = 0; |
|
41 } |
|
42 ck = ( isNaN(ck) ) ? 0 : ck; |
|
43 |
|
44 function tree (a_items, a_template) { |
|
45 |
|
46 this.a_tpl = a_template; |
|
47 this.a_config = a_items; |
|
48 this.o_root = this; |
|
49 this.a_index = []; |
|
50 this.o_selected = null; |
|
51 this.n_depth = -1; |
|
52 |
|
53 var o_icone = new Image(), |
|
54 o_iconl = new Image(); |
|
55 o_icone.src = a_template['icon_e']; |
|
56 o_iconl.src = a_template['icon_l']; |
|
57 a_template['im_e'] = o_icone; |
|
58 a_template['im_l'] = o_iconl; |
|
59 for (var i = 0; i < 64; i++) |
|
60 if (a_template['icon_' + i]) { |
|
61 var o_icon = new Image(); |
|
62 a_template['im_' + i] = o_icon; |
|
63 o_icon.src = a_template['icon_' + i]; |
|
64 } |
|
65 |
|
66 this.toggle = function (n_id,co) { var o_item = this.a_index[n_id]; o_item.open(o_item.b_opened,co); }; |
|
67 this.open = function (n_id,co) { var o_item = this.a_index[n_id]; o_item.open(false,co); }; |
|
68 this.select = function (n_id) { return this.a_index[n_id].select(); }; |
|
69 this.mout = function (n_id) { this.a_index[n_id].upstatus(true) }; |
|
70 this.mover = function (n_id) { this.a_index[n_id].upstatus() }; |
|
71 |
|
72 this.a_children = []; |
|
73 for (var i = 0; i < a_items.length; i++) |
|
74 { |
|
75 new tree_item(this, i); |
|
76 } |
|
77 |
|
78 this.n_id = trees.length; |
|
79 trees[this.n_id] = this; |
|
80 |
|
81 for (var i = 0; i < this.a_children.length; i++) { |
|
82 document.write(this.a_children[i].init()); |
|
83 this.a_children[i].open(false, true); |
|
84 } |
|
85 } |
|
86 function tree_item (o_parent, n_order) { |
|
87 |
|
88 this.n_depth = o_parent.n_depth + 1; |
|
89 this.a_config = o_parent.a_config[n_order + (this.n_depth ? 2 : 0)]; |
|
90 if (!this.a_config) return; |
|
91 |
|
92 this.o_root = o_parent.o_root; |
|
93 this.o_parent = o_parent; |
|
94 this.n_order = n_order; |
|
95 this.b_opened = !this.n_depth; |
|
96 |
|
97 this.n_id = this.o_root.a_index.length; |
|
98 this.o_root.a_index[this.n_id] = this; |
|
99 o_parent.a_children[n_order] = this; |
|
100 |
|
101 this.a_children = []; |
|
102 for (var i = 0; i < this.a_config.length - 2; i++) |
|
103 { |
|
104 new tree_item(this, i); |
|
105 } |
|
106 |
|
107 this.get_icon = item_get_icon; |
|
108 this.open = item_open; |
|
109 this.select = item_select; |
|
110 this.init = item_init; |
|
111 this.upstatus = item_upstatus; |
|
112 this.is_last = function () { return this.n_order == this.o_parent.a_children.length - 1 }; |
|
113 |
|
114 // CODE MODIFICATION |
|
115 // added: |
|
116 // Do we need to open the branch? |
|
117 n = Math.pow(2, this.n_id); |
|
118 var disp = ( ck & n ) ? true : false; |
|
119 s = ( disp ) ? 'open' : 'closed'; |
|
120 //if(s=='open') alert(this.n_id + ': ' + s); |
|
121 if(disp) setTimeout('trees['+trees.length+'].open('+this.n_id+', true);', 10); |
|
122 // END MODIFICATIONS |
|
123 } |
|
124 |
|
125 function item_open (b_close, nocookie) { |
|
126 //alert('item_open('+this.n_id+');'); |
|
127 var o_idiv = get_element('i_div' + this.o_root.n_id + '_' + this.n_id); |
|
128 if (!o_idiv) return; |
|
129 |
|
130 if (!o_idiv.innerHTML) { |
|
131 var a_children = []; |
|
132 for (var i = 0; i < this.a_children.length; i++) |
|
133 { |
|
134 a_children[i]= this.a_children[i].init(); |
|
135 } |
|
136 o_idiv.innerHTML = a_children.join(''); |
|
137 } |
|
138 o_idiv.style.display = (b_close ? 'none' : 'block'); |
|
139 |
|
140 // CODE MODIFICATION |
|
141 // added: |
|
142 if(!nocookie) |
|
143 { |
|
144 // The idea here is to use a bitwise field. Nice 'n simple, right? Object of the game is to assemble |
|
145 // a binary number that depicts the open/closed state of the entire menu in one cookie. |
|
146 n = Math.pow(2, this.n_id); |
|
147 ck = ( b_close ) ? ck-n : ck+n; |
|
148 //alert('open(): doing the cookie routine for id '+this.n_id+"\nResult for bitwise op: "+ck); |
|
149 createCookie('admin_menu_state', ck, 365); |
|
150 } else { |
|
151 //alert('open(): NOT doing the cookie routine for id '+this.n_id); |
|
152 } |
|
153 // END MODIFICATIONS |
|
154 |
|
155 this.b_opened = !b_close; |
|
156 var o_jicon = document.images['j_img' + this.o_root.n_id + '_' + this.n_id], |
|
157 o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id]; |
|
158 if (o_jicon) o_jicon.src = this.get_icon(true); |
|
159 if (o_iicon) o_iicon.src = this.get_icon(); |
|
160 this.upstatus(); |
|
161 } |
|
162 |
|
163 function item_select (b_deselect) { |
|
164 if (!b_deselect) { |
|
165 var o_olditem = this.o_root.o_selected; |
|
166 this.o_root.o_selected = this; |
|
167 if (o_olditem) o_olditem.select(true); |
|
168 } |
|
169 var o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id]; |
|
170 if (o_iicon) o_iicon.src = this.get_icon(); |
|
171 get_element('i_txt' + this.o_root.n_id + '_' + this.n_id).style.fontWeight = b_deselect ? 'normal' : 'bold'; |
|
172 |
|
173 this.upstatus(); |
|
174 return Boolean(this.a_config[1]); |
|
175 } |
|
176 |
|
177 function item_upstatus (b_clear) { |
|
178 window.setTimeout('window.status="' + (b_clear ? '' : this.a_config[0] + (this.a_config[1] ? ' ('+ this.a_config[1] + ')' : '')) + '"', 10); |
|
179 } |
|
180 |
|
181 function item_init () { |
|
182 var a_offset = [], |
|
183 o_current_item = this.o_parent; |
|
184 for (var i = this.n_depth; i > 1; i--) { |
|
185 a_offset[i] = '<img src="' + this.o_root.a_tpl[o_current_item.is_last() ? 'icon_e' : 'icon_l'] + '" border="0" align="absbottom">'; |
|
186 o_current_item = o_current_item.o_parent; |
|
187 } |
|
188 return '<table cellpadding="0" cellspacing="0" border="0"><tr><td nowrap="nowrap">' + (this.n_depth ? a_offset.join('') + (this.a_children.length |
|
189 ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')"><img src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '"></a>' |
|
190 : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '') |
|
191 // CODE MODIFICATION |
|
192 // removed: |
|
193 // + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '"><img src="' + this.get_icon() + '" border="0" align="absbottom" name="i_img' + this.o_root.n_id + '_' + this.n_id + '" class="t' + this.o_root.n_id + 'im">' + this.a_config[0] + '</a></td></tr></table>' + (this.a_children.length ? '<div id="i_div' + this.o_root.n_id + '_' + this.n_id + '" style="display:none"></div>' : ''); |
|
194 // added: |
|
195 + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '">' + this.a_config[0] + '</a></td></tr></table>' + (this.a_children.length ? '<div id="i_div' + this.o_root.n_id + '_' + this.n_id + '" style="display:none"></div>' : ''); |
|
196 // END MODIFICATIONS |
|
197 alert('i_div' + this.o_root.n_id + '_' + this.n_id); |
|
198 } |
|
199 |
|
200 function item_get_icon (b_junction) { |
|
201 return this.o_root.a_tpl['icon_' + ((this.n_depth ? 0 : 32) + (this.a_children.length ? 16 : 0) + (this.a_children.length && this.b_opened ? 8 : 0) + (!b_junction && this.o_root.o_selected == this ? 4 : 0) + (b_junction ? 2 : 0) + (b_junction && this.is_last() ? 1 : 0))]; |
|
202 } |
|
203 |
|
204 var trees = []; |
|
205 get_element = document.all ? |
|
206 function (s_id) { return document.all[s_id] } : |
|
207 function (s_id) { return document.getElementById(s_id) }; |
|
208 |
|
209 |