author | Dan |
Sat, 14 Mar 2009 14:06:02 -0400 | |
changeset 857 | f3a5a276208c |
parent 853 | 21fea79d9de4 |
child 865 | 7f8262b2004a |
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(); |
|
459 |
el = parent.getElementsByTagName(type); |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
22
diff
changeset
|
460 |
for ( var i = 0; i < el.length; i++ ) |
1 | 461 |
{ |
462 |
if ( typeof(el[i]) != 'object') |
|
463 |
continue; // toJSONString() compatibility |
|
464 |
if(el[i].className) |
|
465 |
{ |
|
466 |
if(el[i].className.indexOf(' ') > 0) |
|
467 |
{ |
|
468 |
classes = el[i].className.split(' '); |
|
469 |
} |
|
470 |
else |
|
471 |
{ |
|
472 |
classes = new Array(); |
|
473 |
classes.push(el[i].className); |
|
474 |
} |
|
475 |
if ( in_array(cls, classes) ) |
|
476 |
ret.push(el[i]); |
|
477 |
} |
|
478 |
} |
|
479 |
return ret; |
|
480 |
} |
|
481 |
||
482 |
document.getElementsByClassName = function(type, cls) { |
|
483 |
return getElementsByClassName(document, type, cls); |
|
484 |
} |
|
485 |
||
486 |
function setMousePos(event) |
|
487 |
{ |
|
488 |
if(IE) |
|
489 |
{ |
|
490 |
if(!event) |
|
491 |
{ |
|
492 |
event = window.event; |
|
493 |
} |
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
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
|
498 |
sL = 0; |
1 | 499 |
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
|
500 |
mouseY = event.clientY + ( document.body ? document.body.scrollTop : 0 ); |
1 | 501 |
return; |
502 |
} |
|
503 |
if( typeof(event.clientX) == 'number' ) |
|
504 |
{ |
|
505 |
mouseX = event.clientX; |
|
506 |
mouseY = event.clientY; |
|
507 |
return; |
|
508 |
} |
|
509 |
else if( typeof(event.layerX) == 'number' ) |
|
510 |
{ |
|
511 |
mouseX = event.layerX; |
|
512 |
mouseY = event.layerY; |
|
513 |
return; |
|
514 |
} |
|
515 |
else if( typeof(event.offsetX) == 'number' ) |
|
516 |
{ |
|
517 |
mouseX = event.offsetX; |
|
518 |
mouseY = event.offsetY; |
|
519 |
return; |
|
520 |
} |
|
521 |
else if( typeof(event.screenX) == 'number' ) |
|
522 |
{ |
|
523 |
mouseX = event.screenX; |
|
524 |
mouseY = event.screenY; |
|
525 |
return; |
|
526 |
} |
|
527 |
else if( typeof(event.x) == 'number' ) |
|
528 |
{ |
|
529 |
mouseX = event.x; |
|
530 |
mouseY = event.y; |
|
531 |
return; |
|
532 |
} |
|
533 |
} |
|
534 |
||
535 |
document.onmousemove = function(e) |
|
536 |
{ |
|
537 |
setMousePos(e); |
|
538 |
}; |
|
539 |
||
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
540 |
function removeTextNodes(obj) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
541 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
542 |
if(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(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
|
545 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
546 |
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
|
547 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
548 |
obj.parentNode.removeChild(obj); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
549 |
return; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
550 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
551 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
552 |
if(obj.firstChild) |
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 |
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
|
555 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
556 |
removeTextNodes(obj.childNodes[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 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
523
diff
changeset
|
559 |
} |
1 | 560 |
} |
561 |