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