author | Dan |
Thu, 05 Jul 2007 10:43:03 -0400 | |
changeset 43 | 30d2fb25afff |
parent 40 | 723bb7acf914 |
child 57 | b354deeaa4c4 |
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 |
} |
|
39 |
||
40 |
// Initializes each menu. |
|
41 |
function jBoxBatchSetup() |
|
42 |
{ |
|
43 |
var menus = document.getElementsByClassName('div', 'menu_nojs'); |
|
44 |
if ( menus.length > 0 ) |
|
45 |
{ |
|
46 |
for ( var i in menus ) |
|
47 |
{ |
|
48 |
if ( typeof(menus[i]) != 'object') |
|
49 |
continue; // toJSONString() compatibility |
|
50 |
jBoxSetup(menus[i]); |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
||
55 |
// Initializes a div with a jBox menu in it. |
|
56 |
function jBoxSetup(obj) |
|
57 |
{ |
|
58 |
$(obj).addClass('menu'); |
|
59 |
removeTextNodes(obj); |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
60 |
|
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
61 |
for ( var i = 0; i < obj.childNodes.length; i++ ) |
1 | 62 |
{ |
63 |
/* normally this would be done in about 2 lines of code, but javascript is so picky..... */ |
|
64 |
if ( obj.childNodes[i] ) |
|
65 |
{ |
|
66 |
if ( obj.childNodes[i].tagName ) |
|
67 |
{ |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
68 |
if ( obj.childNodes[i].tagName == 'A' ) |
1 | 69 |
{ |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
70 |
// 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
|
71 |
if ( obj.childNodes[i].nextSibling ) |
1 | 72 |
{ |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
73 |
// 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
|
74 |
if ( obj.childNodes[i].nextSibling.tagName ) |
1 | 75 |
{ |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
76 |
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
|
77 |
{ |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
78 |
// Calculate height |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
79 |
var ul = obj.childNodes[i].nextSibling; |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
80 |
domObjChangeOpac(0, ul); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
81 |
ul.style.display = 'block'; |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
82 |
var dim = fetch_dimensions(ul); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
83 |
if ( !ul.id ) |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
84 |
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
|
85 |
jBoxMenuHeights[ul.id] = parseInt(dim['h']) - 2; // subtract 2px for border width |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
86 |
ul.style.display = 'none'; |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
87 |
domObjChangeOpac(100, ul); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
88 |
|
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
89 |
// Setup events |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
obj.childNodes[i].nextSibling.onmouseout = function(e) { jBoxOutHandler(this, e); }; |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
93 |
} |
1 | 94 |
} |
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
// Called when user hovers mouse over a submenu |
|
103 |
function jBoxOverHandler(obj) |
|
104 |
{ |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
105 |
// if ( is_Safari ) |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
106 |
// alert('Safari and over'); |
1 | 107 |
// Random ID used to track the object to perform on |
108 |
var seed = Math.floor(Math.random() * 1000000); |
|
109 |
jBoxObjCache[seed] = obj; |
|
110 |
||
111 |
// Sleep for a (little more than a tenth of a) second to see if the user really wants the menu to expand |
|
112 |
setTimeout('if(isOverObj(jBoxObjCache['+seed+'], false, false)) jBoxOverHandlerBin(jBoxObjCache['+seed+']);', 150); |
|
113 |
} |
|
114 |
||
115 |
// Displays a menu. |
|
116 |
function jBoxOverHandlerBin(obj) |
|
117 |
{ |
|
118 |
var others = obj.parentNode.getElementsByTagName('ul'); |
|
119 |
for ( var i in others ) |
|
120 |
{ |
|
121 |
if(typeof(others[i]) == 'object') |
|
122 |
{ |
|
123 |
others[i].style.display = 'none'; |
|
124 |
others[i].previousSibling.className = ''; |
|
125 |
} |
|
126 |
} |
|
127 |
var others = obj.parentNode.getElementsByTagName('div'); |
|
128 |
for ( var i in others ) |
|
129 |
{ |
|
130 |
if(typeof(others[i]) == 'object') |
|
131 |
{ |
|
132 |
if ( others[i].className == 'submenu' ) |
|
133 |
{ |
|
134 |
others[i].style.display = 'none'; |
|
135 |
others[i].previousSibling.className = ''; |
|
136 |
} |
|
137 |
} |
|
138 |
} |
|
139 |
if(obj.nextSibling.tagName.toLowerCase() == 'ul' || ( obj.nextSibling.tagName.toLowerCase() == 'div' && obj.nextSibling.className == 'submenu' )) |
|
140 |
{ |
|
141 |
obj.className = 'liteselected'; |
|
142 |
var ul = obj.nextSibling; |
|
143 |
var dim = fetch_dimensions(obj); |
|
144 |
var off = fetch_offset(obj); |
|
145 |
var dimh = parseInt(dim['h']); |
|
146 |
var offtop = parseInt(off['top']); |
|
147 |
var top = dimh + offtop; |
|
148 |
left = off['left']; |
|
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
|
149 |
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
|
150 |
{ |
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
|
151 |
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
|
152 |
} |
1 | 153 |
ul.style.left = left + 'px'; |
154 |
ul.style.top = top + 'px'; |
|
155 |
ul.style.clip = 'rect(auto,auto,auto,auto)'; |
|
156 |
ul.style.overflow = 'visible'; |
|
157 |
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
|
158 |
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
|
159 |
{ |
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
|
160 |
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
|
161 |
} |
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
|
162 |
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
|
163 |
{ |
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
|
164 |
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
|
165 |
} |
1 | 166 |
} |
167 |
} |
|
168 |
||
169 |
function jBoxOutHandler(obj, event) |
|
170 |
{ |
|
171 |
var seed = Math.floor(Math.random() * 1000000); |
|
172 |
var seed2 = Math.floor(Math.random() * 1000000); |
|
173 |
jBoxObjCache[seed] = obj; |
|
174 |
jBoxObjCache[seed2] = event; |
|
175 |
setTimeout('jBoxOutHandlerBin(jBoxObjCache['+seed+'], jBoxObjCache['+seed2+']);', 750); |
|
176 |
} |
|
177 |
||
178 |
function jBoxOutHandlerBin(obj, event) |
|
179 |
{ |
|
180 |
var caller = obj.tagName.toLowerCase(); |
|
181 |
if(caller == 'a') |
|
182 |
{ |
|
183 |
a = obj; |
|
184 |
ul = obj.nextSibling; |
|
185 |
} |
|
186 |
else if(caller == 'ul' || caller == 'div') |
|
187 |
{ |
|
188 |
a = obj.previousSibling; |
|
189 |
ul = obj; |
|
190 |
} |
|
191 |
else |
|
192 |
{ |
|
193 |
return false; |
|
194 |
} |
|
195 |
||
196 |
if (!isOverObj(a, false, event) && !isOverObj(ul, true, event)) |
|
197 |
{ |
|
198 |
a.className = ''; |
|
199 |
||
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
200 |
if ( jBox_slide_enable ) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
201 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
202 |
slideIn(ul); |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
203 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
204 |
else |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
205 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
206 |
ul.style.display = 'none'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
207 |
} |
1 | 208 |
|
209 |
} |
|
210 |
||
211 |
return true; |
|
212 |
} |
|
213 |
||
214 |
// Slide an element downwards until it is at full height. |
|
215 |
// First parameter should be a DOM object with style.display = block and opacity = 0. |
|
216 |
||
217 |
var sliderobj = new Object(); |
|
218 |
||
219 |
function slideOut(obj) |
|
220 |
{ |
|
221 |
if ( jBoxSlideBlocker[obj.id] ) |
|
222 |
return false; |
|
223 |
||
224 |
jBoxSlideBlocker[obj.id] = true; |
|
225 |
||
226 |
if ( slide_speed == -1 ) |
|
227 |
{ |
|
228 |
obj.style.display = 'block'; |
|
229 |
return false; |
|
230 |
} |
|
231 |
||
232 |
var currentheight = 0; |
|
233 |
var targetheight = jBoxMenuHeights[obj.id]; |
|
234 |
var inertiabase = inertia_base; |
|
235 |
var inertiainc = inertia_inc; |
|
236 |
slideStep(obj, 0); |
|
237 |
domObjChangeOpac(100, obj); |
|
238 |
obj.style.overflow = 'hidden'; |
|
239 |
||
240 |
// Don't edit past here |
|
241 |
var timercnt = 0; |
|
242 |
||
243 |
var seed = Math.floor(Math.random() * 1000000); |
|
244 |
sliderobj[seed] = obj; |
|
245 |
||
246 |
var framecnt = 0; |
|
247 |
||
248 |
while(true) |
|
249 |
{ |
|
250 |
framecnt++; |
|
251 |
timercnt += ( 100 - slide_speed ); |
|
252 |
inertiabase += inertiainc; |
|
253 |
currentheight += inertiabase; |
|
254 |
if ( currentheight > targetheight ) |
|
255 |
currentheight = targetheight; |
|
256 |
setTimeout('slideStep(sliderobj['+seed+'], '+currentheight+', '+targetheight+');', timercnt); |
|
257 |
if ( currentheight >= targetheight ) |
|
258 |
break; |
|
259 |
} |
|
260 |
timercnt = timercnt + ( 100 - slide_speed ); |
|
261 |
setTimeout('jBoxSlideBlocker[sliderobj['+seed+'].id] = false;', timercnt); |
|
262 |
var opacstep = jBox_opacity / framecnt; |
|
263 |
var opac = 0; |
|
264 |
var timerstep = 0; |
|
265 |
domObjChangeOpac(0, obj); |
|
266 |
while(true) |
|
267 |
{ |
|
268 |
timerstep += ( 100 - slide_speed ); |
|
269 |
opac += opacstep; |
|
270 |
setTimeout('domObjChangeOpac('+opac+', sliderobj['+seed+']);', timerstep); |
|
271 |
if ( opac >= jBox_opacity ) |
|
272 |
break; |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
function slideIn(obj) |
|
277 |
{ |
|
278 |
if ( obj.style.display != 'block' ) |
|
279 |
return false; |
|
280 |
||
281 |
if ( jBoxSlideBlocker[obj.id] ) |
|
282 |
return false; |
|
283 |
||
284 |
jBoxSlideBlocker[obj.id] = true; |
|
285 |
||
286 |
var targetheight = 0; |
|
287 |
var dim = fetch_dimensions(obj); |
|
288 |
var currentheight = jBoxMenuHeights[obj.id]; |
|
289 |
var origheight = currentheight; |
|
290 |
var inertiabase = inertia_base; |
|
291 |
var inertiainc = inertia_inc; |
|
292 |
domObjChangeOpac(100, obj); |
|
293 |
obj.style.overflow = 'hidden'; |
|
294 |
||
295 |
// Don't edit past here |
|
296 |
var timercnt = 0; |
|
297 |
||
298 |
var seed = Math.floor(Math.random() * 1000000); |
|
299 |
sliderobj[seed] = obj; |
|
300 |
||
301 |
var framecnt = 0; |
|
302 |
||
303 |
for(var j = 0;j<100;j++) // while(true) |
|
304 |
{ |
|
305 |
framecnt++; |
|
306 |
timercnt = timercnt + ( 100 - slide_speed ); |
|
307 |
inertiabase = inertiabase + inertiainc; |
|
308 |
currentheight = currentheight - inertiabase; |
|
309 |
if ( currentheight < targetheight ) |
|
310 |
currentheight = targetheight; |
|
311 |
setTimeout('slideStep(sliderobj['+seed+'], '+currentheight+');', timercnt); |
|
312 |
if ( currentheight <= targetheight ) |
|
313 |
break; |
|
314 |
} |
|
315 |
timercnt += ( 100 - slide_speed ); |
|
316 |
setTimeout('sliderobj['+seed+'].style.display="none";sliderobj['+seed+'].style.height="'+origheight+'px";jBoxSlideBlocker[sliderobj['+seed+'].id] = false;', timercnt); |
|
317 |
||
318 |
var opacstep = jBox_opacity / framecnt; |
|
319 |
var opac = jBox_opacity; |
|
320 |
var timerstep = 0; |
|
321 |
domObjChangeOpac(100, obj); |
|
322 |
while(true) |
|
323 |
{ |
|
324 |
timerstep += ( 100 - slide_speed ); |
|
325 |
opac -= opacstep; |
|
326 |
setTimeout('domObjChangeOpac('+opac+', sliderobj['+seed+']);', timerstep); |
|
327 |
if ( opac <= 0 ) |
|
328 |
break; |
|
329 |
} |
|
330 |
||
331 |
} |
|
332 |
||
333 |
function slideStep(obj, height, maxheight) |
|
334 |
{ |
|
335 |
obj.style.height = height + 'px'; |
|
336 |
//obj.style.clip = 'rect(3px,auto,'+maxheight+'px,auto)'; |
|
337 |
obj.style.overflow = 'hidden'; |
|
338 |
//obj.style.clip = 'rect('+height+'px,0px,'+maxheight+'px,auto);'; |
|
339 |
} |
|
340 |
||
341 |
function isOverObj(obj, bias, event) |
|
342 |
{ |
|
343 |
var fieldUL = new Object(); |
|
344 |
var dim = fetch_dimensions(obj); |
|
345 |
var off = fetch_offset(obj); |
|
346 |
fieldUL['top'] = off['top']; |
|
347 |
fieldUL['left'] = off['left']; |
|
348 |
fieldUL['right'] = off['left'] + dim['w']; |
|
349 |
fieldUL['bottom'] = off['top'] + dim['h']; |
|
350 |
||
351 |
//document.getElementById('debug').innerHTML = '<br /><br /><br /><br /><br />Mouse: x: '+mouseX+', y:' + mouseY + '<br />'; // + document.getElementById('debug').innerHTML; |
|
352 |
||
353 |
if(bias) |
|
354 |
{ |
|
355 |
if ( ( mouseX < fieldUL['left'] + 2 || mouseX > fieldUL['right'] - 5 ) || |
|
356 |
( mouseY < fieldUL['top'] - 2 || mouseY > fieldUL['bottom'] - 2 ) ) |
|
357 |
{ |
|
358 |
return false; |
|
359 |
} |
|
360 |
} |
|
361 |
else |
|
362 |
{ |
|
363 |
if ( ( mouseX < fieldUL['left'] || mouseX > fieldUL['right'] ) || |
|
364 |
( mouseY < fieldUL['top'] || mouseY > fieldUL['bottom'] ) ) |
|
365 |
return false; |
|
366 |
} |
|
367 |
||
368 |
return true; |
|
369 |
||
370 |
/* |
|
371 |
var tgt = event.target; |
|
372 |
if ( !tgt ) |
|
373 |
return false; |
|
374 |
do { |
|
375 |
if ( tgt == obj ) |
|
376 |
return true; |
|
377 |
tgt = tgt.parentNode; |
|
378 |
} while (tgt.tagName.toLowerCase() != 'body' ); |
|
379 |
return false; |
|
380 |
*/ |
|
381 |
} |
|
382 |
||
383 |
function jBoxGarbageCollection(e) |
|
384 |
{ |
|
385 |
setMousePos(e); |
|
386 |
var menus = document.getElementsByClassName('div', 'menu'); |
|
387 |
if ( menus.length > 0 ) |
|
388 |
{ |
|
389 |
for ( var i in menus ) |
|
390 |
{ |
|
391 |
if ( typeof(menus[i]) != 'object') |
|
392 |
continue; // toJSONString() compatibility |
|
393 |
var uls = menus[i].getElementsByTagName('ul'); |
|
394 |
if ( uls.length > 0 ) |
|
395 |
{ |
|
396 |
for ( var j = 0; j < uls.length; j++ ) |
|
397 |
{ |
|
398 |
if ( !isOverObj(uls[j], false, e) ) |
|
399 |
{ |
|
400 |
uls[j].previousSibling.className = ''; |
|
401 |
//uls[j].style.display = 'none'; |
|
402 |
slideIn(uls[j]); |
|
403 |
} |
|
404 |
} |
|
405 |
} |
|
406 |
var uls = getElementsByClassName(menus[i], 'divs', 'submenu'); |
|
407 |
if ( uls.length > 0 ) |
|
408 |
{ |
|
409 |
for ( var j = 0; j < uls.length; j++ ) |
|
410 |
{ |
|
411 |
if ( !isOverObj(uls[j], false, e) ) |
|
412 |
{ |
|
413 |
uls[j].previousSibling.className = ''; |
|
414 |
//uls[j].style.display = 'none'; |
|
415 |
slideIn(uls[j]); |
|
416 |
} |
|
417 |
} |
|
418 |
} |
|
419 |
} |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
document.onclick = jBoxGarbageCollection; |
|
424 |
||
425 |
function removeTextNodes(obj) |
|
426 |
{ |
|
427 |
if(obj) |
|
428 |
{ |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
429 |
if(typeof(obj.tagName) != 'string' || ( String(obj) == '[object Text]' && is_Safari ) ) |
1 | 430 |
{ |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
431 |
if ( ( obj.nodeType == 3 && obj.data.match(/^([\s]*)$/ig) ) ) // || ( typeof(obj.innerHTML) == undefined && is_Safari ) ) |
1 | 432 |
{ |
433 |
obj.parentNode.removeChild(obj); |
|
434 |
return; |
|
435 |
} |
|
436 |
} |
|
437 |
if(obj.firstChild) |
|
438 |
{ |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
439 |
for(var i = 0; i < obj.childNodes.length; i++) |
1 | 440 |
{ |
441 |
removeTextNodes(obj.childNodes[i]); |
|
442 |
} |
|
443 |
} |
|
444 |
} |
|
445 |
} |
|
446 |
||
447 |
var getElementsByClassName = function(parent, type, cls) { |
|
448 |
if(!type) |
|
449 |
type = '*'; |
|
450 |
ret = new Array(); |
|
451 |
el = parent.getElementsByTagName(type); |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
452 |
for ( var i = 0; i < el.length; i++ ) |
1 | 453 |
{ |
454 |
if ( typeof(el[i]) != 'object') |
|
455 |
continue; // toJSONString() compatibility |
|
456 |
if(el[i].className) |
|
457 |
{ |
|
458 |
if(el[i].className.indexOf(' ') > 0) |
|
459 |
{ |
|
460 |
classes = el[i].className.split(' '); |
|
461 |
} |
|
462 |
else |
|
463 |
{ |
|
464 |
classes = new Array(); |
|
465 |
classes.push(el[i].className); |
|
466 |
} |
|
467 |
if ( in_array(cls, classes) ) |
|
468 |
ret.push(el[i]); |
|
469 |
} |
|
470 |
} |
|
471 |
return ret; |
|
472 |
} |
|
473 |
||
474 |
document.getElementsByClassName = function(type, cls) { |
|
475 |
return getElementsByClassName(document, type, cls); |
|
476 |
} |
|
477 |
||
478 |
function setMousePos(event) |
|
479 |
{ |
|
480 |
if(IE) |
|
481 |
{ |
|
482 |
if(!event) |
|
483 |
{ |
|
484 |
event = window.event; |
|
485 |
} |
|
486 |
clX = event.clientX; |
|
487 |
sL = document.body.scrollLeft; |
|
488 |
mouseX = clX + sL; |
|
489 |
mouseY = event.clientY + document.body.scrollTop; |
|
490 |
return; |
|
491 |
} |
|
492 |
if( typeof(event.clientX) == 'number' ) |
|
493 |
{ |
|
494 |
mouseX = event.clientX; |
|
495 |
mouseY = event.clientY; |
|
496 |
return; |
|
497 |
} |
|
498 |
else if( typeof(event.layerX) == 'number' ) |
|
499 |
{ |
|
500 |
mouseX = event.layerX; |
|
501 |
mouseY = event.layerY; |
|
502 |
return; |
|
503 |
} |
|
504 |
else if( typeof(event.offsetX) == 'number' ) |
|
505 |
{ |
|
506 |
mouseX = event.offsetX; |
|
507 |
mouseY = event.offsetY; |
|
508 |
return; |
|
509 |
} |
|
510 |
else if( typeof(event.screenX) == 'number' ) |
|
511 |
{ |
|
512 |
mouseX = event.screenX; |
|
513 |
mouseY = event.screenY; |
|
514 |
return; |
|
515 |
} |
|
516 |
else if( typeof(event.x) == 'number' ) |
|
517 |
{ |
|
518 |
mouseX = event.x; |
|
519 |
mouseY = event.y; |
|
520 |
return; |
|
521 |
} |
|
522 |
} |
|
523 |
||
524 |
document.onmousemove = function(e) |
|
525 |
{ |
|
526 |
setMousePos(e); |
|
527 |
}; |
|
528 |
||
529 |
function domObjChangeOpac(opacity, id) { |
|
530 |
var object = id.style; |
|
531 |
object.opacity = (opacity / 100); |
|
532 |
object.MozOpacity = (opacity / 100); |
|
533 |
object.KhtmlOpacity = (opacity / 100); |
|
534 |
object.filter = "alpha(opacity=" + opacity + ")"; |
|
535 |
} |
|
536 |