1 // PHP Layers Menu 3.2.0-rc (C) 2001-2004 Marco Pratesi - http://www.marcopratesi.it/
3 useTimeouts = 1;
4 timeoutLength = 1000; // time in ms; not significant if useTimeouts = 0;
5 shutdownOnClick = 0;
8 loaded = 0;
9 layersMoved = 0;
10 layerPoppedUp = '';
12 timeoutFlag = 0;
13 if (Opera56 || IE4) {
14 useTimeouts = 0;
15 }
16 if (NS4 || Opera56 || IE4) {
17 shutdownOnClick = 1;
18 }
20 currentY = 0;
21 function grabMouse(e) // for NS4
22 {
23 currentY = e.pageY;
24 }
25 if (NS4) {
26 document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE);
27 document.onmousemove = grabMouse;
28 }
30 function seeThroughElements(show)
31 {
32 if (show) {
33 foobar = 'visible';
34 } else {
35 foobar = 'hidden';
36 }
37 for (i=0; i<toBeHidden.length; i++) {
38 toBeHidden[i].style.visibility = foobar;
39 }
40 }
42 function shutdown()
43 {
44 for (i=0; i<numl; i++) {
45 LMPopUpL(listl[i], false);
46 }
47 layerPoppedUp = '';
48 if (Konqueror || IE5) {
49 seeThroughElements(true);
50 }
51 }
52 if (shutdownOnClick) {
53 if (NS4) {
54 document.onmousedown = shutdown;
55 } else {
56 document.onclick = shutdown;
57 }
58 }
60 function setLMTO()
61 {
62 if (useTimeouts) {
63 timeoutFlag = setTimeout('shutdown()', timeoutLength);
64 }
65 }
67 function clearLMTO()
68 {
69 if (useTimeouts) {
70 clearTimeout(timeoutFlag);
71 }
72 }
74 function moveLayerX(menuName)
75 {
76 if (!loaded || (isVisible(menuName) && menuName != layerPoppedUp)) {
77 return;
78 }
79 if (father[menuName] != '') {
80 if (!Opera5 && !IE4) {
81 width0 = lwidth[father[menuName]];
82 width1 = lwidth[menuName];
83 } else if (Opera5) {
84 // Opera 5 stupidly and exaggeratedly overestimates layers widths
85 // hence we consider a default value equal to $abscissaStep
86 width0 = abscissaStep;
87 width1 = abscissaStep;
88 } else if (IE4) {
89 width0 = getOffsetWidth(father[menuName]);
90 width1 = getOffsetWidth(menuName);
91 }
92 onLeft = getOffsetLeft(father[menuName]) - width1 + menuLeftShift;
93 onRight = getOffsetLeft(father[menuName]) + width0 - menuRightShift;
94 windowWidth = getWindowWidth();
95 windowXOffset = getWindowXOffset();
96 // if (NS4 && !DOM) {
97 // windowXOffset = 0;
98 // }
99 if (onLeft < windowXOffset && onRight + width1 > windowWidth + windowXOffset) {
100 if (onRight + width1 - windowWidth - windowXOffset > windowXOffset - onLeft) {
101 onLeft = windowXOffset;
102 } else {
103 onRight = windowWidth + windowXOffset - width1;
104 }
105 }
106 if (back[father[menuName]]) {
107 if (onLeft < windowXOffset) {
108 back[menuName] = 0;
109 } else {
110 back[menuName] = 1;
111 }
112 } else {
113 //alert(onRight + ' - ' + width1 + ' - ' + windowWidth + ' - ' + windowXOffset);
114 if (onRight + width1 > windowWidth + windowXOffset) {
115 back[menuName] = 1;
116 } else {
117 back[menuName] = 0;
118 }
119 }
120 if (back[menuName]) {
121 setLeft(menuName, onLeft);
122 } else {
123 setLeft(menuName, onRight);
124 }
125 }
126 moveLayerY(menuName); // workaround needed for Mozilla < 1.4 for MS Windows
127 }
129 function moveLayerY(menuName)
130 {
131 if (!loaded || (isVisible(menuName) && menuName != layerPoppedUp)) {
132 return;
133 }
134 if (!layersMoved) {
135 moveLayers();
136 layersMoved = 1;
137 }
138 if (!NS4) {
139 newY = getOffsetTop('ref' + menuName);
140 } else {
141 newY = currentY;
142 }
143 newY += menuTopShift;
144 layerHeight = getOffsetHeight(menuName);
145 windowHeight = getWindowHeight();
146 windowYOffset = getWindowYOffset();
147 if (newY + layerHeight > windowHeight + windowYOffset) {
148 if (layerHeight > windowHeight) {
149 newY = windowYOffset;
150 } else {
151 newY = windowHeight + windowYOffset - layerHeight;
152 }
153 }
154 if (Math.abs(getOffsetTop(menuName) - newY) > thresholdY) {
155 setTop(menuName, newY);
156 }
157 }
159 function moveLayerX1(menuName, father)
160 {
161 if (!lwidthDetected) {
162 return;
163 }
164 if (!Opera5 && !IE4) {
165 width1 = lwidth[menuName];
166 } else if (Opera5) {
167 // Opera 5 stupidly and exaggeratedly overestimates layers widths
168 // hence we consider a default value equal to $abscissaStep
169 width1 = abscissaStep;
170 }
171 foobar = getOffsetLeft(father + menuName);
172 if (!IE4) {
173 windowWidth = getWindowWidth();
174 windowXOffset = getWindowXOffset();
175 if (foobar + width1 > windowWidth + windowXOffset) {
176 foobar = windowWidth + windowXOffset - width1;
177 }
178 if (foobar < windowXOffset) {
179 foobar = windowXOffset;
180 }
181 }
182 setLeft(menuName, foobar);
183 }
185 function layersOverlap(layer, i)
186 {
187 if (Konqueror22) {
188 return true;
189 }
191 // xa1 = getOffsetLeft(layer);
192 //setLeft(layer, xa1);
193 xa1 = layerLeft[layer];
194 xa2 = xa1 + getOffsetWidth(layer);
195 //setWidth(layer, xa2-xa1);
196 // ya1 = getOffsetTop(layer);
197 //setTop(layer, ya1);
198 ya1 = layerTop[layer];
199 ya2 = ya1 + getOffsetHeight(layer);
200 //setHeight(layer, ya2-ya1);
201 //alert(':' + xa1 + ':' + xa2 + ':' + ya1 + ':' + ya2 + ':');
203 xb1 = toBeHiddenLeft[i];
204 xb2 = xb1 + toBeHidden[i].offsetWidth;
205 yb1 = toBeHiddenTop[i];
206 yb2 = yb1 + toBeHidden[i].offsetHeight;
207 //alert(':' + xb1 + ':' + xb2 + ':' + yb1 + ':' + yb2 + ':');
209 if(xb1>xa1) xa1=xb1; if(xb2<xa2) xa2=xb2;
210 if(yb1>ya1) ya1=yb1; if(yb2<ya2) ya2=yb2;
212 return (xa2>xa1 && ya2>ya1);
213 }
215 function seeThroughWorkaround(menuName, on)
216 {
217 for (i=0; i<toBeHidden.length; i++) {
218 if (layersOverlap(menuName, i)) {
219 if (on) {
220 toBeHidden[i].style.visibility = 'hidden';
221 } else {
222 toBeHidden[i].style.visibility = 'visible';
223 }
224 }
225 }
226 }
228 function LMPopUpL(menuName, on)
229 {
230 if (!loaded) {
231 return;
232 }
233 if (!layersMoved) {
234 moveLayers();
235 layersMoved = 1;
236 }
237 setVisibility(menuName, on);
238 }
240 function LMPopUp(menuName, isCurrent)
241 {
242 if (!loaded || menuName == layerPoppedUp || (isVisible(menuName) && !isCurrent)) {
243 return;
244 }
245 if (menuName == father[layerPoppedUp]) {
246 LMPopUpL(layerPoppedUp, false);
247 // seeThroughWorkaround(menuName, false);
248 } else if (father[menuName] == layerPoppedUp) {
249 LMPopUpL(menuName, true);
250 seeThroughWorkaround(menuName, true);
251 } else {
252 shutdown();
253 foobar = menuName;
254 do {
255 LMPopUpL(foobar, true);
256 seeThroughWorkaround(foobar, true);
257 foobar = father[foobar];
258 } while (foobar != '')
259 }
260 /*
261 if (layerPoppedUp == '') {
262 seeThroughElements(false);
263 }
264 */
265 layerPoppedUp = menuName;
266 }
268 function resizeHandler()
269 {
270 if (NS4) {
271 window.location.reload();
272 }
273 shutdown();
274 for (i=0; i<numl; i++) {
275 setLeft(listl[i], 0);
276 setTop(listl[i], 0);
277 }
278 if (toBeHidden != null && toBeHidden.length > 0) {
279 seeThroughCoordinatesDetection();
280 }
281 // moveLayers();
282 layersMoved = 0;
283 }
284 window.onresize = resizeHandler;
286 function yaresizeHandler()
287 {
288 if (window.innerWidth != origWidth || window.innerHeight != origHeight) {
289 if (Konqueror22 || Opera5) {
290 window.location.reload(); // Opera 5 often fails this
291 }
292 origWidth = window.innerWidth;
293 origHeight = window.innerHeight;
294 resizeHandler();
295 }
296 setTimeout('yaresizeHandler()', 500);
297 }
298 function loadHandler()
299 {
300 if (Konqueror22 || Opera56) {
301 origWidth = window.innerWidth;
302 origHeight = window.innerHeight;
303 yaresizeHandler();
304 }
305 }
306 window.onload = loadHandler;
308 function fixieflm(menuName)
309 {
310 if (DOM) {
311 setWidth(menuName, '100%');
312 } else { // IE4 IS SIMPLY A BASTARD !!!
313 document.write('</div>');
314 document.write('<div id="IE4' + menuName + '" style="position: relative; width: 100%; visibility: visible;">');
315 }
316 }