calendar_lw_menu.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. // written by Tan Ling Wee
  2. // last updated 20 June 2003
  3. // email : [email protected]
  4. var orientation=0 // 0-horizontal 1-vertical
  5. var imgPath = "js/"
  6. var mainItemForeground = "#000000"
  7. var mainItemBorder = "#f0f0f0"
  8. var mainItemBackground = "#f0f0f0"
  9. var mainItemHoverForeground = "#000000"
  10. var mainItemHoverBorder = "#a0a0a0"
  11. var mainItemHoverBackground = "#d0d0d0"
  12. var subItemForeground = "#000000"
  13. var subItemBorder = "#ffffff"
  14. var subItemBackground = "#ffffff"
  15. var subItemHoverForeground = "#000000"
  16. var subItemHoverBorder = "#a0a0a0"
  17. var subItemHoverBackground = "#d0d0d0"
  18. var menuFont = "verdana"
  19. var menuSize = "11px"
  20. /////////////////////////////////////////////////////////////////////////////
  21. var ie=(navigator.appName=='Microsoft Internet Explorer')
  22. var ns=(navigator.appName=='Netscape')
  23. var dom=document.getElementById
  24. var lw_menuId, lw_trigger, to1
  25. var s1
  26. /////////////////////////////////////////////////////////////////////////////
  27. function Tmenu (id, parentId, url, description, img) {
  28. this.id = id
  29. this.parentId = parentId
  30. this.url = url
  31. this.description = description
  32. this.numChild = 0
  33. this.levelId = 0
  34. this.img = img
  35. }
  36. /////////////////////////////////////////////////////////////////////////////
  37. var menu = new Array()
  38. var menuCounter = 0
  39. var numLevel = 0
  40. var prevMenuId = -1
  41. var nNowAt = 0
  42. function displayMenuItem(menuId) {
  43. var sHTML
  44. if (menu[menuId].parentId>0)
  45. {
  46. ItemForeground = subItemForeground
  47. Border = subItemBorder
  48. Background = subItemBackground
  49. HoverForeground = subItemHoverForeground
  50. HoverBorder = subItemHoverBorder
  51. HoverBackground = subItemHoverBackground
  52. }
  53. else
  54. {
  55. ItemForeground = mainItemForeground
  56. Border = mainItemBorder
  57. Background = mainItemBackground
  58. HoverForeground = mainItemHoverForeground
  59. HoverBorder = mainItemHoverBorder
  60. HoverBackground = mainItemHoverBackground
  61. }
  62. if ((orientation==1)||(menu[menuId].levelId>0))
  63. {
  64. sHTML += "<tr>"
  65. }
  66. if (menu[menuId].description!='-')
  67. {
  68. sHTML = "<td valign='top' id='menu_"+menuId+"' style='cursor:pointer;cursor:hand;border-style:solid;border-width:1px;background-color:"+ Background +";color=\""+ ItemForeground +"\";border-color:"+ Border +"' onmouseover='clearInterval(s1);this.style.backgroundColor=\"" + HoverBackground + "\";this.style.color=\"" + HoverForeground + "\";this.style.borderColor=\"" + HoverBorder + "\";"
  69. if (menu[menuId].numChild!=0) {
  70. sHTML += "showSubmenu("+menu[menuId].id+",this);hideSubmenu(menu["+menuId+"].levelId+1);"
  71. }
  72. else
  73. {
  74. sHTML += "prevMenuId = "+menuId+";hideSubmenu(menu["+menuId+"].levelId);"
  75. }
  76. sHTML += ";nNowAt="+menuId+";clearAll("+menu[menuId].levelId+","+menu[menuId].parentId+")' onclick='document.location.href=\""+menu[menuId].url+"\"' onmouseout='s1=setInterval(\"resetMenu();hideSubmenu(0)\",1000);'><table cellpadding=0 cellspacing=0 border=0 width='100%'><tr>"
  77. if (menu[menuId].levelId>0)
  78. {
  79. sHTML += "<td valign='bottom' style='padding-left:3px' width=20><img src='"
  80. if (menu[menuId].img=="")
  81. {
  82. sHTML += imgPath + "trans.gif"
  83. }
  84. else
  85. {
  86. sHTML += imgPath + menu[menuId].img
  87. }
  88. sHTML += "' width=16 height=16 border=0></td>"
  89. }
  90. if ((orientation==0) && (menu[menuId].levelId==0))
  91. {
  92. nArrowWidth = 0
  93. }
  94. else
  95. {
  96. nArrowWidth = 25
  97. }
  98. sHTML += "<td valign='bottom' style='padding-left:5px;padding-right:5px' align=left>" + menu[menuId].description.replace(" ","&nbsp;") + "</td><td style='padding-right:2px' align=right width="+nArrowWidth+">"
  99. if (menu[menuId].numChild>0)
  100. {
  101. if ((orientation==0)&&(menu[menuId].levelId==0))
  102. {
  103. sHTML += "<img src='" + imgPath + "arrow_down.gif'>"
  104. }
  105. else
  106. {
  107. sHTML += "<img src='" + imgPath + "arrow_right.gif'>"
  108. }
  109. }
  110. else
  111. {
  112. sHTML += "&nbsp;"
  113. }
  114. sHTML += "</td></tr></table></td>"
  115. }
  116. else
  117. {
  118. sHTML = "<td valign='bottom'><img src='" + imgPath + "trans.gif' height=2></td></tr><tr><td onmouseover='' bgcolor='#d0d0d0'><img src='" + imgPath + "trans.gif' height=1></td></tr><tr><td><img src='" + imgPath + "trans.gif' height=2></td>"
  119. }
  120. if ((orientation==1)||(menu[menuId].levelId>0))
  121. {
  122. sHTML += "</tr>"
  123. }
  124. return sHTML
  125. }
  126. function clearAll(levelId, parentId) {
  127. if (levelId>0)
  128. {
  129. Border = subItemBorder
  130. Background = subItemBackground
  131. }
  132. else
  133. {
  134. Border = mainItemBorder
  135. Background = mainItemBackground
  136. }
  137. for (i=0;i<menuCounter;i++)
  138. {
  139. if (menu[i].levelId==levelId)
  140. {
  141. if ((i!=nNowAt) && (menu[i].parentId==parentId) && (menu[i].description!="-")) {
  142. lw_getObj("menu_"+i).backgroundColor=Background;
  143. lw_getObj("menu_"+i).borderColor=Border
  144. }
  145. }
  146. }
  147. }
  148. function mapID (id) {
  149. for (var i=0;i<menuCounter;i++)
  150. {
  151. if (menu[i].id==id)
  152. {
  153. return i
  154. }
  155. }
  156. return -1
  157. }
  158. function showSubmenu(menuId,trigger) {
  159. lw_menuId = menuId
  160. lw_trigger = trigger
  161. if (ns)
  162. {
  163. to1 = setTimeout("showActualSubmenu(lw_menuId,lw_trigger)",50)
  164. }
  165. else
  166. {
  167. showActualSubmenu(lw_menuId,lw_trigger)
  168. }
  169. }
  170. function showActualSubmenu(menuId,trigger) {
  171. var nLevel = 0
  172. var leftpos = 0
  173. var nIndex=0
  174. if (menuId>0)
  175. {
  176. lw_calcpos(trigger)
  177. for (var i=0;i<menuCounter;i++)
  178. {
  179. if (menu[i].id==menuId)
  180. {
  181. nLevel = menu[i].levelId
  182. nIndex = i
  183. }
  184. }
  185. if ((orientation==1)||(menu[nIndex].parentId>0))
  186. {
  187. lw_getObj("menu_level_"+nLevel).top=lw_toppos
  188. leftpos = lw_leftpos + lw_width + 5
  189. if (nLevel==0) {
  190. leftpos -= 3
  191. }
  192. }
  193. else {
  194. lw_getObj("menu_level_"+nLevel).top = lw_toppos + lw_height + 2
  195. leftpos = lw_leftpos
  196. }
  197. lw_getObj("menu_level_"+nLevel).left=leftpos
  198. sHTML = "<table cellpadding=0 cellspacing=0 border=1>"
  199. for (var i=0;i<menuCounter;i++)
  200. {
  201. if (menu[i].parentId==menuId)
  202. {
  203. sHTML += displayMenuItem (i)
  204. }
  205. }
  206. sHTML += "</table>"
  207. document.getElementById("menu_level_"+nLevel+"_content").innerHTML=sHTML
  208. lw_showLayer('menu_level_'+nLevel)
  209. }
  210. }
  211. function hideSubmenu(levelId) {
  212. for (var cnt=levelId; cnt<numLevel; cnt++)
  213. {
  214. lw_hideLayerName("menu_level_"+cnt)
  215. }
  216. }
  217. function DrawMenu () {
  218. for (var i=0; i<numLevel ; i++)
  219. {
  220. lw_createLayer("menu_level_"+i,0,0,0,0,"#ffffff","#d0d0d0",100)
  221. }
  222. sHTML="<table width=100% cellpadding=2 cellspacing=0>"
  223. for (var i=0; i<menuCounter; i++)
  224. {
  225. if (menu[i].parentId==0)
  226. {
  227. sHTML += displayMenuItem (i)
  228. }
  229. else if (menu[i].parentId==-1)
  230. {
  231. sHTML += "<tr><td valign='top'><img src='trans' height=2></td></tr><tr bgcolor='"+mainItemBackground+"'><td style='padding:5px'><b>" + menu[i].description + "</b></td></tr>"
  232. }
  233. }
  234. sHTML += "</table>"
  235. document.writeln(sHTML)
  236. }
  237. function getLevel (menuId) {
  238. var pId=menuId
  239. var nLevel=0
  240. while (pId!=0)
  241. {
  242. nLevel++
  243. for (var i=0;i<menuCounter;i++)
  244. {
  245. if (menu[i].id==pId)
  246. {
  247. pId = menu[i].parentId
  248. }
  249. }
  250. }
  251. return nLevel
  252. }
  253. function AddMenuItem (id, parentId, url, description, img) {
  254. menu[menuCounter++] = new Tmenu (id, parentId, url, description, img)
  255. if (parentId>0)
  256. {
  257. for (i=0;i<menuCounter;i++)
  258. {
  259. if (menu[i].id==parentId)
  260. {
  261. menu[i].numChild++
  262. }
  263. }
  264. menu[menuCounter-1].levelId = getLevel(parentId)
  265. if ( numLevel < menu[menuCounter-1].levelId)
  266. {
  267. numLevel = menu[menuCounter-1].levelId
  268. }
  269. }
  270. else if (parentId==0)
  271. {
  272. menu[menuCounter-1].levelId = 0
  273. }
  274. else
  275. {
  276. menu[menuCounter-1].levelId = -1
  277. }
  278. }
  279. function handleonclick() {
  280. if (ns)
  281. {
  282. lw_closeAllLayers()
  283. }
  284. else
  285. {
  286. lw_closeAllLayers(event)
  287. }
  288. resetMenu()
  289. }
  290. function handlekeypress(e) {
  291. if (ns)
  292. {
  293. var keyCode = e.keyCode?e.keyCode:e.which?e.which:e.charCode;
  294. if ((keyCode==27)||(keyCode==1))
  295. {
  296. handleonclick()
  297. }
  298. }
  299. else
  300. if ((event.keyCode==0)||(event.keyCode==27))
  301. {
  302. handleonclick()
  303. }
  304. resetMenu()
  305. }
  306. function resetMenu () {
  307. for (i=0;i<menuCounter;i++)
  308. {
  309. if (menu[i].levelId==0)
  310. {
  311. lw_getObj("menu_"+i).backgroundColor=mainItemBackground
  312. lw_getObj("menu_"+i).borderColor=mainItemBorder
  313. }
  314. }
  315. }
  316. document.onkeypress = handlekeypress
  317. document.onclick = handleonclick