home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / ProPlus.WW / ProPsWW2.cab / MENUS.JS < prev    next >
Text File  |  2007-02-04  |  3KB  |  85 lines

  1. // ========================================================================
  2. // ===                             menus.js                             ===
  3. // ========================================================================
  4.  
  5. // The popup object that will hold the menu.
  6. var g_objPopup = window.createPopup();
  7.  
  8. // === Menu() =========
  9. // the main menu object
  10. function Menu()
  11. {
  12.     this.MenuHTML = "";
  13.     this.AddMenuItem = AddMenuItem;
  14.     this.AddSeparator = AddSeparator;
  15.     this.Create = Create;
  16. }
  17.  
  18. // === AddMenuItem(string, string, boolean) ====================
  19. // add an item to the menu object with the given text and action
  20. function AddMenuItem(i_strTitle, i_strAction, i_blnEnabled)
  21. {
  22.     i_strTitle = i_strTitle.replace(/ /g, " ");
  23.  
  24.     var strHTML = "";
  25.     if (i_blnEnabled)
  26.     {
  27.         strHTML += "<div style=\"width:100%; cursor:default; padding:1px 22px 3px 17px; border:1px solid menu; font-family:tahoma; font-size:8pt;\" onmouseover=\"this.style.backgroundColor='highlight'; this.style.color='highlighttext';\" onmouseout=\"this.style.backgroundColor=''; this.style.color='';\"";
  28.         if (i_strAction != "")
  29.             strHTML += " onclick=\"" + i_strAction + "\"";
  30.     }
  31.     else
  32.         strHTML += "<div style=\"width:100%; cursor:default; padding:2px 23px 4px 18px; font-family:tahoma; font-size:8pt; color:threedshadow;\"";
  33.  
  34.     strHTML += ">" + i_strTitle + "</div>";
  35.     this.MenuHTML += strHTML;
  36. }
  37.  
  38. // === AddSeparator() ====================
  39. // add a separator item to the menu object
  40. function AddSeparator()
  41. {
  42.     var strHTML = "";
  43.     strHTML += "<div style=\"margin:4px 3px 4px 3px; border-width:1px; border-style:solid; border-color:buttonshadow buttonhighlight buttonhighlight buttonshadow;\"></div>";
  44.     this.MenuHTML += strHTML;
  45. }
  46.  
  47. // === Create() ============================
  48. // create the final HTML for the menu object
  49. function Create()
  50. {
  51.     this.MenuHTML = "<div style=\"background:menu; color:menutext; border-width:2px; border-color:buttonhighlight buttonshadow buttonshadow buttonhighlight; border-style:outset; z-index:100;\">" + this.MenuHTML + "</div>";
  52. }
  53.  
  54. // === MenuPopup(object, object) ============================================
  55. // called to display the menu, reference object and menu to display passed in
  56. function MenuPopup(i_objRef, i_objMenu)
  57. {
  58.     var intTop = GetOffset(i_objRef, "top") + i_objRef.offsetHeight + 1;
  59.     var intLeft = GetOffset(i_objRef, "left");
  60.     var objPopupBody = g_objPopup.document.body;
  61.     objPopupBody.innerHTML = i_objMenu.MenuHTML;
  62.     g_objPopup.show(0, 0, 0, 0);
  63.     var realWidth = objPopupBody.scrollWidth;
  64.     var realHeight = objPopupBody.scrollHeight;
  65.     g_objPopup.show(intLeft, intTop, realWidth, realHeight, document.body);
  66. }
  67.  
  68. // === GetOffset(object, string) =========================================
  69. // utility function used to get offset of reference object passed in, gets
  70. // either top or left offset of the object
  71. function GetOffset(i_objPos, i_strDir)
  72. {
  73.     var intOffset = 0;
  74.     var objOffset = i_objPos;
  75.     while (objOffset.tagName != "BODY")
  76.     {
  77.         if (i_strDir == "top")
  78.             intOffset += objOffset.offsetTop;
  79.         else if (i_strDir == "left")
  80.             intOffset += objOffset.offsetLeft;
  81.  
  82.         objOffset = objOffset.offsetParent;
  83.     }
  84.     return intOffset;
  85. }