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