Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

543 lines
14 KiB

  1. <PUBLIC:COMPONENT>
  2. <PUBLIC:PROPERTY NAME="menudata" />
  3. <PUBLIC:METHOD NAME="show_flyout" />
  4. <PUBLIC:METHOD NAME="kill_flyout" />
  5. <PUBLIC:METHOD NAME="scroll" />
  6. <PUBLIC:ATTACH EVENT="ondocumentready" ONEVENT="event_ondocumentready()" />
  7. <SCRIPT language="JScript">
  8. // Copyright � 2001 Microsoft Corporation
  9. var IMAGES = "/library/flyoutmenu/images/"
  10. var MENU_WIDTH = 180
  11. var MENU_BORDER_COLOR = '#C7D8FA'
  12. var MENU_BACKGROUND_COLOR = '#C7D8FA'
  13. var MENU_CURRENTPAGE_COLOR = '#C7D8FA'
  14. var MENU_MOUSEOVER_COLOR = '#C7D8FA'
  15. var MENU_MOUSEDOWN_COLOR = '#C7D8FA'
  16. var MENU_SHADOW_COLOR = '#C7D8FA'
  17. var FLYOUT_DELAY = 200
  18. var KILL_DELAY = 300
  19. var SCROLL_DELAY = 35
  20. var SCROLL_PXPERSEC = 150
  21. var MIN_FLYOUT_WIDTH = 100
  22. var MAX_FLYOUT_WIDTH = 410
  23. var global = window.document
  24. global.fo_currentMenu = null
  25. global.fo_shadows = new Array
  26. global.fo_killTimer = null
  27. var flyoutTimer = null
  28. var scrollTimer = null
  29. var flyoutCount = 0
  30. var flyouts = new Array
  31. var rowHeight = 0
  32. var menuToShow = null
  33. var scrollDelta = 0
  34. var scrollStart = 0
  35. var scrollTime = 0
  36. var scrollArea = null
  37. var upEnabled = new Image()
  38. var upDisabled = new Image()
  39. var downEnabled = new Image()
  40. var downDisabled = new Image()
  41. function newid()
  42. {
  43. var id
  44. do
  45. id = 'id' + Math.random().toString().substr(2, 10)
  46. while (global.all(id))
  47. return id
  48. }
  49. function event_ondocumentready()
  50. {
  51. if (!global.firstFlyoutInstance)
  52. {
  53. global.firstFlyoutInstance = true
  54. global.body.attachEvent("onmousemove", body_onmousemove)
  55. upEnabled.src = IMAGES + "up_enabled.gif"
  56. upDisabled.src = IMAGES + "up_disabled.gif"
  57. downEnabled.src = IMAGES + "down_enabled.gif"
  58. downDisabled.src = IMAGES + "down_disabled.gif"
  59. }
  60. if (this.id == '')
  61. this.id = newid()
  62. var mdd = null
  63. if (menudata)
  64. if (menudata.substr(0, 1) == '#')
  65. mdd = eval(menudata.substr(1)).XMLDocument.documentElement
  66. else
  67. {
  68. var md = new ActiveXObject("MSXML.DOMDocument")
  69. md.async = false
  70. md.load(menudata)
  71. if (md.parseError.errorCode == 0)
  72. mdd = md.documentElement
  73. }
  74. var items = this.all.tags("TD")
  75. var i
  76. var nParentItem = 0
  77. var nParentLen = -1
  78. var lhref = normalized_href(location.href)
  79. for (i=0; i<items.length; i++)
  80. {
  81. var item = items[i]
  82. if (item.className == "flyoutLink" || item.className == "flyoutLinkMail")
  83. {
  84. var disabled = false
  85. var anchors = item.all.tags("A")
  86. if (anchors.length > 0)
  87. {
  88. var anchor = anchors.item(0)
  89. var ahref = normalized_href(anchor.href)
  90. if (ahref == lhref)
  91. {
  92. anchor.outerHTML = anchor.innerHTML
  93. item.style.borderColor = MENU_BORDER_COLOR
  94. item.style.backgroundColor = MENU_CURRENTPAGE_COLOR
  95. item.style.cursor = 'default'
  96. disabled = true
  97. nParentItem = 0
  98. nParentLen = 9999
  99. }
  100. else
  101. {
  102. var slash = ahref.lastIndexOf("/")
  103. if (slash == ahref.length - 1)
  104. if (lhref.substr(0, slash + 1) == ahref)
  105. if (ahref.length > nParentLen)
  106. {
  107. nParentItem = i
  108. nParentLen = ahref.length
  109. }
  110. }
  111. }
  112. item.defaultBorder = item.style.borderColor
  113. item.defaultBackground = item.style.backgroundColor
  114. item.attachEvent("onmouseover", item_onmouseover)
  115. item.attachEvent("onmouseout", item_onmouseout)
  116. if (!disabled)
  117. {
  118. item.attachEvent("onmousedown", item_onmousedown)
  119. item.attachEvent("onmouseup", item_onmouseup)
  120. }
  121. if (item.handle && mdd)
  122. {
  123. var sm = mdd.selectSingleNode("//submenu[@handle='" + item.handle + "']")
  124. if (sm)
  125. {
  126. var fa = document.createElement("img")
  127. fa.src = IMAGES + "flyout_arrow.gif"
  128. fa.width = 4
  129. fa.height = 7
  130. fa.style.position = "absolute"
  131. fa.style.top = element_top(item) + 6
  132. fa.style.left = MENU_WIDTH - 15
  133. fa.flyoutArrow = true
  134. global.body.insertAdjacentElement("beforeEnd", fa)
  135. var table = document.createElement("table") //submenu
  136. table.attachEvent("onmouseover", submenu_onmouseover)
  137. table.attachEvent("onmouseout", submenu_onmouseout)
  138. table.width = MAX_FLYOUT_WIDTH + 6
  139. table.cellPadding = 0
  140. table.cellSpacing = 0
  141. table.className = "flyoutMenu"
  142. table.style.border = "solid 1px " + MENU_BORDER_COLOR
  143. table.style.position = "absolute"
  144. table.style.left = MENU_WIDTH - 4
  145. table.style.top = 0
  146. table.baseTop = fa.style.posTop - 9
  147. cell = table.insertRow().insertCell()
  148. cell.style.padding = "2px 0px"
  149. scrollArea = document.createElement("div")
  150. scrollArea.id = newid()
  151. cell.insertAdjacentElement("afterBegin", scrollArea)
  152. upScroller = create_sublink('<center><img src="' + IMAGES + 'up_disabled.gif" width="7" height="9"></center>')
  153. upScroller.style.display = 'none'
  154. upScroller.rows[0].cells[0].scroller = scrollArea
  155. cell.insertAdjacentElement("afterBegin", upScroller)
  156. downScroller = create_sublink('<center><img src="' + IMAGES + 'down_enabled.gif" width="7" height="9"></center>')
  157. downScroller.style.display = 'none'
  158. downScroller.rows[0].cells[0].scroller = scrollArea
  159. cell.insertAdjacentElement("beforeEnd", downScroller)
  160. scrollArea.upScroller = upScroller
  161. scrollArea.downScroller = downScroller
  162. var it = sm.firstChild
  163. var ic = 0
  164. var j
  165. var mi //menu item
  166. while (it)
  167. {
  168. ic++
  169. var tn = it.tagName
  170. var att = it.attributes
  171. if (tn == 'item')
  172. {
  173. var h = '<a href="' + att.getNamedItem("href").value + '">' + att.getNamedItem("label").value + '</a>'
  174. mi = create_sublink(h)
  175. }
  176. else if (tn == 'heading')
  177. mi = create_sublink(att.getNamedItem("label").value, "flyoutSubHeading")
  178. else if (tn == 'separator')
  179. mi = create_separator()
  180. else
  181. mi = create_sublink("", "flyoutSubHeading")
  182. scrollArea.insertAdjacentElement('beforeEnd', mi)
  183. it = it.nextSibling
  184. }
  185. global.body.insertAdjacentElement('beforeEnd', table)
  186. item.flyoutid = flyoutCount
  187. flyouts[flyoutCount++] = table
  188. var maxWidth = MIN_FLYOUT_WIDTH
  189. for (j=0; j<ic; j++)
  190. {
  191. mi = scrollArea.childNodes(j)
  192. if (mi.offsetWidth > maxWidth)
  193. maxWidth = mi.offsetWidth
  194. }
  195. if (maxWidth > MAX_FLYOUT_WIDTH)
  196. maxWidth = MAX_FLYOUT_WIDTH
  197. table.width = ''
  198. rowHeight = scrollArea.childNodes(0).offsetHeight
  199. for (j=0; j<ic; j++)
  200. {
  201. mi = scrollArea.childNodes(j)
  202. mi.style.width = maxWidth + mi.widthAdjust
  203. }
  204. upScroller.style.width = maxWidth
  205. downScroller.style.width = maxWidth
  206. table.style.display = "none"
  207. }
  208. }
  209. }
  210. }
  211. if (nParentItem != 0)
  212. {
  213. items[nParentItem].style.borderColor = MENU_BORDER_COLOR
  214. items[nParentItem].defaultBorder = MENU_BORDER_COLOR
  215. }
  216. }
  217. function normalized_href(href)
  218. {
  219. href = href.toLowerCase();
  220. var slash = href.lastIndexOf("/");
  221. if (-1 != slash)
  222. {
  223. var filename = href.substr(slash + 1);
  224. if ("default.htm" == filename || "default.asp" == filename)
  225. href = href.substr(0, slash + 1);
  226. }
  227. return href;
  228. }
  229. function image_load(src)
  230. {
  231. var img = new Image()
  232. img.src = src
  233. return img
  234. }
  235. function item_onmouseover()
  236. {
  237. var e = whichItem()
  238. if (e.contains(window.event.fromElement))
  239. return
  240. if (e.style.backgroundColor != MENU_CURRENTPAGE_COLOR)
  241. {
  242. e.style.borderColor = MENU_BORDER_COLOR
  243. e.style.backgroundColor = MENU_MOUSEOVER_COLOR
  244. }
  245. if (e.submenu == null)
  246. {
  247. if (e.handle)
  248. menuToShow = flyouts[e.flyoutid]
  249. else
  250. menuToShow = null
  251. flyoutTimer = window.setTimeout(this.id + ".show_flyout()", FLYOUT_DELAY, "JScript")
  252. }
  253. else if (scrollArea = e.scroller) //not a "==" typo
  254. {
  255. if (e.offsetParent.offsetTop > scrollArea.offsetTop)
  256. scrollDelta = +1
  257. else
  258. scrollDelta = -1
  259. scrollStart = scrollArea.scrollTop
  260. scrollTime = current_time()
  261. scrollTimer = window.setInterval(this.id + ".scroll()", SCROLL_DELAY, "JScript")
  262. }
  263. }
  264. function current_time()
  265. {
  266. var temp = new Date()
  267. return temp.valueOf()
  268. }
  269. function item_onmouseout()
  270. {
  271. var e = whichItem()
  272. var te = window.event.toElement
  273. if (te)
  274. if (e.contains(te) || te.flyoutArrow)
  275. return
  276. e.style.borderColor = e.defaultBorder
  277. e.style.backgroundColor = e.defaultBackground
  278. if (flyoutTimer)
  279. {
  280. window.clearTimeout(flyoutTimer)
  281. flyoutTimer = null
  282. }
  283. if (gs = scrollTimer)
  284. {
  285. window.clearInterval(gs)
  286. scrollTimer = null
  287. }
  288. }
  289. function whichItem()
  290. {
  291. var e = event.srcElement
  292. while (e.tagName != "TD")
  293. e = e.parentElement
  294. return e
  295. }
  296. function item_onmousedown()
  297. {
  298. var e = whichItem()
  299. e.style.backgroundColor = MENU_MOUSEDOWN_COLOR
  300. }
  301. function item_onmouseup()
  302. {
  303. if ((event.button & 1) == 0)
  304. return;
  305. var e = whichItem()
  306. e.style.backgroundColor = MENU_MOUSEOVER_COLOR
  307. var a = e.all.tags("A")
  308. if (a.length > 0)
  309. top.location.href = a[0].href
  310. }
  311. function scroll()
  312. {
  313. var temp = scrollStart + Math.round((current_time() - scrollTime) * 0.001 * SCROLL_PXPERSEC) * scrollDelta
  314. scrollArea.scrollTop = temp
  315. upImg = scrollArea.upScroller.all.tags("IMG").item(0)
  316. dnImg = scrollArea.downScroller.all.tags("IMG").item(0)
  317. if (temp <= 0)
  318. upImg.src = IMAGES + "up_disabled.gif"
  319. else
  320. upImg.src = IMAGES + "up_enabled.gif"
  321. if (temp >= scrollArea.scrollHeight - scrollArea.offsetHeight)
  322. dnImg.src = IMAGES + "down_disabled.gif"
  323. else
  324. dnImg.src = IMAGES + "down_enabled.gif"
  325. if (scrollArea.scrollTop != temp)
  326. {
  327. window.clearInterval(scrollTimer)
  328. scrollTimer = null
  329. }
  330. }
  331. function remove_flyout()
  332. {
  333. if (global.fo_currentMenu)
  334. {
  335. var i
  336. for (i=0; i<global.fo_shadows.length; i++)
  337. global.fo_shadows[i].removeNode(true);
  338. global.fo_shadows = new Array();
  339. global.fo_currentMenu.style.display = 'none'
  340. }
  341. }
  342. function show_flyout()
  343. {
  344. flyoutTimer = null
  345. if (global.fo_currentMenu == menuToShow)
  346. return
  347. remove_flyout()
  348. global.fo_currentMenu = menuToShow
  349. if (menuToShow)
  350. {
  351. var menuChildren = menuToShow.rows[0].cells[0].childNodes
  352. var upScroller = menuChildren(0).style
  353. var scrollArea = menuChildren(1).style
  354. var downScroller = menuChildren(2).style
  355. upScroller.display = 'none'
  356. downScroller.display = 'none'
  357. scrollArea.overflow = 'visible'
  358. var menuStyle = menuToShow.style
  359. menuStyle.zIndex = 10
  360. menuStyle.top = menuToShow.baseTop
  361. menuStyle.display = ''
  362. var docBody = global.body
  363. var docTop = docBody.scrollTop
  364. var screenHeight = docBody.offsetHeight
  365. if (menuStyle.posTop - docTop + menuToShow.offsetHeight > screenHeight)
  366. {
  367. menuStyle.posTop -= menuToShow.offsetHeight - 25
  368. if (menuStyle.posTop < docTop)
  369. {
  370. menuStyle.posTop = (screenHeight - menuToShow.offsetHeight) / 2 + docTop - 2
  371. if (menuStyle.posTop < docTop)
  372. {
  373. upScroller.display = '';
  374. menuChildren(0).all.tags("IMG").item(0).src = IMAGES + "up_disabled.gif"
  375. downScroller.display = '';
  376. menuChildren(2).all.tags("IMG").item(0).src = IMAGES + "down_enabled.gif"
  377. scrollArea.overflow = 'hidden';
  378. var vrows = Math.floor((screenHeight - 8) / rowHeight) - 2
  379. if (vrows <= 0)
  380. {
  381. remove_flyout()
  382. return
  383. }
  384. scrollArea.height = vrows * rowHeight
  385. menuStyle.posTop = (screenHeight - menuToShow.offsetHeight) / 2 + docTop - 2
  386. menuChildren(1).scrollTop = 0
  387. }
  388. }
  389. }
  390. makeRectangularDropShadow(menuToShow, MENU_SHADOW_COLOR, 4)
  391. }
  392. }
  393. function element_top(el)
  394. {
  395. var et = 0
  396. while (el)
  397. {
  398. et += el.offsetTop
  399. el = el.offsetParent
  400. }
  401. return et
  402. }
  403. function makeRectangularDropShadow(el, color, size)
  404. {
  405. var i;
  406. for (i=size; i>0; i--)
  407. {
  408. var rect = document.createElement('div');
  409. var rs = rect.style
  410. rs.position = 'absolute';
  411. rs.left = (el.style.posLeft + i) + 'px';
  412. rs.top = (el.style.posTop + i) + 'px';
  413. rs.width = el.offsetWidth + 'px';
  414. rs.height = el.offsetHeight + 'px';
  415. rs.zIndex = el.style.zIndex - i;
  416. rs.backgroundColor = color;
  417. var opacity = 1 - i / (i + 1);
  418. rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
  419. el.insertAdjacentElement('afterEnd', rect);
  420. global.fo_shadows[global.fo_shadows.length] = rect;
  421. }
  422. }
  423. function submenu_onmouseout()
  424. {
  425. var gc = global.fo_currentMenu
  426. var event = window.event
  427. if (!gc.contains(event.toElement))
  428. {
  429. if (event.x < MENU_WIDTH)
  430. return
  431. global.fo_killTimer = window.setTimeout(this.id + ".kill_flyout()", KILL_DELAY, "JScript")
  432. event.cancelBubble = true
  433. }
  434. }
  435. function submenu_onmouseover()
  436. {
  437. if (kt = global.fo_killTimer) //not a == typo
  438. {
  439. window.clearTimeout(kt)
  440. global.fo_killTimer = null
  441. }
  442. }
  443. function kill_flyout()
  444. {
  445. global.fo_killTimer = null
  446. remove_flyout()
  447. global.fo_currentMenu = ''
  448. }
  449. function body_onmousemove()
  450. {
  451. if (!global.fo_currentMenu)
  452. return
  453. if (global.fo_killTimer)
  454. return
  455. if (global.fo_currentMenu.contains(window.event.srcElement))
  456. return
  457. if (window.event.x < MENU_WIDTH)
  458. return
  459. kill_flyout()
  460. }
  461. function create_sublink(html, className)
  462. {
  463. var sublink = document.createElement("table")
  464. sublink.cellPadding = 0
  465. sublink.cellSpacing = 0
  466. sublink.style.margin = "0px 2px"
  467. sublink.widthAdjust = 0
  468. var td = sublink.insertRow().insertCell()
  469. if (!className) className = "flyoutSubLink"
  470. td.className = className
  471. td.submenu = "1"
  472. td.innerHTML = html
  473. return sublink
  474. }
  475. function create_separator()
  476. {
  477. var sep = document.createElement("table")
  478. sep.cellPadding = 0
  479. sep.cellSpacing = 0
  480. sep.style.margin = "2px 0px"
  481. sep.widthAdjust = 4
  482. var td = sep.insertRow().insertCell()
  483. td.width = "100%"
  484. td.height = "1"
  485. td.bgColor = MENU_BORDER_COLOR
  486. return sep
  487. }
  488. </SCRIPT>
  489. </PUBLIC:COMPONENT>