author | Dan |
Wed, 06 Jan 2010 02:20:53 -0500 | |
changeset 1210 | ad49fa34ff3c |
parent 865 | 7f8262b2004a |
child 1227 | bdac73ed481e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
2 |
* The jBox menu system. Written by Dan Fuhry and licensed under the GPL. |
|
3 |
*/ |
|
4 |
||
5 |
// Cache of DOM and event objects, used in setTimeout() calls due to scope rules |
|
6 |
var jBoxObjCache = new Object(); |
|
7 |
||
8 |
// Cache of "correct" heights for unordered list objects used in submenus. Helps the animation routine know what height it's aiming for. |
|
9 |
var jBoxMenuHeights = new Object(); |
|
10 |
||
11 |
// Blocks animations from running if there's already an animation going on the same object |
|
12 |
var jBoxSlideBlocker = new Object(); |
|
13 |
||
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
14 |
// Switch to enable or disable jBox slide animation |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
15 |
var jBox_slide_enable = true; |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
16 |
|
1 | 17 |
// Speed at which the menus should slide open. 1 to 100 or -1 to disable. |
18 |
// Setting this higher than 100 will cause an infinite loop in the browser. |
|
19 |
// Default is 80 - anything higher than 90 means exponential speed increase |
|
20 |
var slide_speed = 80; |
|
21 |
||
22 |
// Inertia value to start with |
|
23 |
// Default is 0 |
|
24 |
var inertia_base = 0; |
|
25 |
||
26 |
// Value added to inertia_base on each frame - generally 1 to 3 is good, with 1 being slowest animation |
|
27 |
// Default is 1 |
|
28 |
var inertia_inc = 1; |
|
29 |
||
30 |
// Opacity that menus should fade to. 1 to 100 or -1 to disable fades. This only works if the slide effect is also enabled. |
|
31 |
// Default is 100 |
|
32 |
var jBox_opacity = 100; |
|
33 |
||
34 |
// Adds the jBox CSS to the HTML header. Called on window onload. |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
35 |
var jBoxInit = function() |
1 | 36 |
{ |
37 |
setTimeout('jBoxBatchSetup();', 200); |
|
38 |
} |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
39 |
addOnloadHook(jBoxInit); |
1 | 40 |
|
41 |
// Initializes each menu. |
|
42 |
function jBoxBatchSetup() |
|
43 |
{ |
|
57
b354deeaa4c4
Vastly improved compatibility with older versions of IE, particularly 5.0, through the use of a kill switch that turns off all AJAX functions
Dan
parents:
40
diff
changeset
|
44 |
if ( KILL_SWITCH ) |
b354deeaa4c4
Vastly improved compatibility with older versions of IE, particularly 5.0, through the use of a kill switch that turns off all AJAX functions
Dan
parents:
40
diff
changeset
|
45 |
return false; |
1 | 46 |
var menus = document.getElementsByClassName('div', 'menu_nojs'); |
47 |
if ( menus.length > 0 ) |
|
48 |
{ |
|
49 |
for ( var i in menus ) |
|
50 |
{ |
|
51 |
if ( typeof(menus[i]) != 'object') |
|
52 |
continue; // toJSONString() compatibility |
|
53 |
jBoxSetup(menus[i]); |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
// Initializes a div with a jBox menu in it. |
|
59 |
function jBoxSetup(obj) |
|
60 |
{ |
|
420
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
394
diff
changeset
|
61 |
$dynano(obj).addClass('menu'); |
1 | 62 |
removeTextNodes(obj); |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
63 |
|
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
64 |
for ( var i = 0; i < obj.childNodes.length; i++ ) |
1 | 65 |
{ |
66 |
/* normally this would be done in about 2 lines of code, but javascript is so picky..... */ |
|
67 |
if ( obj.childNodes[i] ) |
|
68 |
{ |
|
69 |
if ( obj.childNodes[i].tagName ) |
|
70 |
{ |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
71 |
if ( obj.childNodes[i].tagName == 'A' ) |
1 | 72 |
{ |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
73 |
// if ( is_Safari ) alert('It\'s an A: '+obj); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
74 |
if ( obj.childNodes[i].nextSibling ) |
1 | 75 |
{ |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
76 |
// alert("Next sibling: " + obj.childNodes[i].nextSibling); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
77 |
if ( obj.childNodes[i].nextSibling.tagName ) |
1 | 78 |
{ |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
79 |
if ( obj.childNodes[i].nextSibling.tagName == 'UL' || ( obj.childNodes[i].nextSibling.tagName.toLowerCase() == 'div' && obj.childNodes[i].nextSibling.className == 'submenu' ) ) |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
80 |
{ |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
81 |
// Calculate height |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
82 |
var ul = obj.childNodes[i].nextSibling; |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
83 |
domObjChangeOpac(0, ul); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
84 |
ul.style.display = 'block'; |
680 | 85 |
ul.style.zIndex = getHighestZ() + 2; |
806
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
86 |
var links = ul.getElementsByTagName('a'); |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
87 |
for ( var j = 0; j < links.length; j++ ) |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
88 |
{ |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
89 |
links[j].onmouseup = function() |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
90 |
{ |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
91 |
var ul = this; |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
92 |
while ( ul.tagName != 'UL' && ul.tagName != 'DIV' && ul.tagName != 'BODY' ) |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
93 |
ul = ul.parentNode; |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
94 |
if ( ul.tagName == 'BODY' ) |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
95 |
return false; |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
96 |
jBoxHideMenu(ul.previousSibling, ul); |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
97 |
} |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
98 |
} |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
99 |
var dim = fetch_dimensions(ul); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
100 |
if ( !ul.id ) |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
101 |
ul.id = 'jBoxmenuobj_' + Math.floor(Math.random() * 10000000); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
102 |
jBoxMenuHeights[ul.id] = parseInt(dim['h']) - 2; // subtract 2px for border width |
853
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
103 |
|
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
104 |
if ( dim['w'] + $dynano(ul).Left() > getWidth() || $dynano(ul).hasClass('jbox_right') ) |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
105 |
{ |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
106 |
$dynano(ul).addClass('jbox_right'); |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
107 |
ul.jbox_width = $dynano(ul).Width(); |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
108 |
} |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
109 |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
110 |
ul.style.display = 'none'; |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
111 |
domObjChangeOpac(100, ul); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
112 |
|
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
113 |
// Setup events |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
114 |
obj.childNodes[i].onmouseover = function() { jBoxOverHandler(this); }; |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
115 |
obj.childNodes[i].onmouseout = function(e) { jBoxOutHandler(this, e); }; |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
116 |
obj.childNodes[i].nextSibling.onmouseout = function(e) { jBoxOutHandler(this, e); }; |
523 | 117 |
if ( is_iPhone ) |
118 |
{ |
|
119 |
obj.childNodes[i].onclick = function() { jBoxOverHandler(this); return false; }; |
|
120 |
} |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
121 |
} |
1 | 122 |
} |
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
// Called when user hovers mouse over a submenu |
|
131 |
function jBoxOverHandler(obj) |
|
132 |
{ |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
133 |
// if ( is_Safari ) |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
134 |
// alert('Safari and over'); |
1 | 135 |
// Random ID used to track the object to perform on |
136 |
var seed = Math.floor(Math.random() * 1000000); |
|
137 |
jBoxObjCache[seed] = obj; |
|
138 |
||
139 |
// Sleep for a (little more than a tenth of a) second to see if the user really wants the menu to expand |
|
140 |
setTimeout('if(isOverObj(jBoxObjCache['+seed+'], false, false)) jBoxOverHandlerBin(jBoxObjCache['+seed+']);', 150); |
|
141 |
} |
|
142 |
||
143 |
// Displays a menu. |
|
144 |
function jBoxOverHandlerBin(obj) |
|
145 |
{ |
|
146 |
var others = obj.parentNode.getElementsByTagName('ul'); |
|
147 |
for ( var i in others ) |
|
148 |
{ |
|
149 |
if(typeof(others[i]) == 'object') |
|
150 |
{ |
|
151 |
others[i].style.display = 'none'; |
|
420
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
394
diff
changeset
|
152 |
$dynano(others[i].previousSibling).rmClass('liteselected'); |
1 | 153 |
} |
154 |
} |
|
155 |
var others = obj.parentNode.getElementsByTagName('div'); |
|
156 |
for ( var i in others ) |
|
157 |
{ |
|
158 |
if(typeof(others[i]) == 'object') |
|
159 |
{ |
|
160 |
if ( others[i].className == 'submenu' ) |
|
161 |
{ |
|
162 |
others[i].style.display = 'none'; |
|
420
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
394
diff
changeset
|
163 |
$dynano(others[i].previousSibling).rmClass('liteselected'); |
1 | 164 |
} |
165 |
} |
|
166 |
} |
|
167 |
if(obj.nextSibling.tagName.toLowerCase() == 'ul' || ( obj.nextSibling.tagName.toLowerCase() == 'div' && obj.nextSibling.className == 'submenu' )) |
|
168 |
{ |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
169 |
$dynano(obj).addClass('liteselected'); |
128
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents:
80
diff
changeset
|
170 |
//obj.className = 'liteselected'; |
1 | 171 |
var ul = obj.nextSibling; |
172 |
var dim = fetch_dimensions(obj); |
|
173 |
var off = fetch_offset(obj); |
|
174 |
var dimh = parseInt(dim['h']); |
|
175 |
var offtop = parseInt(off['top']); |
|
176 |
var top = dimh + offtop; |
|
853
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
177 |
if ( $dynano(ul).hasClass('jbox_right') ) |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
178 |
{ |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
179 |
left = $dynano(obj).Left() + $dynano(obj).Width() - ul.jbox_width; // ( link left + link width ) - ul width |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
180 |
} |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
181 |
else |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
182 |
{ |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
183 |
left = off['left']; |
21fea79d9de4
Added ability for jBox to align submenu position to right of parent button instead of left
Dan
parents:
806
diff
changeset
|
184 |
} |
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
185 |
if ( jBox_slide_enable ) |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
186 |
{ |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
187 |
domObjChangeOpac(0, ul); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
188 |
} |
1 | 189 |
ul.style.left = left + 'px'; |
190 |
ul.style.top = top + 'px'; |
|
191 |
ul.style.clip = 'rect(auto,auto,auto,auto)'; |
|
192 |
ul.style.overflow = 'visible'; |
|
193 |
ul.style.display = 'block'; |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
194 |
if ( jBox_slide_enable ) |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
195 |
{ |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
196 |
slideOut(ul); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
197 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
198 |
else |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
199 |
{ |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
200 |
domObjChangeOpac(100, ul); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
1
diff
changeset
|
201 |
} |
1 | 202 |
} |
203 |
} |
|
204 |
||
205 |
function jBoxOutHandler(obj, event) |
|
206 |
{ |
|
207 |
var seed = Math.floor(Math.random() * 1000000); |
|
208 |
var seed2 = Math.floor(Math.random() * 1000000); |
|
209 |
jBoxObjCache[seed] = obj; |
|
210 |
jBoxObjCache[seed2] = event; |
|
211 |
setTimeout('jBoxOutHandlerBin(jBoxObjCache['+seed+'], jBoxObjCache['+seed2+']);', 750); |
|
212 |
} |
|
213 |
||
214 |
function jBoxOutHandlerBin(obj, event) |
|
215 |
{ |
|
216 |
var caller = obj.tagName.toLowerCase(); |
|
217 |
if(caller == 'a') |
|
218 |
{ |
|
219 |
a = obj; |
|
220 |
ul = obj.nextSibling; |
|
221 |
} |
|
222 |
else if(caller == 'ul' || caller == 'div') |
|
223 |
{ |
|
224 |
a = obj.previousSibling; |
|
225 |
ul = obj; |
|
226 |
} |
|
227 |
else |
|
228 |
{ |
|
229 |
return false; |
|
230 |
} |
|
231 |
||
232 |
if (!isOverObj(a, false, event) && !isOverObj(ul, true, event)) |
|
233 |
{ |
|
806
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
234 |
jBoxHideMenu(a, ul); |
1 | 235 |
} |
236 |
||
237 |
return true; |
|
238 |
} |
|
239 |
||
806
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
240 |
function jBoxHideMenu(a, ul) |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
241 |
{ |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
242 |
$dynano(a).rmClass('liteselected'); |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
243 |
|
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
244 |
if ( jBox_slide_enable ) |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
245 |
{ |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
246 |
slideIn(ul); |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
247 |
} |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
248 |
else |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
249 |
{ |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
250 |
ul.style.display = 'none'; |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
251 |
} |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
252 |
} |
543c05f86303
jBox: When an anchor in a menu is clicked, menu is now hidden
Dan
parents:
680
diff
changeset
|
253 |
|
1 | 254 |
// Slide an element downwards until it is at full height. |
255 |
// First parameter should be a DOM object with style.display = block and opacity = 0. |
|
256 |
||
257 |
var sliderobj = new Object(); |
|
258 |
||
259 |
function slideOut(obj) |
|
260 |
{ |
|
261 |
if ( jBoxSlideBlocker[obj.id] ) |
|
262 |
return false; |
|
263 |
||
264 |
jBoxSlideBlocker[obj.id] = true; |
|
265 |
||
266 |
if ( slide_speed == -1 ) |
|
267 |
{ |
|
268 |
obj.style.display = 'block'; |
|
269 |
return false; |
|
270 |
} |
|
271 |
||
272 |
var currentheight = 0; |
|
273 |
var targetheight = jBoxMenuHeights[obj.id]; |
|
274 |
var inertiabase = inertia_base; |
|
275 |
var inertiainc = inertia_inc; |
|
276 |
slideStep(obj, 0); |
|
277 |
domObjChangeOpac(100, obj); |
|
278 |
obj.style.overflow = 'hidden'; |
|
279 |
||
280 |
// Don't edit past here |
|
281 |
var timercnt = 0; |
|
282 |
||
283 |
var seed = Math.floor(Math.random() * 1000000); |
|
284 |
sliderobj[seed] = obj; |
|
285 |
||
286 |
var framecnt = 0; |
|
287 |
||
288 |
while(true) |
|
289 |
{ |
|
290 |
framecnt++; |
|
291 |
timercnt += ( 100 - slide_speed ); |
|
292 |
inertiabase += inertiainc; |
|
293 |
currentheight += inertiabase; |
|
294 |
if ( currentheight > targetheight ) |
|
295 |
currentheight = targetheight; |
|
296 |
setTimeout('slideStep(sliderobj['+seed+'], '+currentheight+', '+targetheight+');', timercnt); |
|
297 |
if ( currentheight >= targetheight ) |
|
298 |
break; |
|
299 |
} |
|
300 |
timercnt = timercnt + ( 100 - slide_speed ); |
|
301 |
setTimeout('jBoxSlideBlocker[sliderobj['+seed+'].id] = false;', timercnt); |
|
302 |
var opacstep = jBox_opacity / framecnt; |
|
303 |
var opac = 0; |
|
304 |
var timerstep = 0; |
|
305 |
domObjChangeOpac(0, obj); |
|
306 |
while(true) |
|
307 |
{ |
|
308 |
timerstep += ( 100 - slide_speed ); |
|
309 |
opac += opacstep; |
|
310 |
setTimeout('domObjChangeOpac('+opac+', sliderobj['+seed+']);', timerstep); |
|
311 |
if ( opac >= jBox_opacity ) |
|
312 |
break; |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
function slideIn(obj) |
|
317 |
{ |
|
318 |
if ( obj.style.display != 'block' ) |
|
319 |
return false; |
|
320 |
||
321 |
if ( jBoxSlideBlocker[obj.id] ) |
|
322 |
return false; |
|
323 |
||
324 |
jBoxSlideBlocker[obj.id] = true; |
|
325 |
||
326 |
var targetheight = 0; |
|
327 |
var dim = fetch_dimensions(obj); |
|
328 |
var currentheight = jBoxMenuHeights[obj.id]; |
|
329 |
var origheight = currentheight; |
|
330 |
var inertiabase = inertia_base; |
|
331 |
var inertiainc = inertia_inc; |
|
332 |
domObjChangeOpac(100, obj); |
|
333 |
obj.style.overflow = 'hidden'; |
|
334 |
||
335 |
// Don't edit past here |
|
336 |
var timercnt = 0; |
|
337 |
||
338 |
var seed = Math.floor(Math.random() * 1000000); |
|
339 |
sliderobj[seed] = obj; |
|
340 |
||
341 |
var framecnt = 0; |
|
342 |
||
343 |
for(var j = 0;j<100;j++) // while(true) |
|
344 |
{ |
|
345 |
framecnt++; |
|
346 |
timercnt = timercnt + ( 100 - slide_speed ); |
|
347 |
inertiabase = inertiabase + inertiainc; |
|
348 |
currentheight = currentheight - inertiabase; |
|
349 |
if ( currentheight < targetheight ) |
|
350 |
currentheight = targetheight; |
|
351 |
setTimeout('slideStep(sliderobj['+seed+'], '+currentheight+');', timercnt); |
|
352 |
if ( currentheight <= targetheight ) |
|
353 |
break; |
|
354 |
} |
|
355 |
timercnt += ( 100 - slide_speed ); |
|
356 |
setTimeout('sliderobj['+seed+'].style.display="none";sliderobj['+seed+'].style.height="'+origheight+'px";jBoxSlideBlocker[sliderobj['+seed+'].id] = false;', timercnt); |
|
357 |
||
358 |
var opacstep = jBox_opacity / framecnt; |
|
359 |
var opac = jBox_opacity; |
|
360 |
var timerstep = 0; |
|
361 |
domObjChangeOpac(100, obj); |
|
362 |
while(true) |
|
363 |
{ |
|
364 |
timerstep += ( 100 - slide_speed ); |
|
365 |
opac -= opacstep; |
|
366 |
setTimeout('domObjChangeOpac('+opac+', sliderobj['+seed+']);', timerstep); |
|
367 |
if ( opac <= 0 ) |
|
368 |
break; |
|
369 |
} |
|
370 |
||
371 |
} |
|
372 |
||
373 |
function slideStep(obj, height, maxheight) |
|
374 |
{ |
|
375 |
obj.style.height = height + 'px'; |
|
376 |
//obj.style.clip = 'rect(3px,auto,'+maxheight+'px,auto)'; |
|
377 |
obj.style.overflow = 'hidden'; |
|
378 |
//obj.style.clip = 'rect('+height+'px,0px,'+maxheight+'px,auto);'; |
|
379 |
} |
|
380 |
||
381 |
function isOverObj(obj, bias, event) |
|
382 |
{ |
|
383 |
var fieldUL = new Object(); |
|
384 |
var dim = fetch_dimensions(obj); |
|
385 |
var off = fetch_offset(obj); |
|
386 |
fieldUL['top'] = off['top']; |
|
387 |
fieldUL['left'] = off['left']; |
|
388 |
fieldUL['right'] = off['left'] + dim['w']; |
|
389 |
fieldUL['bottom'] = off['top'] + dim['h']; |
|
390 |
||
394
fbfdcea634a7
Fixed jBox menus failing to appear when window scrolled down
Dan
parents:
128
diff
changeset
|
391 |
var mouseY_local = mouseY + getScrollOffset(); |
fbfdcea634a7
Fixed jBox menus failing to appear when window scrolled down
Dan
parents:
128
diff
changeset
|
392 |
|
fbfdcea634a7
Fixed jBox menus failing to appear when window scrolled down
Dan
parents:
128
diff
changeset
|
393 |
// document.getElementById('debug').innerHTML = '<br />Mouse: x: '+mouseX+', y:' + mouseY + '<br />' + document.getElementById('debug').innerHTML; |
1 | 394 |
|
395 |
if(bias) |
|
396 |
{ |
|
397 |
if ( ( mouseX < fieldUL['left'] + 2 || mouseX > fieldUL['right'] - 5 ) || |
|
394
fbfdcea634a7
Fixed jBox menus failing to appear when window scrolled down
Dan
parents:
128
diff
changeset
|
398 |
( mouseY_local < fieldUL['top'] - 2 || mouseY_local > fieldUL['bottom'] - 2 ) ) |
1 | 399 |
{ |
400 |
return false; |
|
401 |
} |
|
402 |
} |
|
403 |
else |
|
404 |
{ |
|
405 |
if ( ( mouseX < fieldUL['left'] || mouseX > fieldUL['right'] ) || |
|
394
fbfdcea634a7
Fixed jBox menus failing to appear when window scrolled down
Dan
parents:
128
diff
changeset
|
406 |
( mouseY_local < fieldUL['top'] || mouseY_local > fieldUL['bottom'] ) ) |
1 | 407 |
return false; |
408 |
} |
|
409 |
||
410 |
return true; |
|
411 |
} |
|
412 |
||
413 |
function jBoxGarbageCollection(e) |
|
414 |
{ |
|
415 |
setMousePos(e); |
|
416 |
var menus = document.getElementsByClassName('div', 'menu'); |
|
417 |
if ( menus.length > 0 ) |
|
418 |
{ |
|
419 |
for ( var i in menus ) |
|
420 |
{ |
|
421 |
if ( typeof(menus[i]) != 'object') |
|
422 |
continue; // toJSONString() compatibility |
|
423 |
var uls = menus[i].getElementsByTagName('ul'); |
|
424 |
if ( uls.length > 0 ) |
|
425 |
{ |
|
426 |
for ( var j = 0; j < uls.length; j++ ) |
|
427 |
{ |
|
428 |
if ( !isOverObj(uls[j], false, e) ) |
|
429 |
{ |
|
420
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
394
diff
changeset
|
430 |
$dynano(uls[j].previousSibling).rmClass('liteselected'); |
1 | 431 |
//uls[j].style.display = 'none'; |
432 |
slideIn(uls[j]); |
|
433 |
} |
|
434 |
} |
|
435 |
} |
|
436 |
var uls = getElementsByClassName(menus[i], 'divs', 'submenu'); |
|
437 |
if ( uls.length > 0 ) |
|
438 |
{ |
|
439 |
for ( var j = 0; j < uls.length; j++ ) |
|
440 |
{ |
|
441 |
if ( !isOverObj(uls[j], false, e) ) |
|
442 |
{ |
|
420
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
394
diff
changeset
|
443 |
$dynano(uls[j].previousSibling).rmClass('liteselected'); |
1 | 444 |
//uls[j].style.display = 'none'; |
445 |
slideIn(uls[j]); |
|
446 |
} |
|
447 |
} |
|
448 |
} |
|
449 |
} |
|
450 |
} |
|
451 |
} |
|
452 |
||
453 |
document.onclick = jBoxGarbageCollection; |
|
454 |
||
455 |
var getElementsByClassName = function(parent, type, cls) { |
|
456 |
if(!type) |
|
457 |
type = '*'; |
|
458 |
ret = new Array(); |
|
865
7f8262b2004a
New template feature: template hooks (<!-- HOOK foo -->)
Dan
parents:
853
diff
changeset
|
459 |
if ( !parent ) |
7f8262b2004a
New template feature: template hooks (<!-- HOOK foo -->)
Dan
parents:
853
diff
changeset
|
460 |
return ret; |
1 | 461 |
el = parent.getElementsByTagName(type); |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
462 |
for ( var i = 0; i < el.length; i++ ) |
1 | 463 |
{ |
464 |
if ( typeof(el[i]) != 'object') |
|
465 |
continue; // toJSONString() compatibility |
|
466 |
if(el[i].className) |
|
467 |
{ |
|
468 |
if(el[i].className.indexOf(' ') > 0) |
|
469 |
{ |
|
470 |
classes = el[i].className.split(' '); |
|
471 |
} |
|
472 |
else |
|
473 |
{ |
|
474 |
classes = new Array(); |
|
475 |
classes.push(el[i].className); |
|
476 |
} |
|
477 |
if ( in_array(cls, classes) ) |
|
478 |
ret.push(el[i]); |
|
479 |
} |
|
480 |
} |
|
481 |
return ret; |
|
482 |
} |
|
483 |
||
484 |
document.getElementsByClassName = function(type, cls) { |
|
485 |
return getElementsByClassName(document, type, cls); |
|
486 |
} |
|
487 |
||
488 |
function setMousePos(event) |
|
489 |
{ |
|
490 |
if(IE) |
|
491 |
{ |
|
492 |
if(!event) |
|
493 |
{ |
|
494 |
event = window.event; |
|
495 |
} |
|
496 |
clX = event.clientX; |
|
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
parents:
57
diff
changeset
|
497 |
if ( document.body ) |
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
parents:
57
diff
changeset
|
498 |
sL = document.body.scrollLeft; |
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
parents:
57
diff
changeset
|
499 |
else |
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
parents:
57
diff
changeset
|
500 |
sL = 0; |
1 | 501 |
mouseX = clX + sL; |
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
parents:
57
diff
changeset
|
502 |
mouseY = event.clientY + ( document.body ? document.body.scrollTop : 0 ); |
1 | 503 |
return; |
504 |
} |
|
505 |
if( typeof(event.clientX) == 'number' ) |
|
506 |
{ |
|
507 |
mouseX = event.clientX; |
|
508 |
mouseY = event.clientY; |
|
509 |
return; |
|
510 |
} |
|
511 |
else if( typeof(event.layerX) == 'number' ) |
|
512 |
{ |
|
513 |
mouseX = event.layerX; |
|
514 |
mouseY = event.layerY; |
|
515 |
return; |
|
516 |
} |
|
517 |
else if( typeof(event.offsetX) == 'number' ) |
|
518 |
{ |
|
519 |
mouseX = event.offsetX; |
|
520 |
mouseY = event.offsetY; |
|
521 |
return; |
|
522 |
} |
|
523 |
else if( typeof(event.screenX) == 'number' ) |
|
524 |
{ |
|
525 |
mouseX = event.screenX; |
|
526 |
mouseY = event.screenY; |
|
527 |
return; |
|
528 |
} |
|
529 |
else if( typeof(event.x) == 'number' ) |
|
530 |
{ |
|
531 |
mouseX = event.x; |
|
532 |
mouseY = event.y; |
|
533 |
return; |
|
534 |
} |
|
535 |
} |
|
536 |
||
537 |
document.onmousemove = function(e) |
|
538 |
{ |
|
539 |
setMousePos(e); |
|
540 |
}; |
|
541 |
||
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
542 |
function removeTextNodes(obj) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
543 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
544 |
if(obj) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
545 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
546 |
if(typeof(obj.tagName) != 'string' || ( String(obj) == '[object Text]' && is_Safari ) ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
547 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
548 |
if ( ( obj.nodeType == 3 && obj.data.match(/^([\s]*)$/ig) ) ) // || ( typeof(obj.innerHTML) == undefined && is_Safari ) ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
549 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
550 |
obj.parentNode.removeChild(obj); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
551 |
return; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
552 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
553 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
554 |
if(obj.firstChild) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
555 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
556 |
for(var i = 0; i < obj.childNodes.length; i++) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
557 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
558 |
removeTextNodes(obj.childNodes[i]); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
559 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
560 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
561 |
} |
1 | 562 |
} |
563 |