author | Dan |
Mon, 15 Jun 2009 20:09:58 -0400 | |
changeset 1023 | 5a282dbf8fad |
parent 1010 | 12e76b1acb4e |
child 1046 | cfc6c30c5e2d |
permissions | -rw-r--r-- |
1 | 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 |
||
12 |
/* |
|
13 |
* Title: Tigra Tree |
|
14 |
* Description: See the demo at url |
|
15 |
* URL: http://www.softcomplex.com/products/tigra_tree_menu/ |
|
16 |
* Version: 1.1 |
|
17 |
* Date: 11-12-2002 (mm-dd-yyyy) |
|
18 |
* Notes: This script is free. Visit official site for further details. |
|
19 |
* |
|
15
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
parents:
1
diff
changeset
|
20 |
* Due to the unclear licensing conditions on this script, I contacted the author, who said that because Enano |
1010
12e76b1acb4e
Clarified some licensing issues from the Fedora project's preliminary review.
Dan
parents:
651
diff
changeset
|
21 |
* is not a "competing product" I was allowed release the modified code as GPL. The conversation can be seen in the |
12e76b1acb4e
Clarified some licensing issues from the Fedora project's preliminary review.
Dan
parents:
651
diff
changeset
|
22 |
* licenses/tigra-menu.html document in the Enano distribution. |
1 | 23 |
*/ |
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
24 |
|
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
25 |
if ( typeof(readCookie) == 'function' ) |
1 | 26 |
{ |
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
27 |
var ck = readCookie('admin_menu_state'); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
28 |
if(ck) |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
29 |
{ |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
30 |
ck = parseInt(ck); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
31 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
32 |
else |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
33 |
{ |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
34 |
ck = 0; |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
35 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
36 |
ck = ( isNaN(ck) ) ? 0 : ck; |
1 | 37 |
} |
38 |
else |
|
39 |
{ |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
15
diff
changeset
|
40 |
var ck = 0; |
1 | 41 |
} |
42 |
||
1023
5a282dbf8fad
Added support for preloading javascript libs ($template->preload_js()). Updated admin theme and Tigra Tree Menu to support this + JS_{HEADER,FOOTER} variables.
Dan
parents:
1010
diff
changeset
|
43 |
function tree (a_items, a_template, s_target) { |
1 | 44 |
|
45 |
this.a_tpl = a_template; |
|
46 |
this.a_config = a_items; |
|
47 |
this.o_root = this; |
|
48 |
this.a_index = []; |
|
49 |
this.o_selected = null; |
|
50 |
this.n_depth = -1; |
|
51 |
||
52 |
var o_icone = new Image(), |
|
53 |
o_iconl = new Image(); |
|
54 |
o_icone.src = a_template['icon_e']; |
|
55 |
o_iconl.src = a_template['icon_l']; |
|
56 |
a_template['im_e'] = o_icone; |
|
57 |
a_template['im_l'] = o_iconl; |
|
58 |
for (var i = 0; i < 64; i++) |
|
59 |
if (a_template['icon_' + i]) { |
|
60 |
var o_icon = new Image(); |
|
61 |
a_template['im_' + i] = o_icon; |
|
62 |
o_icon.src = a_template['icon_' + i]; |
|
63 |
} |
|
64 |
||
65 |
this.toggle = function (n_id,co) { var o_item = this.a_index[n_id]; o_item.open(o_item.b_opened,co); }; |
|
66 |
this.open = function (n_id,co) { var o_item = this.a_index[n_id]; o_item.open(false,co); }; |
|
67 |
this.select = function (n_id) { return this.a_index[n_id].select(); }; |
|
68 |
this.mout = function (n_id) { this.a_index[n_id].upstatus(true) }; |
|
69 |
this.mover = function (n_id) { this.a_index[n_id].upstatus() }; |
|
70 |
||
71 |
this.a_children = []; |
|
72 |
for (var i = 0; i < a_items.length; i++) |
|
73 |
{ |
|
74 |
new tree_item(this, i); |
|
75 |
} |
|
76 |
||
77 |
this.n_id = trees.length; |
|
78 |
trees[this.n_id] = this; |
|
79 |
||
1023
5a282dbf8fad
Added support for preloading javascript libs ($template->preload_js()). Updated admin theme and Tigra Tree Menu to support this + JS_{HEADER,FOOTER} variables.
Dan
parents:
1010
diff
changeset
|
80 |
for (var i = 0; i < this.a_children.length; i++) |
5a282dbf8fad
Added support for preloading javascript libs ($template->preload_js()). Updated admin theme and Tigra Tree Menu to support this + JS_{HEADER,FOOTER} variables.
Dan
parents:
1010
diff
changeset
|
81 |
{ |
5a282dbf8fad
Added support for preloading javascript libs ($template->preload_js()). Updated admin theme and Tigra Tree Menu to support this + JS_{HEADER,FOOTER} variables.
Dan
parents:
1010
diff
changeset
|
82 |
if ( s_target ) |
5a282dbf8fad
Added support for preloading javascript libs ($template->preload_js()). Updated admin theme and Tigra Tree Menu to support this + JS_{HEADER,FOOTER} variables.
Dan
parents:
1010
diff
changeset
|
83 |
document.getElementById(s_target).innerHTML += this.a_children[i].init(); |
5a282dbf8fad
Added support for preloading javascript libs ($template->preload_js()). Updated admin theme and Tigra Tree Menu to support this + JS_{HEADER,FOOTER} variables.
Dan
parents:
1010
diff
changeset
|
84 |
else |
5a282dbf8fad
Added support for preloading javascript libs ($template->preload_js()). Updated admin theme and Tigra Tree Menu to support this + JS_{HEADER,FOOTER} variables.
Dan
parents:
1010
diff
changeset
|
85 |
document.write(this.a_children[i].init()); |
1 | 86 |
this.a_children[i].open(false, true); |
87 |
} |
|
88 |
} |
|
89 |
function tree_item (o_parent, n_order) { |
|
90 |
||
91 |
this.n_depth = o_parent.n_depth + 1; |
|
92 |
this.a_config = o_parent.a_config[n_order + (this.n_depth ? 2 : 0)]; |
|
93 |
if (!this.a_config) return; |
|
94 |
||
95 |
this.o_root = o_parent.o_root; |
|
96 |
this.o_parent = o_parent; |
|
97 |
this.n_order = n_order; |
|
98 |
this.b_opened = !this.n_depth; |
|
99 |
||
100 |
this.n_id = this.o_root.a_index.length; |
|
101 |
this.o_root.a_index[this.n_id] = this; |
|
102 |
o_parent.a_children[n_order] = this; |
|
103 |
||
104 |
this.a_children = []; |
|
105 |
for (var i = 0; i < this.a_config.length - 2; i++) |
|
106 |
{ |
|
107 |
new tree_item(this, i); |
|
108 |
} |
|
109 |
||
110 |
this.get_icon = item_get_icon; |
|
111 |
this.open = item_open; |
|
112 |
this.select = item_select; |
|
113 |
this.init = item_init; |
|
114 |
this.upstatus = item_upstatus; |
|
115 |
this.is_last = function () { return this.n_order == this.o_parent.a_children.length - 1 }; |
|
116 |
||
117 |
// CODE MODIFICATION |
|
118 |
// added: |
|
119 |
// Do we need to open the branch? |
|
120 |
n = Math.pow(2, this.n_id); |
|
121 |
var disp = ( ck & n ) ? true : false; |
|
122 |
s = ( disp ) ? 'open' : 'closed'; |
|
123 |
//if(s=='open') alert(this.n_id + ': ' + s); |
|
124 |
if(disp) setTimeout('trees['+trees.length+'].open('+this.n_id+', true);', 10); |
|
125 |
// END MODIFICATIONS |
|
126 |
} |
|
127 |
||
128 |
function item_open (b_close, nocookie) { |
|
129 |
//alert('item_open('+this.n_id+');'); |
|
130 |
var o_idiv = get_element('i_div' + this.o_root.n_id + '_' + this.n_id); |
|
131 |
if (!o_idiv) return; |
|
132 |
||
133 |
if (!o_idiv.innerHTML) { |
|
134 |
var a_children = []; |
|
135 |
for (var i = 0; i < this.a_children.length; i++) |
|
136 |
{ |
|
137 |
a_children[i]= this.a_children[i].init(); |
|
138 |
} |
|
139 |
o_idiv.innerHTML = a_children.join(''); |
|
140 |
} |
|
141 |
o_idiv.style.display = (b_close ? 'none' : 'block'); |
|
142 |
||
143 |
// CODE MODIFICATION |
|
144 |
// added: |
|
145 |
if(!nocookie) |
|
146 |
{ |
|
147 |
// The idea here is to use a bitwise field. Nice 'n simple, right? Object of the game is to assemble |
|
148 |
// a binary number that depicts the open/closed state of the entire menu in one cookie. |
|
149 |
n = Math.pow(2, this.n_id); |
|
150 |
ck = ( b_close ) ? ck-n : ck+n; |
|
151 |
//alert('open(): doing the cookie routine for id '+this.n_id+"\nResult for bitwise op: "+ck); |
|
152 |
createCookie('admin_menu_state', ck, 365); |
|
153 |
} else { |
|
154 |
//alert('open(): NOT doing the cookie routine for id '+this.n_id); |
|
155 |
} |
|
156 |
// END MODIFICATIONS |
|
157 |
||
158 |
this.b_opened = !b_close; |
|
159 |
var o_jicon = document.images['j_img' + this.o_root.n_id + '_' + this.n_id], |
|
160 |
o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id]; |
|
161 |
if (o_jicon) o_jicon.src = this.get_icon(true); |
|
162 |
if (o_iicon) o_iicon.src = this.get_icon(); |
|
163 |
this.upstatus(); |
|
164 |
} |
|
165 |
||
166 |
function item_select (b_deselect) { |
|
167 |
if (!b_deselect) { |
|
168 |
var o_olditem = this.o_root.o_selected; |
|
169 |
this.o_root.o_selected = this; |
|
170 |
if (o_olditem) o_olditem.select(true); |
|
171 |
} |
|
172 |
var o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id]; |
|
173 |
if (o_iicon) o_iicon.src = this.get_icon(); |
|
174 |
get_element('i_txt' + this.o_root.n_id + '_' + this.n_id).style.fontWeight = b_deselect ? 'normal' : 'bold'; |
|
175 |
||
176 |
this.upstatus(); |
|
177 |
return Boolean(this.a_config[1]); |
|
178 |
} |
|
179 |
||
180 |
function item_upstatus (b_clear) { |
|
530
8d3c49b8dc79
Fixed Javascript error in admin-menu with quotes in list items
Dan
parents:
21
diff
changeset
|
181 |
window.setTimeout('window.status="' + addslashes(b_clear ? '' : this.a_config[0] + (this.a_config[1] ? ' ('+ this.a_config[1] + ')' : '')) + '"', 10); |
1 | 182 |
} |
183 |
||
184 |
function item_init () { |
|
185 |
var a_offset = [], |
|
186 |
o_current_item = this.o_parent; |
|
187 |
for (var i = this.n_depth; i > 1; i--) { |
|
188 |
a_offset[i] = '<img src="' + this.o_root.a_tpl[o_current_item.is_last() ? 'icon_e' : 'icon_l'] + '" border="0" align="absbottom">'; |
|
189 |
o_current_item = o_current_item.o_parent; |
|
190 |
} |
|
191 |
return '<table cellpadding="0" cellspacing="0" border="0"><tr><td nowrap="nowrap">' + (this.n_depth ? a_offset.join('') + (this.a_children.length |
|
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>' |
|
193 |
: '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '') |
|
194 |
// CODE MODIFICATION |
|
651
ce9d78d7251d
Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents:
582
diff
changeset
|
195 |
// [7/20/08: removed ondblclick property (unneeded)] |
1 | 196 |
// removed: |
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>' : ''); |
|
198 |
// added: |
|
651
ce9d78d7251d
Improved JSON validation and error interface when validation fails; made rank manager support custom CSS
Dan
parents:
582
diff
changeset
|
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>' : ''); |
1 | 200 |
// END MODIFICATIONS |
201 |
alert('i_div' + this.o_root.n_id + '_' + this.n_id); |
|
202 |
} |
|
203 |
||
204 |
function item_get_icon (b_junction) { |
|
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))]; |
|
206 |
} |
|
207 |
||
208 |
var trees = []; |
|
209 |
get_element = document.all ? |
|
210 |
function (s_id) { return document.all[s_id] } : |
|
211 |
function (s_id) { return document.getElementById(s_id) }; |
|
212 |
||
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
561
diff
changeset
|
213 |
function addslashes(text) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
561
diff
changeset
|
214 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
561
diff
changeset
|
215 |
text = text.replace(/\\/g, '\\\\'); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
561
diff
changeset
|
216 |
text = text.replace(/"/g, '\\"'); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
561
diff
changeset
|
217 |
return text; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
561
diff
changeset
|
218 |
} |