JSCookMenu2.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. /*
  2. JSCookMenu v1.25. (c) Copyright 2002 by Heng Yuan
  3. Permission is hereby granted, free of charge, to any person obtaining a
  4. copy of this software and associated documentation files (the "Software"),
  5. to deal in the Software without restriction, including without limitation
  6. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7. and/or sell copies of the Software, and to permit persons to whom the
  8. Software is furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included
  10. in all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  12. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. ITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  16. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. DEALINGS IN THE SOFTWARE.
  18. */
  19. // Globals
  20. var _cmIDCount = 0;
  21. var _cmIDName = 'cmSubMenuID'; // for creating submenu id
  22. var _cmTimeOut = null; // how long the menu would stay
  23. var _cmCurrentItem = null; // the current menu item being selected;
  24. var _cmNoAction = new Object (); // indicate that the item cannot be hovered.
  25. var _cmSplit = new Object (); // indicate that the item is a menu split
  26. var _cmItemList = new Array (); // a simple list of items
  27. // default node properties
  28. var _cmNodeProperties =
  29. {
  30. // main menu display attributes
  31. //
  32. // Note. When the menu bar is horizontal,
  33. // mainFolderLeft and mainFolderRight are
  34. // put in <span></span>. When the menu
  35. // bar is vertical, they would be put in
  36. // a separate TD cell.
  37. // HTML code to the left of the folder item
  38. mainFolderLeft: '',
  39. // HTML code to the right of the folder item
  40. mainFolderRight: '',
  41. // HTML code to the left of the regular item
  42. mainItemLeft: '',
  43. // HTML code to the right of the regular item
  44. mainItemRight: '',
  45. // sub menu display attributes
  46. // HTML code to the left of the folder item
  47. folderLeft: '',
  48. // HTML code to the right of the folder item
  49. folderRight: '',
  50. // HTML code to the left of the regular item
  51. itemLeft: '',
  52. // HTML code to the right of the regular item
  53. itemRight: '',
  54. // cell spacing for main menu
  55. mainSpacing: 0,
  56. // cell spacing for sub menus
  57. subSpacing: 0,
  58. // auto dispear time for submenus in milli-seconds
  59. delay: 500
  60. };
  61. //////////////////////////////////////////////////////////////////////
  62. //
  63. // Drawing Functions and Utility Functions
  64. //
  65. //////////////////////////////////////////////////////////////////////
  66. //
  67. // produce a new unique id
  68. //
  69. function cmNewID ()
  70. {
  71. return _cmIDName + (++_cmIDCount);
  72. }
  73. //
  74. // return the property string for the menu item
  75. //
  76. function cmActionItem (item, prefix, isMain, idSub, orient, nodeProperties)
  77. {
  78. // var index = _cmItemList.push (item) - 1;
  79. _cmItemList[_cmItemList.length] = item;
  80. var index = _cmItemList.length - 1;
  81. idSub = (!idSub) ? 'null' : ('\'' + idSub + '\'');
  82. orient = '\'' + orient + '\'';
  83. prefix = '\'' + prefix + '\'';
  84. return ' onmouseover="cmItemMouseOver (this,' + prefix + ',' + isMain + ',' + idSub + ',' + orient + ',' + index + ')" onmouseout="cmItemMouseOut (this,' + nodeProperties.delay + ')" onmousedown="cmItemMouseDown (this,' + index + ')" onmouseup="cmItemMouseUp (this,' + index + ')"';
  85. }
  86. function cmNoActionItem (item, prefix)
  87. {
  88. return item[1];
  89. }
  90. function cmSplitItem (prefix, isMain, vertical)
  91. {
  92. var classStr = 'cm' + prefix;
  93. if (isMain)
  94. {
  95. classStr += 'Main';
  96. if (vertical)
  97. classStr += 'HSplit';
  98. else
  99. classStr += 'VSplit';
  100. }
  101. else
  102. classStr += 'HSplit';
  103. var item = eval (classStr);
  104. return cmNoActionItem (item, prefix);
  105. }
  106. //
  107. // draw the sub menu recursively
  108. //
  109. function cmDrawSubMenu (subMenu, prefix, id, orient, nodeProperties)
  110. {
  111. var str = '<div class="' + prefix + 'SubMenu" id="' + id + '"><table summary="sub menu" cellspacing="' + nodeProperties.subSpacing + '" class="' + prefix + 'SubMenuTable">';
  112. var strSub = '';
  113. var item;
  114. var idSub;
  115. var hasChild;
  116. var i;
  117. var classStr;
  118. for (i = 5; i < subMenu.length; ++i)
  119. {
  120. item = subMenu[i];
  121. if (!item)
  122. continue;
  123. hasChild = (item.length > 5);
  124. idSub = hasChild ? cmNewID () : null;
  125. str += '<tr class="' + prefix + 'MenuItem"' + cmActionItem (item, prefix, 0, idSub, orient, nodeProperties) + '>';
  126. if (item == _cmSplit)
  127. {
  128. str += cmSplitItem (prefix, 0, true);
  129. str += '</tr>';
  130. continue;
  131. }
  132. if (item[0] == _cmNoAction)
  133. {
  134. str += cmNoActionItem (item, prefix);
  135. str += '</tr>';
  136. continue;
  137. }
  138. classStr = prefix + 'Menu';
  139. classStr += hasChild ? 'Folder' : 'Item';
  140. str += '<td class="' + classStr + 'Left">';
  141. if (item[0] != null && item[0] != _cmNoAction)
  142. str += item[0];
  143. else
  144. str += hasChild ? nodeProperties.folderLeft : nodeProperties.itemLeft;
  145. str += '<td class="' + classStr + 'Text">' + item[1];
  146. str += '<td class="' + classStr + 'Right">';
  147. if (hasChild)
  148. {
  149. str += nodeProperties.folderRight;
  150. strSub += cmDrawSubMenu (item, prefix, idSub, orient, nodeProperties);
  151. }
  152. else
  153. str += nodeProperties.itemRight;
  154. str += '</td></tr>';
  155. }
  156. str += '</table></div>' + strSub;
  157. return str;
  158. }
  159. //
  160. // The function that builds the menu inside the specified element id.
  161. //
  162. // @param id id of the element
  163. // orient orientation of the menu in [hv][ab][lr] format
  164. // menu the menu object to be drawn
  165. // nodeProperties properties for each menu node
  166. //
  167. function cmDraw (id, menu, orient, nodeProperties, prefix)
  168. {
  169. var obj = cmGetObject (id);
  170. if (!nodeProperties)
  171. nodeProperties = _cmNodeProperties;
  172. if (!prefix)
  173. prefix = '';
  174. var str = '<table summary="main menu" class="' + prefix + 'Menu" cellspacing="' + nodeProperties.mainSpacing + '">';
  175. var strSub = '';
  176. if (!orient)
  177. orient = 'hbr';
  178. var orientStr = String (orient);
  179. var orientSub;
  180. var vertical;
  181. // draw the main menu items
  182. if (orientStr.charAt (0) == 'h')
  183. {
  184. // horizontal menu
  185. orientSub = 'v' + orientStr.substr (1, 2);
  186. str += '<tr>';
  187. vertical = false;
  188. }
  189. else
  190. {
  191. // vertical menu
  192. orientSub = 'v' + orientStr.substr (1, 2);
  193. vertical = true;
  194. }
  195. var i;
  196. var item;
  197. var idSub;
  198. var hasChild;
  199. var classStr;
  200. for (i = 0; i < menu.length; ++i)
  201. {
  202. item = menu[i];
  203. if (!item)
  204. continue;
  205. str += vertical ? '<tr' : '<td';
  206. str += ' class="' + prefix + 'MainItem"';
  207. hasChild = (item.length > 5);
  208. idSub = hasChild ? cmNewID () : null;
  209. str += cmActionItem (item, prefix, 1, idSub, orient, nodeProperties) + '>';
  210. if (item == _cmSplit)
  211. {
  212. str += cmSplitItem (prefix, 1, vertical);
  213. str += vertical? '</tr>' : '</td>';
  214. continue;
  215. }
  216. if (item[0] == _cmNoAction)
  217. {
  218. str += cmNoActionItem (item, prefix);
  219. str += vertical? '</tr>' : '</td>';
  220. continue;
  221. }
  222. classStr = prefix + 'Main' + (hasChild ? 'Folder' : 'Item');
  223. str += vertical ? '<td' : '<span';
  224. str += ' class="' + classStr + 'Left">';
  225. str += (item[0] == null) ? (hasChild ? nodeProperties.mainFolderLeft : nodeProperties.mainItemLeft)
  226. : item[0];
  227. str += vertical ? '</td>' : '</span>';
  228. str += vertical ? '<td' : '<span';
  229. str += ' class="' + classStr + 'Text">';
  230. str += item[1];
  231. str += vertical ? '</td>' : '</span>';
  232. str += vertical ? '<td' : '<span';
  233. str += ' class="' + classStr + 'Right">';
  234. str += hasChild ? nodeProperties.mainFolderRight : nodeProperties.mainItemRight;
  235. str += vertical ? '</td>' : '</span>';
  236. str += vertical ? '</tr>' : '</td>';
  237. if (hasChild)
  238. strSub += cmDrawSubMenu (item, prefix, idSub, orientSub, nodeProperties);
  239. }
  240. if (!vertical)
  241. str += '</tr>';
  242. str += '</table>' + strSub;
  243. obj.innerHTML = str;
  244. //document.write ("<xmp>" + str + "</xmp>");
  245. }
  246. //////////////////////////////////////////////////////////////////////
  247. //
  248. // Mouse Event Handling Functions
  249. //
  250. //////////////////////////////////////////////////////////////////////
  251. //
  252. // action should be taken for mouse moving in to the menu item
  253. //
  254. function cmItemMouseOver (obj, prefix, isMain, idSub, orient, index)
  255. {
  256. clearTimeout (_cmTimeOut);
  257. if (!obj.cmPrefix)
  258. {
  259. obj.cmPrefix = prefix;
  260. obj.cmIsMain = isMain;
  261. }
  262. var thisMenu = cmGetThisMenu (obj, prefix);
  263. // insert obj into cmItems if cmItems doesn't have obj
  264. if (!thisMenu.cmItems)
  265. thisMenu.cmItems = new Array ();
  266. var i;
  267. for (i = 0; i < thisMenu.cmItems.length; ++i)
  268. {
  269. if (thisMenu.cmItems[i] == obj)
  270. break;
  271. }
  272. if (i == thisMenu.cmItems.length)
  273. {
  274. //thisMenu.cmItems.push (obj);
  275. thisMenu.cmItems[i] = obj;
  276. }
  277. // hide the previous submenu that is not this branch
  278. if (_cmCurrentItem)
  279. {
  280. // occationally, we get this case when user
  281. // move the mouse slowly to the border
  282. if (_cmCurrentItem == thisMenu)
  283. return;
  284. var thatPrefix = _cmCurrentItem.cmPrefix;
  285. var thatMenu = cmGetThisMenu (_cmCurrentItem, thatPrefix);
  286. if (thatMenu != thisMenu.cmParentMenu)
  287. {
  288. if (_cmCurrentItem.cmIsMain)
  289. _cmCurrentItem.className = thatPrefix + 'MainItem';
  290. else
  291. _cmCurrentItem.className = thatPrefix + 'MenuItem';
  292. if (thatMenu.id != idSub)
  293. cmHideMenu (thatMenu, thisMenu, thatPrefix);
  294. }
  295. }
  296. // okay, set the current menu to this obj
  297. _cmCurrentItem = obj;
  298. // just in case, reset all items in this menu to MenuItem
  299. cmResetMenu (thisMenu, prefix);
  300. var item = _cmItemList[index];
  301. var isDefaultItem = cmIsDefaultItem (item);
  302. if (isDefaultItem)
  303. {
  304. if (isMain)
  305. obj.className = prefix + 'MainItemHover';
  306. else
  307. obj.className = prefix + 'MenuItemHover';
  308. }
  309. if (idSub)
  310. {
  311. var subMenu = cmGetObject (idSub);
  312. cmShowSubMenu (obj, prefix, subMenu, orient);
  313. }
  314. var descript = '';
  315. if (item.length > 4)
  316. descript = (item[4] != null) ? item[4] : (item[2] ? item[2] : descript);
  317. else if (item.length > 2)
  318. descript = (item[2] ? item[2] : descript);
  319. window.defaultStatus = descript;
  320. }
  321. //
  322. // action should be taken for mouse moving out of the menu item
  323. //
  324. function cmItemMouseOut (obj, delayTime)
  325. {
  326. if (!delayTime)
  327. delayTime = _cmNodeProperties.delay;
  328. _cmTimeOut = window.setTimeout ('cmHideMenuTime ()', delayTime);
  329. window.defaultStatus = '';
  330. }
  331. //
  332. // action should be taken for mouse button down at a menu item
  333. //
  334. function cmItemMouseDown (obj, index)
  335. {
  336. if (cmIsDefaultItem (_cmItemList[index]))
  337. {
  338. if (obj.cmIsMain)
  339. obj.className = obj.cmPrefix + 'MainItemActive';
  340. else
  341. obj.className = obj.cmPrefix + 'MenuItemActive';
  342. }
  343. }
  344. //
  345. // action should be taken for mouse button up at a menu item
  346. //
  347. function cmItemMouseUp (obj, index)
  348. {
  349. var item = _cmItemList[index];
  350. var link = null, target = '_self';
  351. if (item.length > 2)
  352. link = item[2];
  353. if (item.length > 3 && item[3])
  354. target = item[3];
  355. if (link != null)
  356. {
  357. window.open (link, target);
  358. }
  359. var prefix = obj.cmPrefix;
  360. var thisMenu = cmGetThisMenu (obj, prefix);
  361. var hasChild = (item.length > 5);
  362. if (!hasChild)
  363. {
  364. if (cmIsDefaultItem (item))
  365. {
  366. if (obj.cmIsMain)
  367. obj.className = prefix + 'MainItem';
  368. else
  369. obj.className = prefix + 'MenuItem';
  370. }
  371. cmHideMenu (thisMenu, null, prefix);
  372. }
  373. else
  374. {
  375. if (cmIsDefaultItem (item))
  376. {
  377. if (obj.cmIsMain)
  378. obj.className = prefix + 'MainItemHover';
  379. else
  380. obj.className = prefix + 'MenuItemHover';
  381. }
  382. }
  383. }
  384. //////////////////////////////////////////////////////////////////////
  385. //
  386. // Mouse Event Support Utility Functions
  387. //
  388. //////////////////////////////////////////////////////////////////////
  389. //
  390. // move submenu to the appropriate location
  391. //
  392. // @param obj the menu item that opens up the subMenu
  393. // subMenu the sub menu to be shown
  394. // orient the orientation of the subMenu
  395. //
  396. function cmMoveSubMenu (obj, subMenu, orient)
  397. {
  398. var mode = String (orient);
  399. var p = subMenu.offsetParent;
  400. if (mode.charAt (0) == 'h')
  401. {
  402. if (mode.charAt (1) == 'b')
  403. subMenu.style.top = (cmGetYAt (obj, p) + cmGetHeight (obj)) + 'px';
  404. else
  405. subMenu.style.top = (cmGetYAt (obj, p) - cmGetHeight (subMenu)) + 'px';
  406. if (mode.charAt (2) == 'r')
  407. subMenu.style.left = (cmGetXAt (obj, p)) + 'px';
  408. else
  409. subMenu.style.left = (cmGetXAt (obj, p) + cmGetWidth (obj) - cmGetWidth (subMenu)) + 'px';
  410. }
  411. else
  412. {
  413. if (mode.charAt (2) == 'r')
  414. subMenu.style.left = (cmGetXAt (obj, p) + cmGetWidth (obj)) + 'px';
  415. else
  416. subMenu.style.left = (cmGetXAt (obj, p) - cmGetWidth (subMenu)) + 'px';
  417. if (mode.charAt (1) == 'b')
  418. subMenu.style.top = (cmGetYAt (obj, p)) + 'px';
  419. else
  420. subMenu.style.top = (cmGetYAt (obj, p) + cmGetHeight (obj) - cmGetHeight (subMenu)) + 'px';
  421. }
  422. }
  423. //
  424. // show the subMenu w/ specified orientation
  425. // also move it to the correct coordinates
  426. //
  427. // @param obj the menu item that opens up the subMenu
  428. // subMenu the sub menu to be shown
  429. // orient the orientation of the subMenu
  430. //
  431. function cmShowSubMenu (obj, prefix, subMenu, orient)
  432. {
  433. if (!subMenu.cmParentMenu)
  434. {
  435. // establish the tree w/ back edge
  436. var thisMenu = cmGetThisMenu (obj, prefix);
  437. subMenu.cmParentMenu = thisMenu;
  438. if (!thisMenu.cmSubMenu)
  439. thisMenu.cmSubMenu = new Array ();
  440. //thisMenu.cmSubMenu.push (subMenu);
  441. thisMenu.cmSubMenu[thisMenu.cmSubMenu.length] = subMenu;
  442. }
  443. // position the sub menu
  444. cmMoveSubMenu (obj, subMenu, orient);
  445. subMenu.style.visibility = 'visible';
  446. //
  447. // On IE, controls such as SELECT, OBJECT, IFRAME (before 5.5)
  448. // are window based controls. So, if the sub menu and these
  449. // controls overlap, sub menu would be hidden behind them. Thus
  450. // one needs to turn the visibility of these controls off when the
  451. // sub menu is showing, and turn their visibility back on
  452. // when the sub menu is hiding.
  453. //
  454. if (document.all) // it is IE
  455. {
  456. /* part of Felix Zaslavskiy's fix on hiding controls
  457. not really sure if this part is necessary, but shouldn't
  458. hurt. */
  459. if (!subMenu.cmOverlap)
  460. subMenu.cmOverlap = new Array ();
  461. /*@cc_on @*/
  462. /*@if (@_jscript_version >= 5.5)
  463. @else @*/
  464. cmHideControl ("IFRAME", subMenu);
  465. /*@end @*/
  466. cmHideControl ("SELECT", subMenu);
  467. cmHideControl ("OBJECT", subMenu);
  468. }
  469. }
  470. //
  471. // reset all the menu items to class MenuItem in thisMenu
  472. //
  473. function cmResetMenu (thisMenu, prefix)
  474. {
  475. if (thisMenu.cmItems)
  476. {
  477. var i;
  478. var str;
  479. var items = thisMenu.cmItems;
  480. for (i = 0; i < items.length; ++i)
  481. {
  482. if (items[i].cmIsMain)
  483. str = prefix + 'MainItem';
  484. else
  485. str = prefix + 'MenuItem';
  486. if (items[i].className != str)
  487. items[i].className = str;
  488. }
  489. }
  490. }
  491. //
  492. // called by the timer to hide the menu
  493. //
  494. function cmHideMenuTime ()
  495. {
  496. if (_cmCurrentItem)
  497. {
  498. var prefix = _cmCurrentItem.cmPrefix;
  499. cmHideMenu (cmGetThisMenu (_cmCurrentItem, prefix), null, prefix);
  500. }
  501. }
  502. //
  503. // hide thisMenu, children of thisMenu, as well as the ancestor
  504. // of thisMenu until currentMenu is encountered. currentMenu
  505. // will not be hidden
  506. //
  507. function cmHideMenu (thisMenu, currentMenu, prefix)
  508. {
  509. var str = prefix + 'SubMenu';
  510. // hide the down stream menus
  511. if (thisMenu.cmSubMenu)
  512. {
  513. var i;
  514. for (i = 0; i < thisMenu.cmSubMenu.length; ++i)
  515. {
  516. cmHideSubMenu (thisMenu.cmSubMenu[i], prefix);
  517. }
  518. }
  519. // hide the upstream menus
  520. while (thisMenu && thisMenu != currentMenu)
  521. {
  522. cmResetMenu (thisMenu, prefix);
  523. if (thisMenu.className == str)
  524. {
  525. thisMenu.style.visibility = 'hidden';
  526. cmShowControl (thisMenu);
  527. }
  528. else
  529. break;
  530. thisMenu = cmGetThisMenu (thisMenu.cmParentMenu, prefix);
  531. }
  532. }
  533. //
  534. // hide thisMenu as well as its sub menus if thisMenu is not
  535. // already hidden
  536. //
  537. function cmHideSubMenu (thisMenu, prefix)
  538. {
  539. if (thisMenu.style.visibility == 'hidden')
  540. return;
  541. if (thisMenu.cmSubMenu)
  542. {
  543. var i;
  544. for (i = 0; i < thisMenu.cmSubMenu.length; ++i)
  545. {
  546. cmHideSubMenu (thisMenu.cmSubMenu[i], prefix);
  547. }
  548. }
  549. cmResetMenu (thisMenu, prefix);
  550. thisMenu.style.visibility = 'hidden';
  551. cmShowControl (thisMenu);
  552. }
  553. //
  554. // hide a control such as IFRAME
  555. //
  556. function cmHideControl (tagName, subMenu)
  557. {
  558. var x = cmGetX (subMenu);
  559. var y = cmGetY (subMenu);
  560. var w = subMenu.offsetWidth;
  561. var h = subMenu.offsetHeight;
  562. var i;
  563. for (i = 0; i < document.all.tags(tagName).length; ++i)
  564. {
  565. var obj = document.all.tags(tagName)[i];
  566. if (!obj || !obj.offsetParent)
  567. continue;
  568. // check if the object and the subMenu overlap
  569. var ox = cmGetX (obj);
  570. var oy = cmGetY (obj);
  571. var ow = obj.offsetWidth;
  572. var oh = obj.offsetHeight;
  573. if (ox > (x + w) || (ox + ow) < x)
  574. continue;
  575. if (oy > (y + h) || (oy + oh) < y)
  576. continue;
  577. // if object is already made hidden by a different
  578. // submenu then we dont want to put it on overlap list of
  579. // of a submenu a second time.
  580. // - bug fixed by Felix Zaslavskiy
  581. if(obj.style.visibility == "hidden")
  582. continue;
  583. //subMenu.cmOverlap.push (obj);
  584. subMenu.cmOverlap[subMenu.cmOverlap.length] = obj;
  585. obj.style.visibility = "hidden";
  586. }
  587. }
  588. //
  589. // show the control hidden by the subMenu
  590. //
  591. function cmShowControl (subMenu)
  592. {
  593. if (subMenu.cmOverlap)
  594. {
  595. var i;
  596. for (i = 0; i < subMenu.cmOverlap.length; ++i)
  597. subMenu.cmOverlap[i].style.visibility = "";
  598. }
  599. subMenu.cmOverlap = null;
  600. }
  601. //
  602. // returns the main menu or the submenu table where this obj (menu item)
  603. // is in
  604. //
  605. function cmGetThisMenu (obj, prefix)
  606. {
  607. var str1 = prefix + 'SubMenu';
  608. var str2 = prefix + 'Menu';
  609. while (obj)
  610. {
  611. if (obj.className == str1 || obj.className == str2)
  612. return obj;
  613. obj = obj.parentNode;
  614. }
  615. return null;
  616. }
  617. //
  618. // return true if this item is handled using default handlers
  619. //
  620. function cmIsDefaultItem (item)
  621. {
  622. if (item == _cmSplit || item[0] == _cmNoAction)
  623. return false;
  624. return true;
  625. }
  626. //
  627. // returns the object baring the id
  628. //
  629. function cmGetObject (id)
  630. {
  631. if (document.all)
  632. return document.all[id];
  633. return document.getElementById (id);
  634. }
  635. //
  636. // functions that obtain the width of an HTML element.
  637. //
  638. function cmGetWidth (obj)
  639. {
  640. var width = obj.offsetWidth;
  641. if (width > 0 || !cmIsTRNode (obj))
  642. return width;
  643. if (!obj.firstChild)
  644. return 0;
  645. // use TABLE's length can cause an extra pixel gap
  646. //return obj.parentNode.parentNode.offsetWidth;
  647. // use the left and right child instead
  648. return obj.lastChild.offsetLeft - obj.firstChild.offsetLeft + cmGetWidth (obj.lastChild);
  649. }
  650. //
  651. // functions that obtain the height of an HTML element.
  652. //
  653. function cmGetHeight (obj)
  654. {
  655. var height = obj.offsetHeight;
  656. if (height > 0 || !cmIsTRNode (obj))
  657. return height;
  658. if (!obj.firstChild)
  659. return 0;
  660. // use the first child's height
  661. return obj.firstChild.offsetHeight;
  662. }
  663. //
  664. // functions that obtain the coordinates of an HTML element
  665. //
  666. function cmGetX (obj)
  667. {
  668. var x = 0;
  669. do
  670. {
  671. x += obj.offsetLeft;
  672. obj = obj.offsetParent;
  673. }
  674. while (obj);
  675. return x;
  676. }
  677. function cmGetXAt (obj, elm)
  678. {
  679. var x = 0;
  680. while (obj && obj != elm)
  681. {
  682. x += obj.offsetLeft;
  683. obj = obj.offsetParent;
  684. }
  685. if (obj == elm)
  686. return x;
  687. return cmGetX (elm) - x;
  688. }
  689. function cmGetY (obj)
  690. {
  691. var y = 0;
  692. do
  693. {
  694. y += obj.offsetTop;
  695. obj = obj.offsetParent;
  696. }
  697. while (obj);
  698. return y;
  699. }
  700. function cmIsTRNode (obj)
  701. {
  702. var tagName = obj.tagName;
  703. return tagName == "TR" || tagName == "tr" || tagName == "Tr" || tagName == "tR";
  704. }
  705. //
  706. // get the Y position of the object. In case of TR element though,
  707. // we attempt to adjust the value.
  708. //
  709. function cmGetYAt (obj, elm)
  710. {
  711. var y = 0;
  712. if (!obj.offsetHeight && cmIsTRNode (obj))
  713. {
  714. var firstTR = obj.parentNode.firstChild;
  715. obj = obj.firstChild;
  716. y -= firstTR.firstChild.offsetTop;
  717. }
  718. while (obj && obj != elm)
  719. {
  720. y += obj.offsetTop;
  721. obj = obj.offsetParent;
  722. }
  723. if (obj == elm)
  724. return y;
  725. return cmGetY (elm) - y;
  726. }
  727. //
  728. // debug function, ignore :)
  729. //
  730. function cmGetProperties (obj)
  731. {
  732. if (obj == undefined)
  733. return 'undefined';
  734. if (obj == null)
  735. return 'null';
  736. var msg = obj + ':\n';
  737. var i;
  738. for (i in obj)
  739. msg += i + ' = ' + obj[i] + '; ';
  740. return msg;
  741. }
  742. /* JSCookMenu v1.25 1. fix Safari positioning issue. The problem is that all TR elements are located
  743. at the top left corner. Thus, need to obtain the "virtual"
  744. position of these element could be at.
  745. */
  746. /* JSCookMenu v1.24 1. fix window based control hiding bug
  747. thanks to Felix Zaslavskiy <felix@bebinary.com> for the fix.
  748. */
  749. /* JSCookMenu v1.23 1. correct a position bug when the container is positioned.
  750. thanks to Andre <anders@netspace.net.au> for narrowing down
  751. the problem.
  752. */
  753. /* JSCookMenu v1.22 1. change Array.push (obj) call to Array[length] = obj.
  754. Suggestion from Dick van der Kaaden <dick@netrex.nl> to
  755. make the script compatible with IE 5.0
  756. 2. Changed theme files a little to add z-index: 100 for sub
  757. menus. This change is necessary for Netscape to avoid
  758. a display problem.
  759. 3. some changes to the DOM structure to make this menu working
  760. on Netscape 6.0 (tested). The main reason is that NN6 does
  761. not do absolute positioning with tables. Therefore an extra
  762. div layer must be put around the table.
  763. */
  764. /* JSCookMenu v1.21 1. fixed a bug that didn't add 'px' as part of coordinates.
  765. JSCookMenu should be XHTML validator friendly now.
  766. 2. removed unnecessary display attribute and corresponding
  767. theme entry to fix a problem that Netscape sometimes
  768. render Office theme incorrectly
  769. */
  770. /* JSCookMenu v1.2. 1. fix the problem of showing status in Netscape
  771. 2. changed the handler parameters a bit to allow
  772. string literals to be passed to javascript based
  773. links
  774. 3. having null in target field would cause the link
  775. to be opened in the current window, but this behavior
  776. could change in the future releases
  777. */
  778. /* JSCookMenu v1.1. added ability to hide controls in IE to show submenus properly */
  779. /* JSCookMenu v1.01. cmDraw generates XHTML code */
  780. /* JSCookMenu v1.0. (c) Copyright 2002 by Heng Yuan */