Witam serdecznie.
Mam pewien problem związany z menu w JS, mianowicie. Podczas ładowania strony, moje menu od razu pojawia się rozwinięte (wszystkie zakładki które pojawiają się po najechaniu, tym razem tylko przy załadowaniu - są wysunięte), i aby je zwinąć, muszę na każdą najechać i od tego momentu działa normalnie, do czasu załadowania następnej strony. Nie chciałem zbytnio ingerować z kod samej funkcji, ale widzę że to nieuniknione. Nie mogę znaleźć elementu, który powoduje że onLoad = wyświetlaj wszystko rozwinięte a nie zwinięte. Oczywiście onLoad nie zostało wykorzystane w tej funkcji.

Poniżej kod:
  1. <script type="text/javascript">
  2. function Menu(id, style, otworz, wysun, czasRozwin, czasZwin, czasOtworz, czasZamknij, nieInicjalizuj)
  3. {
  4. if (typeof czasRozwin == 'undefined' || czasRozwin < 0) czasRozwin = 25;
  5. if (typeof czasZwin == 'undefined' || czasZwin < 0) czasZwin = 25;
  6. if (typeof czasOtworz == 'undefined' || czasOtworz < 0) czasOtworz = 250;
  7. if (typeof czasZamknij == 'undefined' || czasZamknij < 0) czasZamknij = 500;
  8. var url = unescape(window.location.href.replace(/#.*/, ''));
  9. var base = window.location.protocol + '//' + window.location.host + window.location.pathname.replace(/[^\/\\]+$/, '');
  10. if (style)
  11. {
  12. if (style.indexOf(':') < 0)
  13. {
  14. document.getElementById(id).className += ' ' + style;
  15. }
  16. else
  17. {
  18. style = style.replace(/(^\s+|(\s|;)+$)/g, '').split(/\s*;\s*/);
  19. for (var i = 0; i < style.length; i++)
  20. {
  21. style[i] = style[i].split(/\s*:\s*/);
  22. for (var j = 0, c, property = ''; j < style[i][0].length; j++)
  23. {
  24. c = style[i][0].charAt(j);
  25. property += c == '-' ? style[i][0].charAt(++j).toUpperCase() : c.toLowerCase();
  26. }
  27. eval('document.getElementById("' + id + '").style.' + property + ' = "' + style[i][1].replace(/"/g, '\\"') + '"');
  28. }
  29. }
  30. }
  31. for (var i = 0; i < document.getElementById(id).getElementsByTagName('dt').length; i++)
  32. {
  33. var dd = new Array();
  34. var el = document.getElementById(id).getElementsByTagName('dt')[i].nextSibling;
  35. var nodeName;
  36. while (el && (nodeName = el.nodeName.toLowerCase()) != 'dt')
  37. {
  38. if (nodeName == 'dd')
  39. {
  40. el._dt = document.getElementById(id).getElementsByTagName('dt')[i];
  41. if (otworz)
  42. {
  43. el.onmouseover = function()
  44. {
  45. clearTimeout(this._dt._timoutID);
  46. this._dt._displayed = false;
  47. this._dt.onclick();
  48. }
  49. el.onmouseout = function()
  50. {
  51. clearTimeout(this._dt._timoutID);
  52. var dt = this._dt;
  53. this._dt._timoutID = setTimeout(function () { dt._displayed = true; dt.onclick(); }, czasZamknij);
  54. };
  55. }
  56. dd[dd.length] = el;
  57. }
  58. el = el.nextSibling;
  59. }
  60. document.getElementById(id).getElementsByTagName('dt')[i]._dd = dd;
  61. document.getElementById(id).getElementsByTagName('dt')[i]._timoutID = null;
  62. document.getElementById(id).getElementsByTagName('dt')[i]._displayed = false;
  63. document.getElementById(id).getElementsByTagName('dt')[i].onclick = function()
  64. {
  65. clearTimeout(this._timoutID);
  66. if (!this._displayed)
  67. {
  68. var el = this.parentNode.getElementsByTagName('dt')[0];
  69. while (el)
  70. {
  71. if (el.nodeName.toLowerCase() == 'dt' && el != this)
  72. {
  73. el._displayed = false;
  74. if (czasZwin) display(el, 0);
  75. else display(el);
  76. }
  77. el = el.nextSibling;
  78. }
  79. }
  80. this._displayed = !this._displayed;
  81. if (this._displayed && czasRozwin || !this._displayed && czasZwin) display(this, 0);
  82. else display(this);
  83. };
  84. if (otworz)
  85. {
  86. document.getElementById(id).getElementsByTagName('dt')[i].onmouseover = function()
  87. {
  88. clearTimeout(this._timoutID);
  89. var dt = this;
  90. this._timoutID = setTimeout(function () { dt._displayed = false; dt.onclick(); }, czasOtworz);
  91. };
  92. document.getElementById(id).getElementsByTagName('dt')[i].onmouseout = function()
  93. {
  94. clearTimeout(this._timoutID);
  95. var dt = this;
  96. this._timoutID = setTimeout(function () { dt._displayed = true; dt.onclick(); }, czasZamknij);
  97. };
  98. }
  99. }
  100. start(document.getElementById(id).getElementsByTagName('dt')[0]);
  101. function start(dt)
  102. {
  103. var hide = true;
  104. var el = dt;
  105. while (el)
  106. {
  107. var nodeName = el.nodeName.toLowerCase();
  108. if (nodeName == 'dt')
  109. {
  110. dt = el;
  111. hide = true;
  112. }
  113. if (nodeName == 'dt' || nodeName == 'dd')
  114. {
  115. if (!nieInicjalizuj && el.getElementsByTagName('a').length)
  116. {
  117. var active = el.getElementsByTagName('a')[0].href && unescape(el.getElementsByTagName('a')[0].href.replace(/#.*/, '')) == url;
  118. if (!active)
  119. {
  120. var rel = el.getElementsByTagName('a')[0].getAttribute('rel');
  121. if (rel)
  122. {
  123. var matches = (' ' + rel + ' ').match(/\s+Collection\(([^)]+)\)\s+/i);
  124. if (matches)
  125. {
  126. matches = matches[1].split(',');
  127. for (var k = 0, pos = -1; k < matches.length; k++)
  128. {
  129. if (matches[k].charAt(0) == '[' && (pos = matches[k].lastIndexOf(']')) > 0)
  130. {
  131. if (new RegExp(unescape(matches[k].substring(1, pos)), matches[k].substring(pos + 1)).test(url))
  132. {
  133. active = true;
  134. break;
  135. }
  136. }
  137. else
  138. {
  139. if (/^[\/\\]/.test(matches[k])) matches[k] = window.location.protocol + '//' + window.location.host + matches[k];
  140. else if (!/^[a-z0-9]+:/i.test(matches[k])) matches[k] = base + matches[k];
  141. if (unescape(matches[k].replace(/[\/\\]\.([\/\\])/g, '$1').replace(/[^\/\\]+[\/\\]\.\.[\/\\]/g, '').replace(/#.*/, '')) == url)
  142. {
  143. active = true;
  144. break;
  145. }
  146. }
  147. }
  148. }
  149. }
  150. }
  151. if (active)
  152. {
  153. el.className = (el.className ? el.className + ' ' : '') + 'active';
  154. dt._displayed = true;
  155. display(dt);
  156. hide = false;
  157. var el_parentNode = el.parentNode;
  158. while (el_parentNode != document.getElementById(id))
  159. {
  160. if (el_parentNode.nodeName.toLowerCase() == 'dd')
  161. {
  162. var el_sibling = el_parentNode.previousSibling;
  163. while (el_sibling)
  164. {
  165. if (el_sibling.nodeName.toLowerCase() == 'dt')
  166. {
  167. el_sibling._displayed = true;
  168. display(el_sibling)
  169. break;
  170. }
  171. el_sibling = el_sibling.previousSibling;
  172. }
  173. }
  174. el_parentNode = el_parentNode.parentNode;
  175. }
  176. }
  177. }
  178. }
  179. if (nodeName == 'dd')
  180. {
  181. if (hide) el.style.display = 'none';
  182. start(el.getElementsByTagName('dt')[0]);
  183. }
  184. el = el.nextSibling;
  185. }
  186. }
  187. function display(dt, i)
  188. {
  189. if (typeof i == 'undefined')
  190. {
  191. for (var i = 0; i < dt._dd.length; i++)
  192. {
  193. dt._dd[i].style.display = dt._displayed ? 'block' : 'none';
  194. if (!dt._displayed)
  195. {
  196. for (var j = 0; j < dt._dd[i].getElementsByTagName('dt').length; j++)
  197. {
  198. dt._dd[i].getElementsByTagName('dt')[j]._displayed = false;
  199. display(dt._dd[i].getElementsByTagName('dt')[j]);
  200. }
  201. }
  202. }
  203. }
  204. else if (i < dt._dd.length)
  205. {
  206. var dir = wysun ? !dt._displayed : dt._displayed;
  207. var n = dir ? i : dt._dd.length - 1 - i;
  208. dt._dd[n].style.display = dt._displayed ? 'block' : 'none';
  209. if (!dt._displayed)
  210. {
  211. for (var j = 0; j < dt._dd[n].getElementsByTagName('dt').length; j++)
  212. {
  213. dt._dd[n].getElementsByTagName('dt')[j]._displayed = false;
  214. display(dt._dd[n].getElementsByTagName('dt')[j]);
  215. }
  216. }
  217. dt._timoutID = setTimeout(function() { display(dt, i + 1); }, dt._displayed ? czasRozwin : czasZwin);
  218. }
  219. }
  220. }
  221. </script>


A oto jej wywołanie w kodzie:

  1. <script type="text/javascript">
  2. new Menu('menu8', 'menu8', true, false, 0, 0, 0, 0, false);
  3. </script>


Bardzo proszę o pomoc bo męczę się z tym już spory czas, a może szanowni Koledzy i Koleżanki będą w stanie szybciej mi pomóc.