layersmenu.js 6.8 KB

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