JSCookMenu.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  1. /*
  2. JSCookMenu v2.0.4 (c) Copyright 2002-2006 by Heng Yuan
  3. http://jscook.sourceforge.net/JSCookMenu/
  4. Permission is hereby granted, free of charge, to any person obtaining a
  5. copy of this software and associated documentation files (the "Software"),
  6. to deal in the Software without restriction, including without limitation
  7. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. and/or sell copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included
  11. in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. ITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  18. DEALINGS IN THE SOFTWARE.
  19. */
  20. // default node properties
  21. var _cmNodeProperties =
  22. {
  23. // theme prefix
  24. prefix: '',
  25. // main menu display attributes
  26. //
  27. // Note. When the menu bar is horizontal,
  28. // mainFolderLeft and mainFolderRight are
  29. // put in <span></span>. When the menu
  30. // bar is vertical, they would be put in
  31. // a separate TD cell.
  32. // HTML code to the left of the folder item
  33. mainFolderLeft: '',
  34. // HTML code to the right of the folder item
  35. mainFolderRight: '',
  36. // HTML code to the left of the regular item
  37. mainItemLeft: '',
  38. // HTML code to the right of the regular item
  39. mainItemRight: '',
  40. // sub menu display attributes
  41. // HTML code to the left of the folder item
  42. folderLeft: '',
  43. // HTML code to the right of the folder item
  44. folderRight: '',
  45. // HTML code to the left of the regular item
  46. itemLeft: '',
  47. // HTML code to the right of the regular item
  48. itemRight: '',
  49. // cell spacing for main menu
  50. mainSpacing: 0,
  51. // cell spacing for sub menus
  52. subSpacing: 0,
  53. // optional settings
  54. // If not set, use the default
  55. // auto disappear time for submenus in milli-seconds
  56. delay: 500,
  57. // 1st layer sub menu starting index
  58. zIndexStart: 1000,
  59. // z-index incremental step for subsequent layers
  60. zIndexInc: 5,
  61. // sub menu header appears before the sub menu table
  62. subMenuHeader: null,
  63. // sub menu header appears after the sub menu table
  64. subMenuFooter: null,
  65. // submenu location adjustments
  66. //
  67. // offsetHMainAdjust for adjusting the first submenu
  68. // of a 'hbr' menu.
  69. // offsetVMainAdjust for adjusting the first submenu
  70. // of a 'vbr' menu.
  71. // offsetSubAdjust for subsequent level of submenus
  72. //
  73. offsetHMainAdjust: [0, 0],
  74. offsetVMainAdjust: [0, 0],
  75. offsetSubAdjust: [0, 0],
  76. // act on click to open sub menu
  77. // not yet implemented
  78. // 0 : use default behavior
  79. // 1 : hover open in all cases
  80. // 2 : click on main, hover on sub
  81. // 3 : click open in all cases (illegal as of 1.5)
  82. clickOpen: 1,
  83. // special effects on open/closing a sub menu
  84. effect: null
  85. };
  86. // Globals
  87. var _cmIDCount = 0;
  88. var _cmIDName = 'cmSubMenuID'; // for creating submenu id
  89. var _cmTimeOut = null; // how long the menu would stay
  90. var _cmCurrentItem = null; // the current menu item being selected;
  91. var _cmNoAction = new Object (); // indicate that the item cannot be hovered.
  92. var _cmNoClick = new Object (); // similar to _cmNoAction but does not respond to mouseup/mousedown events
  93. var _cmSplit = new Object (); // indicate that the item is a menu split
  94. var _cmMenuList = new Array (); // a list of the current menus
  95. var _cmItemList = new Array (); // a simple list of items
  96. var _cmFrameList = new Array (); // a pool of reusable iframes
  97. var _cmFrameListSize = 0; // keep track of the actual size
  98. var _cmFrameIDCount = 0; // keep track of the frame id
  99. var _cmFrameMasking = true; // use the frame masking
  100. // disable iframe masking for IE7
  101. /*@cc_on
  102. @if (@_jscript_version >= 5.6)
  103. if (_cmFrameMasking)
  104. {
  105. var v = navigator.appVersion;
  106. var i = v.indexOf ("MSIE ");
  107. if (i >= 0)
  108. {
  109. if (parseInt (navigator.appVersion.substring (i + 5)) >= 7)
  110. _cmFrameMasking = false;
  111. }
  112. }
  113. @end
  114. @*/
  115. var _cmClicked = false; // for onClick
  116. // flag for turning on off hiding objects
  117. //
  118. // 0: automatic
  119. // 1: hiding
  120. // 2: no hiding
  121. var _cmHideObjects = 0;
  122. // Utility function to do a shallow copy a node property
  123. function cmClone (nodeProperties)
  124. {
  125. var returnVal = new Object ();
  126. for (v in nodeProperties)
  127. returnVal[v] = nodeProperties[v];
  128. return returnVal;
  129. }
  130. //
  131. // store the new menu information into a structure to retrieve it later
  132. //
  133. function cmAllocMenu (id, menu, orient, nodeProperties, prefix)
  134. {
  135. var info = new Object ();
  136. info.div = id;
  137. info.menu = menu;
  138. info.orient = orient;
  139. info.nodeProperties = nodeProperties;
  140. info.prefix = prefix;
  141. var menuID = _cmMenuList.length;
  142. _cmMenuList[menuID] = info;
  143. return menuID;
  144. }
  145. //
  146. // request a frame
  147. //
  148. function cmAllocFrame ()
  149. {
  150. if (_cmFrameListSize > 0)
  151. return cmGetObject (_cmFrameList[--_cmFrameListSize]);
  152. var frameObj = document.createElement ('iframe');
  153. var id = _cmFrameIDCount++;
  154. frameObj.id = 'cmFrame' + id;
  155. frameObj.frameBorder = '0';
  156. frameObj.style.display = 'none';
  157. frameObj.src = 'javascript:false';
  158. document.body.appendChild (frameObj);
  159. frameObj.style.filter = 'alpha(opacity=0)';
  160. frameObj.style.zIndex = 99;
  161. frameObj.style.position = 'absolute';
  162. frameObj.style.border = '0';
  163. frameObj.scrolling = 'no';
  164. return frameObj;
  165. }
  166. //
  167. // make a frame resuable later
  168. //
  169. function cmFreeFrame (frameObj)
  170. {
  171. _cmFrameList[_cmFrameListSize++] = frameObj.id;
  172. }
  173. //////////////////////////////////////////////////////////////////////
  174. //
  175. // Drawing Functions and Utility Functions
  176. //
  177. //////////////////////////////////////////////////////////////////////
  178. //
  179. // produce a new unique id
  180. //
  181. function cmNewID ()
  182. {
  183. return _cmIDName + (++_cmIDCount);
  184. }
  185. //
  186. // return the property string for the menu item
  187. //
  188. function cmActionItem (item, isMain, idSub, menuInfo, menuID)
  189. {
  190. _cmItemList[_cmItemList.length] = item;
  191. var index = _cmItemList.length - 1;
  192. idSub = (!idSub) ? 'null' : ('\'' + idSub + '\'');
  193. var clickOpen = menuInfo.nodeProperties.clickOpen;
  194. var onClick = (clickOpen == 3) || (clickOpen == 2 && isMain);
  195. var param = 'this,' + isMain + ',' + idSub + ',' + menuID + ',' + index;
  196. var returnStr;
  197. if (onClick)
  198. returnStr = ' onmouseover="cmItemMouseOver(' + param + ',false)" onmousedown="cmItemMouseDownOpenSub (' + param + ')"';
  199. else
  200. returnStr = ' onmouseover="cmItemMouseOverOpenSub (' + param + ')" onmousedown="cmItemMouseDown (' + param + ')"';
  201. return returnStr + ' onmouseout="cmItemMouseOut (' + param + ')" onmouseup="cmItemMouseUp (' + param + ')"';
  202. }
  203. //
  204. // this one is used by _cmNoClick to only take care of onmouseover and onmouseout
  205. // events which are associated with menu but not actions associated with menu clicking/closing
  206. //
  207. function cmNoClickItem (item, isMain, idSub, menuInfo, menuID)
  208. {
  209. // var index = _cmItemList.push (item) - 1;
  210. _cmItemList[_cmItemList.length] = item;
  211. var index = _cmItemList.length - 1;
  212. idSub = (!idSub) ? 'null' : ('\'' + idSub + '\'');
  213. var param = 'this,' + isMain + ',' + idSub + ',' + menuID + ',' + index;
  214. return ' onmouseover="cmItemMouseOver (' + param + ')" onmouseout="cmItemMouseOut (' + param + ')"';
  215. }
  216. function cmNoActionItem (item)
  217. {
  218. return item[1];
  219. }
  220. function cmSplitItem (prefix, isMain, vertical)
  221. {
  222. var classStr = 'cm' + prefix;
  223. if (isMain)
  224. {
  225. classStr += 'Main';
  226. if (vertical)
  227. classStr += 'HSplit';
  228. else
  229. classStr += 'VSplit';
  230. }
  231. else
  232. classStr += 'HSplit';
  233. return eval (classStr);
  234. }
  235. //
  236. // draw the sub menu recursively
  237. //
  238. function cmDrawSubMenu (subMenu, prefix, id, nodeProperties, zIndexStart, menuInfo, menuID)
  239. {
  240. var str = '<div class="' + prefix + 'SubMenu" id="' + id + '" style="z-index: ' + zIndexStart + ';position: absolute; top: 0px; left: 0px;">';
  241. if (nodeProperties.subMenuHeader)
  242. str += nodeProperties.subMenuHeader;
  243. str += '<table summary="sub menu" id="' + id + 'Table" cellspacing="' + nodeProperties.subSpacing + '" class="' + prefix + 'SubMenuTable">';
  244. var strSub = '';
  245. var item;
  246. var idSub;
  247. var hasChild;
  248. var i;
  249. var classStr;
  250. for (i = 5; i < subMenu.length; ++i)
  251. {
  252. item = subMenu[i];
  253. if (!item)
  254. continue;
  255. if (item == _cmSplit)
  256. item = cmSplitItem (prefix, 0, true);
  257. item.parentItem = subMenu;
  258. item.subMenuID = id;
  259. hasChild = (item.length > 5);
  260. idSub = hasChild ? cmNewID () : null;
  261. str += '<tr class="' + prefix + 'MenuItem"';
  262. if (item[0] != _cmNoClick)
  263. str += cmActionItem (item, 0, idSub, menuInfo, menuID);
  264. else
  265. str += cmNoClickItem (item, 0, idSub, menuInfo, menuID);
  266. str += '>';
  267. if (item[0] == _cmNoAction || item[0] == _cmNoClick)
  268. {
  269. str += cmNoActionItem (item);
  270. str += '</tr>';
  271. continue;
  272. }
  273. classStr = prefix + 'Menu';
  274. classStr += hasChild ? 'Folder' : 'Item';
  275. str += '<td class="' + classStr + 'Left">';
  276. if (item[0] != null)
  277. str += item[0];
  278. else
  279. str += hasChild ? nodeProperties.folderLeft : nodeProperties.itemLeft;
  280. str += '</td><td class="' + classStr + 'Text">' + item[1];
  281. str += '</td><td class="' + classStr + 'Right">';
  282. if (hasChild)
  283. {
  284. str += nodeProperties.folderRight;
  285. strSub += cmDrawSubMenu (item, prefix, idSub, nodeProperties, zIndexStart + nodeProperties.zIndexInc, menuInfo, menuID);
  286. }
  287. else
  288. str += nodeProperties.itemRight;
  289. str += '</td></tr>';
  290. }
  291. str += '</table>';
  292. if (nodeProperties.subMenuFooter)
  293. str += nodeProperties.subMenuFooter;
  294. str += '</div>' + strSub;
  295. return str;
  296. }
  297. //
  298. // The function that builds the menu inside the specified element id.
  299. //
  300. // id id of the element
  301. // orient orientation of the menu in [hv][ub][lr] format
  302. // menu the menu object to be drawn
  303. // nodeProperties properties for the theme
  304. // prefix prefix of the theme
  305. //
  306. function cmDraw (id, menu, orient, nodeProperties, prefix)
  307. {
  308. var obj = cmGetObject (id);
  309. if (!prefix)
  310. prefix = nodeProperties.prefix;
  311. if (!prefix)
  312. prefix = '';
  313. if (!nodeProperties)
  314. nodeProperties = _cmNodeProperties;
  315. if (!orient)
  316. orient = 'hbr';
  317. var menuID = cmAllocMenu (id, menu, orient, nodeProperties, prefix);
  318. var menuInfo = _cmMenuList[menuID];
  319. // setup potentially missing properties
  320. if (!nodeProperties.delay)
  321. nodeProperties.delay = _cmNodeProperties.delay;
  322. if (!nodeProperties.clickOpen)
  323. nodeProperties.clickOpen = _cmNodeProperties.clickOpen;
  324. if (!nodeProperties.zIndexStart)
  325. nodeProperties.zIndexStart = _cmNodeProperties.zIndexStart;
  326. if (!nodeProperties.zIndexInc)
  327. nodeProperties.zIndexInc = _cmNodeProperties.zIndexInc;
  328. if (!nodeProperties.offsetHMainAdjust)
  329. nodeProperties.offsetHMainAdjust = _cmNodeProperties.offsetHMainAdjust;
  330. if (!nodeProperties.offsetVMainAdjust)
  331. nodeProperties.offsetVMainAdjust = _cmNodeProperties.offsetVMainAdjust;
  332. if (!nodeProperties.offsetSubAdjust)
  333. nodeProperties.offsetSubAdjust = _cmNodeProperties.offsetSubAdjust;
  334. // save user setting on frame masking
  335. menuInfo.cmFrameMasking = _cmFrameMasking;
  336. var str = '<table summary="main menu" class="' + prefix + 'Menu" cellspacing="' + nodeProperties.mainSpacing + '">';
  337. var strSub = '';
  338. var vertical;
  339. // draw the main menu items
  340. if (orient.charAt (0) == 'h')
  341. {
  342. str += '<tr>';
  343. vertical = true;
  344. }
  345. else
  346. {
  347. vertical = false;
  348. }
  349. var i;
  350. var item;
  351. var idSub;
  352. var hasChild;
  353. var classStr;
  354. for (i = 0; i < menu.length; ++i)
  355. {
  356. item = menu[i];
  357. if (!item)
  358. continue;
  359. item.menu = menu;
  360. item.subMenuID = id;
  361. str += vertical ? '<tr' : '<td';
  362. str += ' class="' + prefix + 'MainItem"';
  363. hasChild = (item.length > 5);
  364. idSub = hasChild ? cmNewID () : null;
  365. str += cmActionItem (item, 1, idSub, menuInfo, menuID) + '>';
  366. if (item == _cmSplit)
  367. item = cmSplitItem (prefix, 1, vertical);
  368. if (item[0] == _cmNoAction || item[0] == _cmNoClick)
  369. {
  370. str += cmNoActionItem (item);
  371. str += vertical? '</tr>' : '</td>';
  372. continue;
  373. }
  374. classStr = prefix + 'Main' + (hasChild ? 'Folder' : 'Item');
  375. str += vertical ? '<td' : '<span';
  376. str += ' class="' + classStr + 'Left">';
  377. str += (item[0] == null) ? (hasChild ? nodeProperties.mainFolderLeft : nodeProperties.mainItemLeft)
  378. : item[0];
  379. str += vertical ? '</td>' : '</span>';
  380. str += vertical ? '<td' : '<span';
  381. str += ' class="' + classStr + 'Text">';
  382. str += item[1];
  383. str += vertical ? '</td>' : '</span>';
  384. str += vertical ? '<td' : '<span';
  385. str += ' class="' + classStr + 'Right">';
  386. str += hasChild ? nodeProperties.mainFolderRight : nodeProperties.mainItemRight;
  387. str += vertical ? '</td>' : '</span>';
  388. str += vertical ? '</tr>' : '</td>';
  389. if (hasChild)
  390. strSub += cmDrawSubMenu (item, prefix, idSub, nodeProperties, nodeProperties.zIndexStart, menuInfo, menuID);
  391. }
  392. if (!vertical)
  393. str += '</tr>';
  394. str += '</table>' + strSub;
  395. obj.innerHTML = str;
  396. }
  397. //
  398. // The function builds the menu inside the specified element id.
  399. //
  400. // This function is similar to cmDraw except that menu is taken from HTML node
  401. // rather a javascript tree. This feature allows links to be scanned by search
  402. // bots.
  403. //
  404. // This function basically converts HTML node to a javascript tree, and then calls
  405. // cmDraw to draw the actual menu, replacing the hidden menu tree.
  406. //
  407. // Format:
  408. // <div id="menu">
  409. // <ul style="visibility: hidden">
  410. // <li><span>icon</span><a href="link" title="description">main menu text</a>
  411. // <ul>
  412. // <li><span>icon</span><a href="link" title="description">submenu item</a>
  413. // </li>
  414. // </ul>
  415. // </li>
  416. // </ul>
  417. // </div>
  418. //
  419. function cmDrawFromText (id, orient, nodeProperties, prefix)
  420. {
  421. var domMenu = cmGetObject (id);
  422. var menu = null;
  423. for (var currentDomItem = domMenu.firstChild; currentDomItem; currentDomItem = currentDomItem.nextSibling)
  424. {
  425. if (!currentDomItem.tagName)
  426. continue;
  427. var tag = currentDomItem.tagName.toLowerCase ();
  428. if (tag != 'ul' && tag != 'ol')
  429. continue;
  430. menu = cmDrawFromTextSubMenu (currentDomItem);
  431. break;
  432. }
  433. if (menu)
  434. cmDraw (id, menu, orient, nodeProperties, prefix);
  435. }
  436. //
  437. // a recursive function that build menu tree structure
  438. //
  439. function cmDrawFromTextSubMenu (domMenu)
  440. {
  441. var items = new Array ();
  442. for (var currentDomItem = domMenu.firstChild; currentDomItem; currentDomItem = currentDomItem.nextSibling)
  443. {
  444. if (!currentDomItem.tagName || currentDomItem.tagName.toLowerCase () != 'li')
  445. continue;
  446. if (currentDomItem.firstChild == null)
  447. {
  448. items[items.length] = _cmSplit;
  449. continue;
  450. }
  451. var item = new Array ();
  452. var currentItem = currentDomItem.firstChild;
  453. var hasAction = false;
  454. for (; currentItem; currentItem = currentItem.nextSibling)
  455. {
  456. // scan for span or div tag
  457. if (!currentItem.tagName)
  458. continue;
  459. if (currentItem.className == 'cmNoClick')
  460. {
  461. item[0] = _cmNoClick;
  462. item[1] = getActionHTML (currentItem);
  463. hasAction = true;
  464. break;
  465. }
  466. if (currentItem.className == 'cmNoAction')
  467. {
  468. item[0] = _cmNoAction;
  469. item[1] = getActionHTML (currentItem);
  470. hasAction = true;
  471. break;
  472. }
  473. var tag = currentItem.tagName.toLowerCase ();
  474. if (tag != 'span')
  475. continue;
  476. if (!currentItem.firstChild)
  477. item[0] = null;
  478. else
  479. item[0] = currentItem.innerHTML;
  480. currentItem = currentItem.nextSibling;
  481. break;
  482. }
  483. if (hasAction)
  484. {
  485. items[items.length] = item;
  486. continue;
  487. }
  488. if (!currentItem)
  489. continue;
  490. for (; currentItem; currentItem = currentItem.nextSibling)
  491. {
  492. if (!currentItem.tagName)
  493. continue;
  494. var tag = currentItem.tagName.toLowerCase ();
  495. if (tag == 'a')
  496. {
  497. item[1] = currentItem.innerHTML;
  498. item[2] = currentItem.href;
  499. item[3] = currentItem.target;
  500. item[4] = currentItem.title;
  501. if (item[4] == '')
  502. item[4] = null;
  503. }
  504. else if (tag == 'span' || tag == 'div')
  505. {
  506. item[1] = currentItem.innerHTML;
  507. item[2] = null;
  508. item[3] = null;
  509. item[4] = null;
  510. }
  511. break;
  512. }
  513. for (; currentItem; currentItem = currentItem.nextSibling)
  514. {
  515. // scan for span tag
  516. if (!currentItem.tagName)
  517. continue;
  518. var tag = currentItem.tagName.toLowerCase ();
  519. if (tag != 'ul' && tag != 'ol')
  520. continue;
  521. var subMenuItems = cmDrawFromTextSubMenu (currentItem);
  522. for (i = 0; i < subMenuItems.length; ++i)
  523. item[i + 5] = subMenuItems[i];
  524. break;
  525. }
  526. items[items.length] = item;
  527. }
  528. return items;
  529. }
  530. //
  531. // obtain the actual action item's action, which is inside a
  532. // table. The first row should be it
  533. //
  534. function getActionHTML (htmlNode)
  535. {
  536. var returnVal = '<td></td><td></td><td></td>';
  537. var currentDomItem;
  538. // find the table first
  539. for (currentDomItem = htmlNode.firstChild; currentDomItem; currentDomItem = currentDomItem.nextSibling)
  540. {
  541. if (currentDomItem.tagName && currentDomItem.tagName.toLowerCase () == 'table')
  542. break;
  543. }
  544. if (!currentDomItem)
  545. return returnVal;
  546. // skip over tbody
  547. for (currentDomItem = currentDomItem.firstChild; currentDomItem; currentDomItem = currentDomItem.nextSibling)
  548. {
  549. if (currentDomItem.tagName && currentDomItem.tagName.toLowerCase () == 'tbody')
  550. break;
  551. }
  552. if (!currentDomItem)
  553. return returnVal;
  554. // get the first tr
  555. for (currentDomItem = currentDomItem.firstChild; currentDomItem; currentDomItem = currentDomItem.nextSibling)
  556. {
  557. if (currentDomItem.tagName && currentDomItem.tagName.toLowerCase () == 'tr')
  558. break;
  559. }
  560. if (!currentDomItem)
  561. return returnVal;
  562. return currentDomItem.innerHTML;
  563. }
  564. //
  565. // get the DOM object associated with the item
  566. //
  567. function cmGetMenuItem (item)
  568. {
  569. if (!item.subMenuID)
  570. return null;
  571. var subMenu = cmGetObject (item.subMenuID);
  572. // we are dealing with a main menu item
  573. if (item.menu)
  574. {
  575. var menu = item.menu;
  576. // skip over table, tbody, tr, reach td
  577. subMenu = subMenu.firstChild.firstChild.firstChild.firstChild;
  578. var i;
  579. for (i = 0; i < menu.length; ++i)
  580. {
  581. if (menu[i] == item)
  582. return subMenu;
  583. subMenu = subMenu.nextSibling;
  584. }
  585. }
  586. else if (item.parentItem) // sub menu item
  587. {
  588. var menu = item.parentItem;
  589. var table = cmGetObject (item.subMenuID + 'Table');
  590. if (!table)
  591. return null;
  592. // skip over table, tbody, reach tr
  593. subMenu = table.firstChild.firstChild;
  594. var i;
  595. for (i = 5; i < menu.length; ++i)
  596. {
  597. if (menu[i] == item)
  598. return subMenu;
  599. subMenu = subMenu.nextSibling;
  600. }
  601. }
  602. return null;
  603. }
  604. //
  605. // disable a menu item
  606. //
  607. function cmDisableItem (item, prefix)
  608. {
  609. if (!item)
  610. return;
  611. var menuItem = cmGetMenuItem (item);
  612. if (!menuItem)
  613. return;
  614. if (item.menu)
  615. menuItem.className = prefix + 'MainItemDisabled';
  616. else
  617. menuItem.className = prefix + 'MenuItemDisabled';
  618. item.isDisabled = true;
  619. }
  620. //
  621. // enable a menu item
  622. //
  623. function cmEnableItem (item, prefix)
  624. {
  625. if (!item)
  626. return;
  627. var menuItem = cmGetMenuItem (item);
  628. if (!menuItem)
  629. return;
  630. if (item.menu)
  631. menu.className = prefix + 'MainItem';
  632. else
  633. menu.className = prefix + 'MenuItem';
  634. item.isDisabled = false;
  635. }
  636. //////////////////////////////////////////////////////////////////////
  637. //
  638. // Mouse Event Handling Functions
  639. //
  640. //////////////////////////////////////////////////////////////////////
  641. //
  642. // action should be taken for mouse moving in to the menu item
  643. //
  644. // Here we just do things concerning this menu item, w/o opening sub menus.
  645. //
  646. function cmItemMouseOver (obj, isMain, idSub, menuID, index, calledByOpenSub)
  647. {
  648. if (!calledByOpenSub && _cmClicked)
  649. {
  650. cmItemMouseOverOpenSub (obj, isMain, idSub, menuID, index);
  651. return;
  652. }
  653. clearTimeout (_cmTimeOut);
  654. if (_cmItemList[index].isDisabled)
  655. return;
  656. var prefix = _cmMenuList[menuID].prefix;
  657. if (!obj.cmMenuID)
  658. {
  659. obj.cmMenuID = menuID;
  660. obj.cmIsMain = isMain;
  661. }
  662. var thisMenu = cmGetThisMenu (obj, prefix);
  663. // insert obj into cmItems if cmItems doesn't have obj
  664. if (!thisMenu.cmItems)
  665. thisMenu.cmItems = new Array ();
  666. var i;
  667. for (i = 0; i < thisMenu.cmItems.length; ++i)
  668. {
  669. if (thisMenu.cmItems[i] == obj)
  670. break;
  671. }
  672. if (i == thisMenu.cmItems.length)
  673. {
  674. //thisMenu.cmItems.push (obj);
  675. thisMenu.cmItems[i] = obj;
  676. }
  677. // hide the previous submenu that is not this branch
  678. if (_cmCurrentItem)
  679. {
  680. // occationally, we get this case when user
  681. // move the mouse slowly to the border
  682. if (_cmCurrentItem == obj || _cmCurrentItem == thisMenu)
  683. {
  684. var item = _cmItemList[index];
  685. cmSetStatus (item);
  686. return;
  687. }
  688. var thatMenuInfo = _cmMenuList[_cmCurrentItem.cmMenuID];
  689. var thatPrefix = thatMenuInfo.prefix;
  690. var thatMenu = cmGetThisMenu (_cmCurrentItem, thatPrefix);
  691. if (thatMenu != thisMenu.cmParentMenu)
  692. {
  693. if (_cmCurrentItem.cmIsMain)
  694. _cmCurrentItem.className = thatPrefix + 'MainItem';
  695. else
  696. _cmCurrentItem.className = thatPrefix + 'MenuItem';
  697. if (thatMenu.id != idSub)
  698. cmHideMenu (thatMenu, thisMenu, thatMenuInfo);
  699. }
  700. }
  701. // okay, set the current menu to this obj
  702. _cmCurrentItem = obj;
  703. // just in case, reset all items in this menu to MenuItem
  704. cmResetMenu (thisMenu, prefix);
  705. var item = _cmItemList[index];
  706. var isDefaultItem = cmIsDefaultItem (item);
  707. if (isDefaultItem)
  708. {
  709. if (isMain)
  710. obj.className = prefix + 'MainItemHover';
  711. else
  712. obj.className = prefix + 'MenuItemHover';
  713. }
  714. cmSetStatus (item);
  715. }
  716. //
  717. // action should be taken for mouse moving in to the menu item
  718. //
  719. // This function also opens sub menu
  720. //
  721. function cmItemMouseOverOpenSub (obj, isMain, idSub, menuID, index)
  722. {
  723. clearTimeout (_cmTimeOut);
  724. if (_cmItemList[index].isDisabled)
  725. return;
  726. cmItemMouseOver (obj, isMain, idSub, menuID, index, true);
  727. if (idSub)
  728. {
  729. var subMenu = cmGetObject (idSub);
  730. var menuInfo = _cmMenuList[menuID];
  731. var orient = menuInfo.orient;
  732. var prefix = menuInfo.prefix;
  733. cmShowSubMenu (obj, isMain, subMenu, menuInfo);
  734. }
  735. }
  736. //
  737. // action should be taken for mouse moving out of the menu item
  738. //
  739. function cmItemMouseOut (obj, isMain, idSub, menuID, index)
  740. {
  741. var delayTime = _cmMenuList[menuID].nodeProperties.delay;
  742. _cmTimeOut = window.setTimeout ('cmHideMenuTime ()', delayTime);
  743. window.defaultStatus = '';
  744. }
  745. //
  746. // action should be taken for mouse button down at a menu item
  747. //
  748. function cmItemMouseDown (obj, isMain, idSub, menuID, index)
  749. {
  750. if (_cmItemList[index].isDisabled)
  751. return;
  752. if (cmIsDefaultItem (_cmItemList[index]))
  753. {
  754. var prefix = _cmMenuList[menuID].prefix;
  755. if (obj.cmIsMain)
  756. obj.className = prefix + 'MainItemActive';
  757. else
  758. obj.className = prefix + 'MenuItemActive';
  759. }
  760. }
  761. //
  762. // action should be taken for mouse button down at a menu item
  763. // this is one also opens submenu if needed
  764. //
  765. function cmItemMouseDownOpenSub (obj, isMain, idSub, menuID, index)
  766. {
  767. if (_cmItemList[index].isDisabled)
  768. return;
  769. _cmClicked = true;
  770. cmItemMouseDown (obj, isMain, idSub, menuID, index);
  771. if (idSub)
  772. {
  773. var subMenu = cmGetObject (idSub);
  774. var menuInfo = _cmMenuList[menuID];
  775. cmShowSubMenu (obj, isMain, subMenu, menuInfo);
  776. }
  777. }
  778. //
  779. // action should be taken for mouse button up at a menu item
  780. //
  781. function cmItemMouseUp (obj, isMain, idSub, menuID, index)
  782. {
  783. if (_cmItemList[index].isDisabled)
  784. return;
  785. var item = _cmItemList[index];
  786. var link = null, target = '_self';
  787. if (item.length > 2)
  788. link = item[2];
  789. if (item.length > 3 && item[3])
  790. target = item[3];
  791. if (link != null)
  792. {
  793. _cmClicked = false;
  794. window.open (link, target);
  795. }
  796. var menuInfo = _cmMenuList[menuID];
  797. var prefix = menuInfo.prefix;
  798. var thisMenu = cmGetThisMenu (obj, prefix);
  799. var hasChild = (item.length > 5);
  800. if (!hasChild)
  801. {
  802. if (cmIsDefaultItem (item))
  803. {
  804. if (obj.cmIsMain)
  805. obj.className = prefix + 'MainItem';
  806. else
  807. obj.className = prefix + 'MenuItem';
  808. }
  809. cmHideMenu (thisMenu, null, menuInfo);
  810. }
  811. else
  812. {
  813. if (cmIsDefaultItem (item))
  814. {
  815. if (obj.cmIsMain)
  816. obj.className = prefix + 'MainItemHover';
  817. else
  818. obj.className = prefix + 'MenuItemHover';
  819. }
  820. }
  821. }
  822. //////////////////////////////////////////////////////////////////////
  823. //
  824. // Mouse Event Support Utility Functions
  825. //
  826. //////////////////////////////////////////////////////////////////////
  827. //
  828. // move submenu to the appropriate location
  829. //
  830. function cmMoveSubMenu (obj, isMain, subMenu, menuInfo)
  831. {
  832. var orient = menuInfo.orient;
  833. var offsetAdjust;
  834. if (isMain)
  835. {
  836. if (orient.charAt (0) == 'h')
  837. offsetAdjust = menuInfo.nodeProperties.offsetHMainAdjust;
  838. else
  839. offsetAdjust = menuInfo.nodeProperties.offsetVMainAdjust;
  840. }
  841. else
  842. offsetAdjust = menuInfo.nodeProperties.offsetSubAdjust;
  843. if (!isMain && orient.charAt (0) == 'h')
  844. orient = 'v' + orient.charAt (1) + orient.charAt (2);
  845. var mode = String (orient);
  846. var p = subMenu.offsetParent;
  847. var subMenuWidth = cmGetWidth (subMenu);
  848. var horiz = cmGetHorizontalAlign (obj, mode, p, subMenuWidth);
  849. if (mode.charAt (0) == 'x')
  850. {
  851. if (mode.charAt (1) == 'b')
  852. subMenu.style.top = (cmGetYAt (obj, p) + cmGetHeight (obj) + offsetAdjust[1]) + 'px';
  853. else
  854. subMenu.style.top = (cmGetYAt (obj, p) - cmGetHeight (subMenu) - offsetAdjust[1]) + 'px';
  855. if (horiz == 'r')
  856. subMenu.style.left = (cmGetXAt (obj, p) + offsetAdjust[0]) + 'px';
  857. else
  858. subMenu.style.left = (cmGetXAt (obj, p) + cmGetWidth (obj) - subMenuWidth - offsetAdjust[0]) + 'px';
  859. }
  860. else
  861. {
  862. if (horiz == 'r')
  863. subMenu.style.left = (cmGetXAt (obj, p) + cmGetWidth (obj) + offsetAdjust[0]) + 'px';
  864. else
  865. subMenu.style.left = (cmGetXAt (obj, p) - subMenuWidth - offsetAdjust[0]) + 'px';
  866. if (mode.charAt (1) == 'b')
  867. subMenu.style.top = (cmGetYAt (obj, p) + offsetAdjust[1]) + 'px';
  868. else
  869. subMenu.style.top = (cmGetYAt (obj, p) + cmGetHeight (obj) - cmGetHeight (subMenu) + offsetAdjust[1]) + 'px';
  870. }
  871. // IE specific iframe masking method
  872. /*@cc_on
  873. @if (@_jscript_version >= 5.5)
  874. if (menuInfo.cmFrameMasking)
  875. {
  876. if (!subMenu.cmFrameObj)
  877. {
  878. var frameObj = cmAllocFrame ();
  879. subMenu.cmFrameObj = frameObj;
  880. }
  881. var frameObj = subMenu.cmFrameObj;
  882. frameObj.style.zIndex = subMenu.style.zIndex - 1;
  883. frameObj.style.left = (cmGetX (subMenu) - cmGetX (frameObj.offsetParent)) + 'px';
  884. frameObj.style.top = (cmGetY (subMenu) - cmGetY (frameObj.offsetParent)) + 'px';
  885. frameObj.style.width = cmGetWidth (subMenu) + 'px';
  886. frameObj.style.height = cmGetHeight (subMenu) + 'px';
  887. frameObj.style.display = 'block';
  888. }
  889. @end
  890. @*/
  891. if (horiz != orient.charAt (2))
  892. orient = orient.charAt (0) + orient.charAt (1) + horiz;
  893. return orient;
  894. }
  895. //
  896. // automatically re-adjust the menu position based on available screen size.
  897. //
  898. function cmGetHorizontalAlign (obj, mode, p, subMenuWidth)
  899. {
  900. var horiz = mode.charAt (2);
  901. if (!(document.body))
  902. return horiz;
  903. var body = document.body;
  904. var browserLeft;
  905. var browserRight;
  906. if (window.innerWidth)
  907. {
  908. // DOM window attributes
  909. browserLeft = window.pageXOffset;
  910. browserRight = window.innerWidth + browserLeft;
  911. }
  912. else if (body.clientWidth)
  913. {
  914. // IE attributes
  915. browserLeft = body.clientLeft;
  916. browserRight = body.clientWidth + browserLeft;
  917. }
  918. else
  919. return horiz;
  920. if (mode.charAt (0) == 'x')
  921. {
  922. if (horiz == 'r' && (cmGetXAt (obj) + subMenuWidth) > browserRight)
  923. horiz = 'l';
  924. if (horiz == 'l' && (cmGetXAt (obj) + cmGetWidth (obj) - subMenuWidth) < browserLeft)
  925. horiz = 'r';
  926. return horiz;
  927. }
  928. else
  929. {
  930. if (horiz == 'r' && (cmGetXAt (obj, p) + cmGetWidth (obj) + subMenuWidth) > browserRight)
  931. horiz = 'l';
  932. if (horiz == 'l' && (cmGetXAt (obj, p) - subMenuWidth) < browserLeft)
  933. horiz = 'r';
  934. return horiz;
  935. }
  936. }
  937. //
  938. // show the subMenu w/ specified orientation
  939. // also move it to the correct coordinates
  940. //
  941. function cmShowSubMenu (obj, isMain, subMenu, menuInfo)
  942. {
  943. var prefix = menuInfo.prefix;
  944. if (!subMenu.cmParentMenu)
  945. {
  946. // establish the tree w/ back edge
  947. var thisMenu = cmGetThisMenu (obj, prefix);
  948. subMenu.cmParentMenu = thisMenu;
  949. if (!thisMenu.cmSubMenu)
  950. thisMenu.cmSubMenu = new Array ();
  951. thisMenu.cmSubMenu[thisMenu.cmSubMenu.length] = subMenu;
  952. }
  953. var effectInstance = subMenu.cmEffect;
  954. if (effectInstance)
  955. effectInstance.showEffect (true);
  956. else
  957. {
  958. // position the sub menu only if we are not already showing the submenu
  959. var orient = cmMoveSubMenu (obj, isMain, subMenu, menuInfo);
  960. subMenu.cmOrient = orient;
  961. var forceShow = false;
  962. if (subMenu.style.visibility != 'visible' && menuInfo.nodeProperties.effect)
  963. {
  964. try
  965. {
  966. effectInstance = menuInfo.nodeProperties.effect.getInstance (subMenu, orient);
  967. effectInstance.showEffect (false);
  968. }
  969. catch (e)
  970. {
  971. forceShow = true;
  972. subMenu.cmEffect = null;
  973. }
  974. }
  975. else
  976. forceShow = true;
  977. if (forceShow)
  978. {
  979. subMenu.style.visibility = 'visible';
  980. /*@cc_on
  981. @if (@_jscript_version >= 5.5)
  982. if (subMenu.cmFrameObj)
  983. subMenu.cmFrameObj.style.display = 'block';
  984. @end
  985. @*/
  986. }
  987. }
  988. if (!_cmHideObjects)
  989. {
  990. _cmHideObjects = 2; // default = not hide, may change behavior later
  991. try
  992. {
  993. if (window.opera)
  994. {
  995. if (parseInt (navigator.appVersion) < 9)
  996. _cmHideObjects = 1;
  997. }
  998. }
  999. catch (e)
  1000. {
  1001. }
  1002. }
  1003. if (_cmHideObjects == 1)
  1004. {
  1005. if (!subMenu.cmOverlap)
  1006. subMenu.cmOverlap = new Array ();
  1007. cmHideControl ("IFRAME", subMenu);
  1008. cmHideControl ("OBJECT", subMenu);
  1009. }
  1010. }
  1011. //
  1012. // reset all the menu items to class MenuItem in thisMenu
  1013. //
  1014. function cmResetMenu (thisMenu, prefix)
  1015. {
  1016. if (thisMenu.cmItems)
  1017. {
  1018. var i;
  1019. var str;
  1020. var items = thisMenu.cmItems;
  1021. for (i = 0; i < items.length; ++i)
  1022. {
  1023. if (items[i].cmIsMain)
  1024. {
  1025. if (items[i].className == (prefix + 'MainItemDisabled'))
  1026. continue;
  1027. }
  1028. else
  1029. {
  1030. if (items[i].className == (prefix + 'MenuItemDisabled'))
  1031. continue;
  1032. }
  1033. if (items[i].cmIsMain)
  1034. str = prefix + 'MainItem';
  1035. else
  1036. str = prefix + 'MenuItem';
  1037. if (items[i].className != str)
  1038. items[i].className = str;
  1039. }
  1040. }
  1041. }
  1042. //
  1043. // called by the timer to hide the menu
  1044. //
  1045. function cmHideMenuTime ()
  1046. {
  1047. _cmClicked = false;
  1048. if (_cmCurrentItem)
  1049. {
  1050. var menuInfo = _cmMenuList[_cmCurrentItem.cmMenuID];
  1051. var prefix = menuInfo.prefix;
  1052. cmHideMenu (cmGetThisMenu (_cmCurrentItem, prefix), null, menuInfo);
  1053. _cmCurrentItem = null;
  1054. }
  1055. }
  1056. //
  1057. // Only hides this menu
  1058. //
  1059. function cmHideThisMenu (thisMenu, menuInfo)
  1060. {
  1061. var effectInstance = thisMenu.cmEffect;
  1062. if (effectInstance)
  1063. effectInstance.hideEffect (true);
  1064. else
  1065. {
  1066. thisMenu.style.visibility = 'hidden';
  1067. thisMenu.style.top = '0px';
  1068. thisMenu.style.left = '0px';
  1069. thisMenu.cmOrient = null;
  1070. /*@cc_on
  1071. @if (@_jscript_version >= 5.5)
  1072. if (thisMenu.cmFrameObj)
  1073. {
  1074. var frameObj = thisMenu.cmFrameObj;
  1075. frameObj.style.display = 'none';
  1076. frameObj.style.width = '1px';
  1077. frameObj.style.height = '1px';
  1078. thisMenu.cmFrameObj = null;
  1079. cmFreeFrame (frameObj);
  1080. }
  1081. @end
  1082. @*/
  1083. }
  1084. cmShowControl (thisMenu);
  1085. thisMenu.cmItems = null;
  1086. }
  1087. //
  1088. // hide thisMenu, children of thisMenu, as well as the ancestor
  1089. // of thisMenu until currentMenu is encountered. currentMenu
  1090. // will not be hidden
  1091. //
  1092. function cmHideMenu (thisMenu, currentMenu, menuInfo)
  1093. {
  1094. var prefix = menuInfo.prefix;
  1095. var str = prefix + 'SubMenu';
  1096. // hide the down stream menus
  1097. if (thisMenu.cmSubMenu)
  1098. {
  1099. var i;
  1100. for (i = 0; i < thisMenu.cmSubMenu.length; ++i)
  1101. {
  1102. cmHideSubMenu (thisMenu.cmSubMenu[i], menuInfo);
  1103. }
  1104. }
  1105. // hide the upstream menus
  1106. while (thisMenu && thisMenu != currentMenu)
  1107. {
  1108. cmResetMenu (thisMenu, prefix);
  1109. if (thisMenu.className == str)
  1110. {
  1111. cmHideThisMenu (thisMenu, menuInfo);
  1112. }
  1113. else
  1114. break;
  1115. thisMenu = cmGetThisMenu (thisMenu.cmParentMenu, prefix);
  1116. }
  1117. }
  1118. //
  1119. // hide thisMenu as well as its sub menus if thisMenu is not
  1120. // already hidden
  1121. //
  1122. function cmHideSubMenu (thisMenu, menuInfo)
  1123. {
  1124. if (thisMenu.style.visibility == 'hidden')
  1125. return;
  1126. if (thisMenu.cmSubMenu)
  1127. {
  1128. var i;
  1129. for (i = 0; i < thisMenu.cmSubMenu.length; ++i)
  1130. {
  1131. cmHideSubMenu (thisMenu.cmSubMenu[i], menuInfo);
  1132. }
  1133. }
  1134. var prefix = menuInfo.prefix;
  1135. cmResetMenu (thisMenu, prefix);
  1136. cmHideThisMenu (thisMenu, menuInfo);
  1137. }
  1138. //
  1139. // hide a control such as IFRAME
  1140. //
  1141. function cmHideControl (tagName, subMenu)
  1142. {
  1143. var x = cmGetX (subMenu);
  1144. var y = cmGetY (subMenu);
  1145. var w = subMenu.offsetWidth;
  1146. var h = subMenu.offsetHeight;
  1147. var i;
  1148. for (i = 0; i < document.all.tags(tagName).length; ++i)
  1149. {
  1150. var obj = document.all.tags(tagName)[i];
  1151. if (!obj || !obj.offsetParent)
  1152. continue;
  1153. // check if the object and the subMenu overlap
  1154. var ox = cmGetX (obj);
  1155. var oy = cmGetY (obj);
  1156. var ow = obj.offsetWidth;
  1157. var oh = obj.offsetHeight;
  1158. if (ox > (x + w) || (ox + ow) < x)
  1159. continue;
  1160. if (oy > (y + h) || (oy + oh) < y)
  1161. continue;
  1162. // if object is already made hidden by a different
  1163. // submenu then we dont want to put it on overlap list of
  1164. // of a submenu a second time.
  1165. // - bug fixed by Felix Zaslavskiy
  1166. if(obj.style.visibility == 'hidden')
  1167. continue;
  1168. //subMenu.cmOverlap.push (obj);
  1169. subMenu.cmOverlap[subMenu.cmOverlap.length] = obj;
  1170. obj.style.visibility = 'hidden';
  1171. }
  1172. }
  1173. //
  1174. // show the control hidden by the subMenu
  1175. //
  1176. function cmShowControl (subMenu)
  1177. {
  1178. if (subMenu.cmOverlap)
  1179. {
  1180. var i;
  1181. for (i = 0; i < subMenu.cmOverlap.length; ++i)
  1182. subMenu.cmOverlap[i].style.visibility = "";
  1183. }
  1184. subMenu.cmOverlap = null;
  1185. }
  1186. //
  1187. // returns the main menu or the submenu table where this obj (menu item)
  1188. // is in
  1189. //
  1190. function cmGetThisMenu (obj, prefix)
  1191. {
  1192. var str1 = prefix + 'SubMenu';
  1193. var str2 = prefix + 'Menu';
  1194. while (obj)
  1195. {
  1196. if (obj.className == str1 || obj.className == str2)
  1197. return obj;
  1198. obj = obj.parentNode;
  1199. }
  1200. return null;
  1201. }
  1202. //
  1203. // A special effect function to hook the menu which contains
  1204. // special effect object to the timer.
  1205. //
  1206. function cmTimeEffect (menuID, show, delayTime)
  1207. {
  1208. window.setTimeout ('cmCallEffect("' + menuID + '",' + show + ')', delayTime);
  1209. }
  1210. //
  1211. // A special effect function. Called by timer.
  1212. //
  1213. function cmCallEffect (menuID, show)
  1214. {
  1215. var menu = cmGetObject (menuID);
  1216. if (!menu || !menu.cmEffect)
  1217. return;
  1218. try
  1219. {
  1220. if (show)
  1221. menu.cmEffect.showEffect (false);
  1222. else
  1223. menu.cmEffect.hideEffect (false);
  1224. }
  1225. catch (e)
  1226. {
  1227. }
  1228. }
  1229. //
  1230. // return true if this item is handled using default handlers
  1231. //
  1232. function cmIsDefaultItem (item)
  1233. {
  1234. if (item == _cmSplit || item[0] == _cmNoAction || item[0] == _cmNoClick)
  1235. return false;
  1236. return true;
  1237. }
  1238. //
  1239. // returns the object baring the id
  1240. //
  1241. function cmGetObject (id)
  1242. {
  1243. if (document.all)
  1244. return document.all[id];
  1245. return document.getElementById (id);
  1246. }
  1247. //
  1248. // functions that obtain the width of an HTML element.
  1249. //
  1250. function cmGetWidth (obj)
  1251. {
  1252. var width = obj.offsetWidth;
  1253. if (width > 0 || !cmIsTRNode (obj))
  1254. return width;
  1255. if (!obj.firstChild)
  1256. return 0;
  1257. // use TABLE's length can cause an extra pixel gap
  1258. //return obj.parentNode.parentNode.offsetWidth;
  1259. // use the left and right child instead
  1260. return obj.lastChild.offsetLeft - obj.firstChild.offsetLeft + cmGetWidth (obj.lastChild);
  1261. }
  1262. //
  1263. // functions that obtain the height of an HTML element.
  1264. //
  1265. function cmGetHeight (obj)
  1266. {
  1267. var height = obj.offsetHeight;
  1268. if (height > 0 || !cmIsTRNode (obj))
  1269. return height;
  1270. if (!obj.firstChild)
  1271. return 0;
  1272. // use the first child's height
  1273. return obj.firstChild.offsetHeight;
  1274. }
  1275. //
  1276. // functions that obtain the coordinates of an HTML element
  1277. //
  1278. function cmGetX (obj)
  1279. {
  1280. if (!obj)
  1281. return 0;
  1282. var x = 0;
  1283. do
  1284. {
  1285. x += obj.offsetLeft;
  1286. obj = obj.offsetParent;
  1287. }
  1288. while (obj);
  1289. return x;
  1290. }
  1291. function cmGetXAt (obj, elm)
  1292. {
  1293. var x = 0;
  1294. while (obj && obj != elm)
  1295. {
  1296. x += obj.offsetLeft;
  1297. obj = obj.offsetParent;
  1298. }
  1299. if (obj == elm)
  1300. return x;
  1301. return x - cmGetX (elm);
  1302. }
  1303. function cmGetY (obj)
  1304. {
  1305. if (!obj)
  1306. return 0;
  1307. var y = 0;
  1308. do
  1309. {
  1310. y += obj.offsetTop;
  1311. obj = obj.offsetParent;
  1312. }
  1313. while (obj);
  1314. return y;
  1315. }
  1316. function cmIsTRNode (obj)
  1317. {
  1318. var tagName = obj.tagName;
  1319. return tagName == "TR" || tagName == "tr" || tagName == "Tr" || tagName == "tR";
  1320. }
  1321. //
  1322. // get the Y position of the object. In case of TR element though,
  1323. // we attempt to adjust the value.
  1324. //
  1325. function cmGetYAt (obj, elm)
  1326. {
  1327. var y = 0;
  1328. if (!obj.offsetHeight && cmIsTRNode (obj))
  1329. {
  1330. var firstTR = obj.parentNode.firstChild;
  1331. obj = obj.firstChild;
  1332. y -= firstTR.firstChild.offsetTop;
  1333. }
  1334. while (obj && obj != elm)
  1335. {
  1336. y += obj.offsetTop;
  1337. obj = obj.offsetParent;
  1338. }
  1339. if (obj == elm)
  1340. return y;
  1341. return y - cmGetY (elm);
  1342. }
  1343. //
  1344. // extract description from the menu item and set the status text
  1345. //
  1346. function cmSetStatus (item)
  1347. {
  1348. var descript = '';
  1349. if (item.length > 4)
  1350. descript = (item[4] != null) ? item[4] : (item[2] ? item[2] : descript);
  1351. else if (item.length > 2)
  1352. descript = (item[2] ? item[2] : descript);
  1353. window.defaultStatus = descript;
  1354. }
  1355. //
  1356. // debug function, ignore :)
  1357. //
  1358. function cmGetProperties (obj)
  1359. {
  1360. if (obj == undefined)
  1361. return 'undefined';
  1362. if (obj == null)
  1363. return 'null';
  1364. var msg = obj + ':\n';
  1365. var i;
  1366. for (i in obj)
  1367. msg += i + ' = ' + obj[i] + '; ';
  1368. return msg;
  1369. }
  1370. /* v2.0.4 1. Fixed the bug that cmEnableItem setting the wrong isDisabled value.
  1371. 2. Fixed a missing semicolon issue.
  1372. */
  1373. /* v2.0.3 1. Fix an issue with IE6 displaying menu over HTTPS connection.
  1374. Thanks to Paul Horton for reporting the bug and testing
  1375. possible solutions.
  1376. */
  1377. /* v2.0.2 1. Minor clean up and some attempts to reduce memory leak in IE.
  1378. */
  1379. /* v2.0.1 1. Disable iframe masking for IE7 since it is no longer necessary.
  1380. */
  1381. /* v2.0 1. improves the way handling flash/iframe/select boxes in IE
  1382. and firefox and Opera 9. Hiding these elements is no
  1383. longer necessary. For older versions of Opera, flash/iframe
  1384. still need to be hidden.
  1385. 2. Improves cmDrawFromText (). Also allows custom actions.
  1386. 3. Improves clickOpen behavior. Now once a submenu is opened,
  1387. opening other sub menus no longer requires clicking.
  1388. 4. Special Effects. This version has hooks that allow people
  1389. to install special effects to various themes.
  1390. 5. For a given menu item, cmGetMenuitem(item) provides the ability
  1391. to find the corresponding DOM element.
  1392. 6. Disable API. If you know which item to disable, you can call
  1393. cmDisableItem(item, themePrefix) and cmEnableItem(item, themePrefix).
  1394. However, you will have to provide your own CSS for the item.
  1395. For purposes other than to disable an item, cmGetMenuItem (item)
  1396. is provided for locating HTML DOM element of the menu item in concern.
  1397. 7. Better z-index. Now you can specify in the theme property the
  1398. starting z-index and incremental step for submenus.
  1399. 8. Allow themes to insert additional elements before and after
  1400. the sub menu table.
  1401. 9. Improved themes. More organized and easier to customize.
  1402. 10. Add a flag to control hiding/nohiding objects/iframes. By default,
  1403. only Opera before 9 hides objects.
  1404. 11. Add new property options to control submenu positions to fine tune
  1405. the look.
  1406. 12. It is no longer necessary to specify the theme name while calling
  1407. cmDraw and cmDrawFromText. Currently it still accepts it, but it
  1408. will not in the future.
  1409. */
  1410. /* v1.4.4 1. a quick fix for a bug for _cmSplit checking. reported by
  1411. Son Nguyen.
  1412. */
  1413. /* v1.4.3 1. changed how _cmSplit is handled a bit so that _cmNoClick can work
  1414. properly. All splits in predefined themes are changed to use
  1415. _cmNoClick instead of _cmNoAction.
  1416. */
  1417. /* v1.4.2 1. fixed _cmNoClick mouse hoover bug.
  1418. 2. fixed a statusbar text problem that cause text to disappear when
  1419. hoovering mouse within the same menu item.
  1420. 3. changed the behavior of cmDrawFromText s.t. if the title of the
  1421. of a link is empty, the actual url is used as text. To clear
  1422. this link information, title needs to be ' '.
  1423. */
  1424. /* v1.4.1 1. fixed a problem introduced in 1.4 where re-entering a main menu
  1425. item which doesn't have a child can disable its hover setting.
  1426. Apparently I deleted an extra line of code when I was doing
  1427. cleaning up. Reported by David Maliachi and a few others.
  1428. */
  1429. /* JSCookMenu v1.4 1. fixed a minor td cell closure problem. Thanks to Georg Lorenz
  1430. <georg@lonux.de> for discovering that.
  1431. 2. added clickOpen to nodeProperties. See _cmNodeProperties for
  1432. description. Basically menus can be opened on click only.
  1433. 3. added an ability to draw menu from an html node instead of a javascript
  1434. tree, making this script search bot friendly (I hope?).
  1435. */
  1436. /* JSCookMenu v1.31 1. fix a bug on IE with causes submenus to display at the top
  1437. left corner due to doctype. The fix was provided by
  1438. Burton Strauss <Burton@ntopsupport.com>.
  1439. */
  1440. /* JSCookMenu v1.3 1. automatically realign (left and right) the submenu when
  1441. client space is not enough.
  1442. 2. add _cmNoClick to get rid of menu closing behavior
  1443. on the particular menu item, to make it possible for things
  1444. such as search box to be inside the menu.
  1445. */
  1446. /* JSCookMenu v1.25 1. fix Safari positioning issue. The problem is that all TR elements are located
  1447. at the top left corner. Thus, need to obtain the "virtual"
  1448. position of these element could be at.
  1449. */
  1450. /* JSCookMenu v1.24 1. fix window based control hiding bug
  1451. thanks to Felix Zaslavskiy <felix@bebinary.com> for the fix.
  1452. */
  1453. /* JSCookMenu v1.23 1. correct a position bug when the container is positioned.
  1454. thanks to Andre <anders@netspace.net.au> for narrowing down
  1455. the problem.
  1456. */
  1457. /* JSCookMenu v1.22 1. change Array.push (obj) call to Array[length] = obj.
  1458. Suggestion from Dick van der Kaaden <dick@netrex.nl> to
  1459. make the script compatible with IE 5.0
  1460. 2. Changed theme files a little to add z-index: 100 for sub
  1461. menus. This change is necessary for Netscape to avoid
  1462. a display problem.
  1463. 3. some changes to the DOM structure to make this menu working
  1464. on Netscape 6.0 (tested). The main reason is that NN6 does
  1465. not do absolute positioning with tables. Therefore an extra
  1466. div layer must be put around the table.
  1467. */
  1468. /* JSCookMenu v1.21 1. fixed a bug that didn't add 'px' as part of coordinates.
  1469. JSCookMenu should be XHTML validator friendly now.
  1470. 2. removed unnecessary display attribute and corresponding
  1471. theme entry to fix a problem that Netscape sometimes
  1472. render Office theme incorrectly
  1473. */
  1474. /* JSCookMenu v1.2. 1. fix the problem of showing status in Netscape
  1475. 2. changed the handler parameters a bit to allow
  1476. string literals to be passed to javascript based
  1477. links
  1478. 3. having null in target field would cause the link
  1479. to be opened in the current window, but this behavior
  1480. could change in the future releases
  1481. */
  1482. /* JSCookMenu v1.1. added ability to hide controls in IE to show submenus properly */
  1483. /* JSCookMenu v1.01. cmDraw generates XHTML code */
  1484. /* JSCookMenu v1.0. (c) Copyright 2002 by Heng Yuan */