5 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
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. |
6 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
7 * |
7 * |
8 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
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. |
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 */ |
10 */ |
14 |
11 |
15 /* |
12 /* |
16 * Title: Tigra Tree |
13 * Title: Tigra Tree |
17 * Description: See the demo at url |
14 * Description: See the demo at url |
18 * URL: http://www.softcomplex.com/products/tigra_tree_menu/ |
15 * URL: http://www.softcomplex.com/products/tigra_tree_menu/ |
19 * Version: 1.1 |
16 * Version: 1.1 |
20 * Date: 11-12-2002 (mm-dd-yyyy) |
17 * Date: 11-12-2002 (mm-dd-yyyy) |
21 * Notes: This script is free. Visit official site for further details. |
18 * Notes: This script is free. Visit official site for further details. |
22 * |
19 * |
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 * Due to the unclear licensing conditions on this script, I contacted the author, who said that because Enano |
20 * Due to the unclear licensing conditions on this script, I contacted the author, who said that because Enano |
33 * is not a "competing product" I was allowed to treat the code as GPL. The conversation can be seen in the |
21 * is not a "competing product" I was allowed release the modified code as GPL. The conversation can be seen in the |
34 * /licenses/tigra-menu.html document in the Enano distribution. |
22 * licenses/tigra-menu.html document in the Enano distribution. |
35 */ |
23 */ |
36 |
24 |
37 if ( typeof(readCookie) == 'function' ) |
25 if ( /admin_menu_state=/.test(document.cookie) ) |
38 { |
26 { |
39 var ck = readCookie('admin_menu_state'); |
27 var ck = (String(document.cookie).match(/admin_menu_state=([0-9]+)/))[1]; |
40 if(ck) |
28 if(ck) |
41 { |
29 { |
42 ck = parseInt(ck); |
30 ck = parseInt(ck); |
43 } |
31 } |
44 else |
32 else |
45 { |
33 { |
46 ck = 0; |
34 ck = 0; |
47 } |
35 } |
48 ck = ( isNaN(ck) ) ? 0 : ck; |
36 ck = ( isNaN(ck) ) ? 0 : ck; |
49 } |
37 } |
50 else |
38 else |
51 { |
39 { |
52 var ck = 0; |
40 var ck = 0; |
53 } |
41 } |
54 |
42 |
55 function tree (a_items, a_template) { |
43 function tree (a_items, a_template, s_target) { |
56 |
44 |
57 this.a_tpl = a_template; |
45 this.a_tpl = a_template; |
58 this.a_config = a_items; |
46 this.a_config = a_items; |
59 this.o_root = this; |
47 this.o_root = this; |
60 this.a_index = []; |
48 this.a_index = []; |
73 a_template['im_' + i] = o_icon; |
61 a_template['im_' + i] = o_icon; |
74 o_icon.src = a_template['icon_' + i]; |
62 o_icon.src = a_template['icon_' + i]; |
75 } |
63 } |
76 |
64 |
77 this.toggle = function (n_id,co) { var o_item = this.a_index[n_id]; o_item.open(o_item.b_opened,co); }; |
65 this.toggle = function (n_id,co) { var o_item = this.a_index[n_id]; o_item.open(o_item.b_opened,co); }; |
78 this.open = function (n_id,co) { var o_item = this.a_index[n_id]; o_item.open(false,co); }; |
66 this.open = function (n_id,co) { var o_item = this.a_index[n_id]; o_item.open(false,co); }; |
79 this.select = function (n_id) { return this.a_index[n_id].select(); }; |
67 this.select = function (n_id) { return this.a_index[n_id].select(); }; |
80 this.mout = function (n_id) { this.a_index[n_id].upstatus(true) }; |
68 this.mout = function (n_id) { this.a_index[n_id].upstatus(true) }; |
81 this.mover = function (n_id) { this.a_index[n_id].upstatus() }; |
69 this.mover = function (n_id) { this.a_index[n_id].upstatus() }; |
82 |
70 |
83 this.a_children = []; |
71 this.a_children = []; |
84 for (var i = 0; i < a_items.length; i++) |
72 for (var i = 0; i < a_items.length; i++) |
85 { |
73 { |
86 new tree_item(this, i); |
74 new tree_item(this, i); |
87 } |
75 } |
88 |
76 |
89 this.n_id = trees.length; |
77 this.n_id = trees.length; |
90 trees[this.n_id] = this; |
78 trees[this.n_id] = this; |
91 |
79 |
92 for (var i = 0; i < this.a_children.length; i++) { |
80 for (var i = 0; i < this.a_children.length; i++) |
93 document.write(this.a_children[i].init()); |
81 { |
|
82 if ( s_target ) |
|
83 document.getElementById(s_target).innerHTML += this.a_children[i].init(); |
|
84 else |
|
85 document.write(this.a_children[i].init()); |
94 this.a_children[i].open(false, true); |
86 this.a_children[i].open(false, true); |
95 } |
87 } |
96 } |
88 } |
97 function tree_item (o_parent, n_order) { |
89 function tree_item (o_parent, n_order) { |
98 |
90 |
109 this.o_root.a_index[this.n_id] = this; |
101 this.o_root.a_index[this.n_id] = this; |
110 o_parent.a_children[n_order] = this; |
102 o_parent.a_children[n_order] = this; |
111 |
103 |
112 this.a_children = []; |
104 this.a_children = []; |
113 for (var i = 0; i < this.a_config.length - 2; i++) |
105 for (var i = 0; i < this.a_config.length - 2; i++) |
114 { |
106 { |
115 new tree_item(this, i); |
107 new tree_item(this, i); |
116 } |
108 } |
117 |
109 |
118 this.get_icon = item_get_icon; |
110 this.get_icon = item_get_icon; |
119 this.open = item_open; |
111 this.open = item_open; |
120 this.select = item_select; |
112 this.select = item_select; |
121 this.init = item_init; |
113 this.init = item_init; |
122 this.upstatus = item_upstatus; |
114 this.upstatus = item_upstatus; |
123 this.is_last = function () { return this.n_order == this.o_parent.a_children.length - 1 }; |
115 this.is_last = function () { return this.n_order == this.o_parent.a_children.length - 1 }; |
124 |
116 |
125 // CODE MODIFICATION |
117 // CODE MODIFICATION |
126 // added: |
118 // added: |
127 // Do we need to open the branch? |
119 // Do we need to open the branch? |
128 n = Math.pow(2, this.n_id); |
120 n = Math.pow(2, this.n_id); |
129 var disp = ( ck & n ) ? true : false; |
121 var disp = ( ck & n ) ? true : false; |
130 s = ( disp ) ? 'open' : 'closed'; |
122 s = ( disp ) ? 'open' : 'closed'; |
131 //if(s=='open') alert(this.n_id + ': ' + s); |
123 //if(s=='open') alert(this.n_id + ': ' + s); |
132 if(disp) setTimeout('trees['+trees.length+'].open('+this.n_id+', true);', 10); |
124 if(disp) setTimeout('trees['+trees.length+'].open('+this.n_id+', true);', 10); |
133 // END MODIFICATIONS |
125 // END MODIFICATIONS |
134 } |
126 } |
135 |
127 |
136 function item_open (b_close, nocookie) { |
128 function item_open (b_close, nocookie) { |
137 //alert('item_open('+this.n_id+');'); |
129 //alert('item_open('+this.n_id+');'); |
138 var o_idiv = get_element('i_div' + this.o_root.n_id + '_' + this.n_id); |
130 var o_idiv = get_element('i_div' + this.o_root.n_id + '_' + this.n_id); |
139 if (!o_idiv) return; |
131 if (!o_idiv) return; |
140 |
132 |
141 if (!o_idiv.innerHTML) { |
133 if (!o_idiv.innerHTML) { |
142 var a_children = []; |
134 var a_children = []; |
143 for (var i = 0; i < this.a_children.length; i++) |
135 for (var i = 0; i < this.a_children.length; i++) |
144 { |
136 { |
145 a_children[i]= this.a_children[i].init(); |
137 a_children[i]= this.a_children[i].init(); |
146 } |
138 } |
147 o_idiv.innerHTML = a_children.join(''); |
139 o_idiv.innerHTML = a_children.join(''); |
148 } |
140 } |
149 o_idiv.style.display = (b_close ? 'none' : 'block'); |
141 o_idiv.style.display = (b_close ? 'none' : 'block'); |
150 |
142 |
151 // CODE MODIFICATION |
143 // CODE MODIFICATION |
152 // added: |
144 // added: |
153 if(!nocookie) |
145 if(!nocookie) |
154 { |
146 { |
155 // The idea here is to use a bitwise field. Nice 'n simple, right? Object of the game is to assemble |
147 // The idea here is to use a bitwise field. Nice 'n simple, right? Object of the game is to assemble |
156 // a binary number that depicts the open/closed state of the entire menu in one cookie. |
148 // a binary number that depicts the open/closed state of the entire menu in one cookie. |
157 n = Math.pow(2, this.n_id); |
149 n = Math.pow(2, this.n_id); |
158 ck = ( b_close ) ? ck-n : ck+n; |
150 ck = ( b_close ) ? ck-n : ck+n; |
159 //alert('open(): doing the cookie routine for id '+this.n_id+"\nResult for bitwise op: "+ck); |
151 //alert('open(): doing the cookie routine for id '+this.n_id+"\nResult for bitwise op: "+ck); |
160 createCookie('admin_menu_state', ck, 365); |
152 createCookie('admin_menu_state', ck, 365); |
161 } else { |
153 } else { |
162 //alert('open(): NOT doing the cookie routine for id '+this.n_id); |
154 //alert('open(): NOT doing the cookie routine for id '+this.n_id); |
163 } |
155 } |
164 // END MODIFICATIONS |
156 // END MODIFICATIONS |
165 |
157 |
166 this.b_opened = !b_close; |
158 this.b_opened = !b_close; |
167 var o_jicon = document.images['j_img' + this.o_root.n_id + '_' + this.n_id], |
159 var o_jicon = document.images['j_img' + this.o_root.n_id + '_' + this.n_id], |
168 o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id]; |
160 o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id]; |
169 if (o_jicon) o_jicon.src = this.get_icon(true); |
161 if (o_jicon) o_jicon.src = this.get_icon(true); |
197 o_current_item = o_current_item.o_parent; |
189 o_current_item = o_current_item.o_parent; |
198 } |
190 } |
199 return '<table cellpadding="0" cellspacing="0" border="0"><tr><td nowrap="nowrap">' + (this.n_depth ? a_offset.join('') + (this.a_children.length |
191 return '<table cellpadding="0" cellspacing="0" border="0"><tr><td nowrap="nowrap">' + (this.n_depth ? a_offset.join('') + (this.a_children.length |
200 ? '<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>' |
192 ? '<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>' |
201 : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '') |
193 : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '') |
202 // CODE MODIFICATION |
194 // CODE MODIFICATION |
203 // removed: |
195 // [7/20/08: removed ondblclick property (unneeded)] |
|
196 // removed: |
204 // + '<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>' : ''); |
197 // + '<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>' : ''); |
205 // added: |
198 // added: |
206 + '<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>' : ''); |
199 + '<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 + ')" 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>' : ''); |
207 // END MODIFICATIONS |
200 // END MODIFICATIONS |
208 alert('i_div' + this.o_root.n_id + '_' + this.n_id); |
201 alert('i_div' + this.o_root.n_id + '_' + this.n_id); |
209 } |
202 } |
210 |
203 |
211 function item_get_icon (b_junction) { |
204 function item_get_icon (b_junction) { |
212 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))]; |
205 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))]; |
213 } |
206 } |
215 var trees = []; |
208 var trees = []; |
216 get_element = document.all ? |
209 get_element = document.all ? |
217 function (s_id) { return document.all[s_id] } : |
210 function (s_id) { return document.all[s_id] } : |
218 function (s_id) { return document.getElementById(s_id) }; |
211 function (s_id) { return document.getElementById(s_id) }; |
219 |
212 |
220 |
213 function addslashes(text) |
|
214 { |
|
215 text = text.replace(/\\/g, '\\\\'); |
|
216 text = text.replace(/"/g, '\\"'); |
|
217 return text; |
|
218 } |
|
219 |
|
220 // ******************************************* |
|
221 // Table collapsing |
|
222 // ******************************************* |
|
223 |
|
224 function admin_table_onload(page) |
|
225 { |
|
226 if ( page != namespace_list['Admin'] + 'GeneralConfig' ) |
|
227 { |
|
228 return true; |
|
229 } |
|
230 var collapse_state = admin_table_get_cookie(page); |
|
231 if ( collapse_state == 0 ) |
|
232 collapse_state = 0xffffffff; |
|
233 $('#ajaxPageContainer > form > div.tblholder > table').each(function(i, table) |
|
234 { |
|
235 // skip if this is a one-row table |
|
236 if ( $('tr:first', table).get(0) == $('tr:last', table).get(0) ) |
|
237 return; |
|
238 |
|
239 var open = (collapse_state >> i) & 1 > 0 ? true : false; |
|
240 |
|
241 var ypos = open ? 0 : 12; |
|
242 |
|
243 var div = document.createElement('div'); |
|
244 $(div).html(gen_sprite_html(scriptPath + '/themes/admin/images/thcollapse.png', 12, 12, ypos, 0)); |
|
245 $(div).click(function() |
|
246 { |
|
247 admin_table_click(this); |
|
248 }).css('cursor', 'pointer').css('float', 'right'); |
|
249 div.thetable = table; |
|
250 div.index = i; |
|
251 div.thepage = page; |
|
252 div.openstate = open; |
|
253 $('tr > th:first', table).prepend(div); |
|
254 if ( !open ) |
|
255 admin_table_collapse(table, true); |
|
256 }); |
|
257 } |
|
258 |
|
259 function admin_table_click(mydiv) |
|
260 { |
|
261 var table = mydiv.thetable; |
|
262 var i = mydiv.index; |
|
263 var page = mydiv.thepage; |
|
264 var collapse_state = admin_table_get_cookie(page); |
|
265 |
|
266 if ( mydiv.openstate ) |
|
267 { |
|
268 $('img', mydiv).css('background-position', '0px -12px'); |
|
269 var new_collapse_state = collapse_state & ~Math.pow(2, i); |
|
270 console.debug(new_collapse_state); |
|
271 mydiv.openstate = false; |
|
272 admin_table_collapse(table); |
|
273 } |
|
274 else |
|
275 { |
|
276 $('img', mydiv).css('background-position', '0px 0px'); |
|
277 var new_collapse_state = collapse_state | Math.pow(2, i); |
|
278 console.debug(new_collapse_state); |
|
279 mydiv.openstate = true; |
|
280 admin_table_expand(table); |
|
281 } |
|
282 createCookie('admin_th:' + page, new_collapse_state, 3650); |
|
283 } |
|
284 |
|
285 function admin_table_get_cookie(page) |
|
286 { |
|
287 var cookievalue = parseInt(readCookie('admin_th:' + page)); |
|
288 if ( isNaN(cookievalue) ) |
|
289 cookievalue = 0; |
|
290 return cookievalue; |
|
291 } |
|
292 |
|
293 function admin_table_collapse(table, noanim) |
|
294 { |
|
295 var targetheight = $('tr > th:first', table).height(); |
|
296 $('tr', table).hide(); |
|
297 $('tr:first', table).show(); |
|
298 } |
|
299 |
|
300 function admin_table_expand(table) |
|
301 { |
|
302 $('tr', table).show(); |
|
303 } |