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.

559 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" || item.className == "flyoutLinkRed" || item.className == "flyoutLink Red" )
  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. {
  310. try
  311. {
  312. var nPassVal = new String ( a[0].parentElement.parentElement.lastChild.firstChild.value );
  313. if ( nPassVal != "undefined" )
  314. parent.frames("sepBody").location.href = a[0].href + "?Val=" + nPassVal
  315. else
  316. {
  317. parent.frames("sepBody").location.href = a[0].href
  318. }
  319. }
  320. catch( err )
  321. {
  322. parent.frames("sepBody").location.href = a[0].href
  323. }
  324. }
  325. }
  326. function scroll()
  327. {
  328. var temp = scrollStart + Math.round((current_time() - scrollTime) * 0.001 * SCROLL_PXPERSEC) * scrollDelta
  329. scrollArea.scrollTop = temp
  330. upImg = scrollArea.upScroller.all.tags("IMG").item(0)
  331. dnImg = scrollArea.downScroller.all.tags("IMG").item(0)
  332. if (temp <= 0)
  333. upImg.src = IMAGES + "up_disabled.gif"
  334. else
  335. upImg.src = IMAGES + "up_enabled.gif"
  336. if (temp >= scrollArea.scrollHeight - scrollArea.offsetHeight)
  337. dnImg.src = IMAGES + "down_disabled.gif"
  338. else
  339. dnImg.src = IMAGES + "down_enabled.gif"
  340. if (scrollArea.scrollTop != temp)
  341. {
  342. window.clearInterval(scrollTimer)
  343. scrollTimer = null
  344. }
  345. }
  346. function remove_flyout()
  347. {
  348. if (global.fo_currentMenu)
  349. {
  350. var i
  351. for (i=0; i<global.fo_shadows.length; i++)
  352. global.fo_shadows[i].removeNode(true);
  353. global.fo_shadows = new Array();
  354. global.fo_currentMenu.style.display = 'none'
  355. }
  356. }
  357. function show_flyout()
  358. {
  359. flyoutTimer = null
  360. if (global.fo_currentMenu == menuToShow)
  361. return
  362. remove_flyout()
  363. global.fo_currentMenu = menuToShow
  364. if (menuToShow)
  365. {
  366. var menuChildren = menuToShow.rows[0].cells[0].childNodes
  367. var upScroller = menuChildren(0).style
  368. var scrollArea = menuChildren(1).style
  369. var downScroller = menuChildren(2).style
  370. upScroller.display = 'none'
  371. downScroller.display = 'none'
  372. scrollArea.overflow = 'visible'
  373. var menuStyle = menuToShow.style
  374. menuStyle.zIndex = 10
  375. menuStyle.top = menuToShow.baseTop
  376. menuStyle.display = ''
  377. var docBody = global.body
  378. var docTop = docBody.scrollTop
  379. var screenHeight = docBody.offsetHeight
  380. if (menuStyle.posTop - docTop + menuToShow.offsetHeight > screenHeight)
  381. {
  382. menuStyle.posTop -= menuToShow.offsetHeight - 25
  383. if (menuStyle.posTop < docTop)
  384. {
  385. menuStyle.posTop = (screenHeight - menuToShow.offsetHeight) / 2 + docTop - 2
  386. if (menuStyle.posTop < docTop)
  387. {
  388. upScroller.display = '';
  389. menuChildren(0).all.tags("IMG").item(0).src = IMAGES + "up_disabled.gif"
  390. downScroller.display = '';
  391. menuChildren(2).all.tags("IMG").item(0).src = IMAGES + "down_enabled.gif"
  392. scrollArea.overflow = 'hidden';
  393. var vrows = Math.floor((screenHeight - 8) / rowHeight) - 2
  394. if (vrows <= 0)
  395. {
  396. remove_flyout()
  397. return
  398. }
  399. scrollArea.height = vrows * rowHeight
  400. menuStyle.posTop = (screenHeight - menuToShow.offsetHeight) / 2 + docTop - 2
  401. menuChildren(1).scrollTop = 0
  402. }
  403. }
  404. }
  405. makeRectangularDropShadow(menuToShow, MENU_SHADOW_COLOR, 4)
  406. }
  407. }
  408. function element_top(el)
  409. {
  410. var et = 0
  411. while (el)
  412. {
  413. et += el.offsetTop
  414. el = el.offsetParent
  415. }
  416. return et
  417. }
  418. function makeRectangularDropShadow(el, color, size)
  419. {
  420. var i;
  421. for (i=size; i>0; i--)
  422. {
  423. var rect = document.createElement('div');
  424. var rs = rect.style
  425. rs.position = 'absolute';
  426. rs.left = (el.style.posLeft + i) + 'px';
  427. rs.top = (el.style.posTop + i) + 'px';
  428. rs.width = el.offsetWidth + 'px';
  429. rs.height = el.offsetHeight + 'px';
  430. rs.zIndex = el.style.zIndex - i;
  431. rs.backgroundColor = color;
  432. var opacity = 1 - i / (i + 1);
  433. rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
  434. el.insertAdjacentElement('afterEnd', rect);
  435. global.fo_shadows[global.fo_shadows.length] = rect;
  436. }
  437. }
  438. function submenu_onmouseout()
  439. {
  440. var gc = global.fo_currentMenu
  441. var event = window.event
  442. if (!gc.contains(event.toElement))
  443. {
  444. if (event.x < MENU_WIDTH)
  445. return
  446. global.fo_killTimer = window.setTimeout(this.id + ".kill_flyout()", KILL_DELAY, "JScript")
  447. event.cancelBubble = true
  448. }
  449. }
  450. function submenu_onmouseover()
  451. {
  452. if (kt = global.fo_killTimer) //not a == typo
  453. {
  454. window.clearTimeout(kt)
  455. global.fo_killTimer = null
  456. }
  457. }
  458. function kill_flyout()
  459. {
  460. global.fo_killTimer = null
  461. remove_flyout()
  462. global.fo_currentMenu = ''
  463. }
  464. function body_onmousemove()
  465. {
  466. if (!global.fo_currentMenu)
  467. return
  468. if (global.fo_killTimer)
  469. return
  470. if (global.fo_currentMenu.contains(window.event.srcElement))
  471. return
  472. if (window.event.x < MENU_WIDTH)
  473. return
  474. kill_flyout()
  475. }
  476. function create_sublink(html, className)
  477. {
  478. var sublink = document.createElement("table")
  479. sublink.cellPadding = 0
  480. sublink.cellSpacing = 0
  481. sublink.style.margin = "0px 2px"
  482. sublink.widthAdjust = 0
  483. var td = sublink.insertRow().insertCell()
  484. if (!className) className = "flyoutSubLink"
  485. td.className = className
  486. td.submenu = "1"
  487. td.innerHTML = html
  488. return sublink
  489. }
  490. function create_separator()
  491. {
  492. var sep = document.createElement("table")
  493. sep.cellPadding = 0
  494. sep.cellSpacing = 0
  495. sep.style.margin = "2px 0px"
  496. sep.widthAdjust = 4
  497. var td = sep.insertRow().insertCell()
  498. td.width = "100%"
  499. td.height = "1"
  500. td.bgColor = MENU_BORDER_COLOR
  501. return sep
  502. }
  503. </SCRIPT>
  504. </PUBLIC:COMPONENT>