home *** CD-ROM | disk | FTP | other *** search
/ ftp.novell.com / 2014.06.ftp.novell.com.tar / ftp.novell.com / forge / camtasia.msi / Cabs.w1.cab / CamtasiaMenuMaker.chm / scripts / popup.js < prev    next >
Text File  |  2009-08-19  |  10KB  |  338 lines

  1. // Copyright (c) 2002-2006 Quadralay Corporation.  All rights reserved.
  2. //
  3.  
  4. function  HTMLHelpPopup_Object(ParamThisPopupRef,
  5.                                ParamWindowRef,
  6.                                ParamNotifyClickedFunction,
  7.                                ParamDivID,
  8.                                ParamTextID,
  9.                                ParamTimeout,
  10.                                ParamOffsetX,
  11.                                ParamOffsetY,
  12.                                ParamWidth)
  13. {
  14.   this.mThisPopupRef = ParamThisPopupRef;
  15.   this.mWindowRef    = ParamWindowRef;
  16.   this.mDivID        = ParamDivID;
  17.   this.mTextID       = ParamTextID;
  18.   this.mTimeout      = (ParamTimeout > 0) ? ParamTimeout : 0;
  19.   this.mOffsetX      = ParamOffsetX;
  20.   this.mOffsetY      = ParamOffsetY;
  21.   this.mWidth        = ParamWidth;
  22.   this.mImages       = new Array();
  23.  
  24.  
  25.   // Updated when popup triggered
  26.   //
  27.   this.mbVisible     = false;
  28.   this.mPositionX    = 0;
  29.   this.mPositionY    = 0;
  30.   this.mText         = "";
  31.   this.mSetTimeoutID = null;
  32.  
  33.   this.fPreloadImages = HTMLHelpPopup_PreloadImages;
  34.   this.fNotifyClicked = ParamNotifyClickedFunction;
  35.   this.fFormat        = HTMLHelpPopup_Format;
  36.   this.fDivTagText    = HTMLHelpPopup_DivTagText;
  37.   this.fShow          = HTMLHelpPopup_Show;
  38.   this.fLoad          = HTMLHelpPopup_Load;
  39.   this.fPositionAt    = HTMLHelpPopup_PositionAt;
  40.   this.fPosition      = HTMLHelpPopup_Position;
  41.   this.fReveal        = HTMLHelpPopup_Reveal;
  42.   this.fHide          = HTMLHelpPopup_Hide;
  43.  
  44.   // Preload graphics
  45.   //
  46.   this.fPreloadImages();
  47. }
  48.  
  49. function  HTMLHelpPopup_PreloadImages()
  50. {
  51.   this.mImages[this.mImages.length] = new Image(); this.mImages[this.mImages.length - 1].src = "images/spc1w2h.gif";
  52.   this.mImages[this.mImages.length] = new Image(); this.mImages[this.mImages.length - 1].src = "images/spc2w1h.gif";
  53.   this.mImages[this.mImages.length] = new Image(); this.mImages[this.mImages.length - 1].src = "images/spc1w7h.gif";
  54.   this.mImages[this.mImages.length] = new Image(); this.mImages[this.mImages.length - 1].src = "images/spc5w1h.gif";
  55. }
  56.  
  57. function  HTMLHelpPopup_Format(ParamWidth,
  58.                                ParamTextID,
  59.                                ParamText)
  60. {
  61.   var  VarHTML = "";
  62.   var  BackgroundColor = "#FFFFCC";
  63.   var  BorderColor     = "#999999";
  64.   var  ReqSpacer1w2h   = "<img src=\"images/spc1w2h.gif\" width=\"1\" height=\"2\" alt=\"\">";
  65.   var  ReqSpacer2w1h   = "<img src=\"images/spc2w1h.gif\" width=\"2\" height=\"1\" alt=\"\">";
  66.  
  67.  
  68.   VarHTML += "<table width=\"4\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"" + BackgroundColor + "\">";
  69.   VarHTML += " <tr>";
  70.   VarHTML += "  <td height=\"2\" colspan=\"3\" bgcolor=\"" + BorderColor + "\">" + ReqSpacer1w2h + "</td>";
  71.   VarHTML += " </tr>";
  72.  
  73.   VarHTML += " <tr>";
  74.   VarHTML += "  <td bgcolor=\"" + BorderColor + "\">" + ReqSpacer2w1h + "</td>";
  75.   VarHTML += "  <td width=\"100%\" id=\"" + ParamTextID + "\">" + ParamText + "</td>";
  76.   VarHTML += "  <td bgcolor=\"" + BorderColor + "\">" + ReqSpacer2w1h + "</td>";
  77.   VarHTML += " </tr>";
  78.  
  79.   VarHTML += " <tr>";
  80.   VarHTML += "  <td height=\"2\" colspan=\"3\" bgcolor=\"" + BorderColor + "\">" + ReqSpacer1w2h + "</td>";
  81.   VarHTML += " </tr>";
  82.   VarHTML += "</table>";
  83.  
  84.   return VarHTML;
  85. }
  86.  
  87. function  HTMLHelpPopup_DivTagText()
  88. {
  89.   var  VarDivTagText = "";
  90.  
  91.  
  92.   // Emit DIV tag
  93.   //
  94.   VarDivTagText += "<div id=\"" + this.mDivID + "\" style=\"position: absolute ; z-index: -1 ; visibility: hidden ; display: none ; top: 0px ; left: 0px\" onclick=\"javascript:" + this.mThisPopupRef + ".fNotifyClicked();\">\n";
  95.   VarDivTagText += this.fFormat(this.mWidth, this.mTextID, "Popup");
  96.   VarDivTagText += "</div>\n";
  97.  
  98.   return VarDivTagText;
  99. }
  100.  
  101. function  HTMLHelpPopup_Show(ParamText,
  102.                              ParamEvent)
  103. {
  104.   var  PopupDocument = eval(this.mWindowRef + ".document");
  105.  
  106.  
  107.   // Hide popup
  108.   //
  109.   this.fHide();
  110.  
  111.   // Position at 0,0
  112.   //
  113.   this.fPositionAt(0, 0);
  114.  
  115.   // Reset the timeout operation to display the popup
  116.   //
  117.   if (this.mSetTimeoutID != null)
  118.   {
  119.     clearTimeout(this.mSetTimeoutID);
  120.     this.mSetTimeoutID = null;
  121.   }
  122.  
  123.   // Check to see if there is anything to display
  124.   //
  125.   if ((ParamText != null) &&
  126.       (ParamEvent != null))
  127.   {
  128.     if ((typeof(PopupDocument.documentElement) != "undefined") &&
  129.         (typeof(PopupDocument.documentElement.clientWidth) != "undefined") &&
  130.         (typeof(PopupDocument.documentElement.clientHeight) != "undefined") &&
  131.         ((PopupDocument.documentElement.scrollLeft != 0) ||
  132.          (PopupDocument.documentElement.scrollTop != 0)))
  133.     {
  134.       this.mPositionX = PopupDocument.documentElement.scrollLeft + ParamEvent.x;
  135.       this.mPositionY = PopupDocument.documentElement.scrollTop  + ParamEvent.y;
  136.     }
  137.     else
  138.     {
  139.       this.mPositionX = PopupDocument.body.scrollLeft + ParamEvent.x;
  140.       this.mPositionY = PopupDocument.body.scrollTop  + ParamEvent.y;
  141.     }
  142.  
  143.     this.mText = ParamText;
  144.  
  145.     // Load popup
  146.     //
  147.     this.fLoad();
  148.   }
  149. }
  150.  
  151. function  HTMLHelpPopup_Load()
  152. {
  153.   var  PopupDocument = eval(this.mWindowRef + ".document");
  154.  
  155.  
  156.   // Set popup contents
  157.   //
  158.   PopupDocument.all[this.mTextID].innerHTML = this.mText;
  159.  
  160.   // Block display mode
  161.   //
  162.   PopupDocument.all[this.mDivID].style.display = "block";
  163.  
  164.   // Reveal
  165.   //
  166.   this.mSetTimeoutID = setTimeout(this.mThisPopupRef + ".fReveal()", this.mTimeout);
  167. }
  168.  
  169. function  HTMLHelpPopup_PositionAt(ParamX,
  170.                                    ParamY)
  171. {
  172.   var  PopupDocument = eval(this.mWindowRef + ".document");
  173.  
  174.  
  175.   // Set popup position
  176.   //
  177.   PopupDocument.all[this.mDivID].style.pixelLeft = ParamX;
  178.   PopupDocument.all[this.mDivID].style.pixelTop  = ParamY;
  179. }
  180.  
  181. function  HTMLHelpPopup_Position()
  182. {
  183.   var  PopupDocument = eval(this.mWindowRef + ".document");
  184.   var  Margin = 8;
  185.   var  NewPositionX;
  186.   var  NewPositionY;
  187.   var  VisibleOffsetX;
  188.   var  VisibleOffsetY;
  189.   var  ScrollTop;
  190.   var  PopupWidth;
  191.   var  PopupHeight;
  192.   var  DeltaY;
  193.  
  194.  
  195.   // Calculate new position for popup
  196.   //
  197.   NewPositionX = this.mPositionX + this.mOffsetX;
  198.   NewPositionY = this.mPositionY + this.mOffsetY;
  199.  
  200.   // Attempt to determine DIV tag dimensions
  201.   //
  202.   PopupWidth = this.mWidth;
  203.   if (PopupDocument.all[this.mDivID].offsetWidth > PopupWidth)
  204.   {
  205.     PopupWidth = PopupDocument.all[this.mDivID].offsetWidth;
  206.   }
  207.   PopupHeight = 60;  // Guess a value
  208.   if (PopupDocument.all[this.mDivID].offsetHeight > PopupHeight)
  209.   {
  210.     PopupHeight = PopupDocument.all[this.mDivID].offsetHeight;
  211.   }
  212.  
  213.   // Calculate maximum values for X and Y such that the
  214.   // popup will remain visible
  215.   //
  216.   if ((typeof(PopupDocument.documentElement) != "undefined") &&
  217.       (typeof(PopupDocument.documentElement.clientWidth) != "undefined") &&
  218.       (typeof(PopupDocument.documentElement.clientHeight) != "undefined") &&
  219.       ((PopupDocument.documentElement.clientWidth != 0) ||
  220.        (PopupDocument.documentElement.clientHeight != 0)))
  221.   {
  222.     VisibleOffsetX = PopupDocument.documentElement.clientWidth  - this.mOffsetX - PopupWidth - Margin;
  223.     VisibleOffsetY = PopupDocument.documentElement.clientHeight - this.mOffsetY - PopupHeight - Margin;
  224.   }
  225.   else
  226.   {
  227.     VisibleOffsetX = PopupDocument.body.clientWidth  - this.mOffsetX - PopupWidth - Margin;
  228.     VisibleOffsetY = PopupDocument.body.clientHeight - this.mOffsetY - PopupHeight - Margin;
  229.   }
  230.   if (VisibleOffsetX < 0)
  231.   {
  232.     VisibleOffsetX = 0;
  233.   }
  234.   if (VisibleOffsetY < 0)
  235.   {
  236.     VisibleOffsetY = 0;
  237.   }
  238.  
  239.   // Confirm popup will be visible and adjust if necessary
  240.   //
  241.   if ((typeof(PopupDocument.documentElement) != "undefined") &&
  242.       (typeof(PopupDocument.documentElement.clientWidth) != "undefined") &&
  243.       (typeof(PopupDocument.documentElement.clientHeight) != "undefined") &&
  244.       ((PopupDocument.documentElement.scrollLeft != 0) ||
  245.        (PopupDocument.documentElement.scrollTop != 0)))
  246.   {
  247.     if (NewPositionX > (PopupDocument.documentElement.scrollLeft + VisibleOffsetX))
  248.     {
  249.       NewPositionX = PopupDocument.documentElement.scrollLeft + VisibleOffsetX;
  250.     }
  251.     ScrollTop = PopupDocument.documentElement.scrollTop;
  252.     if (NewPositionY > (PopupDocument.documentElement.scrollTop + VisibleOffsetY))
  253.     {
  254.       NewPositionY = PopupDocument.documentElement.scrollTop + VisibleOffsetY;
  255.     }
  256.   }
  257.   else
  258.   {
  259.     if (NewPositionX > (PopupDocument.body.scrollLeft + VisibleOffsetX))
  260.     {
  261.       NewPositionX = PopupDocument.body.scrollLeft + VisibleOffsetX;
  262.     }
  263.     ScrollTop = PopupDocument.body.scrollTop;
  264.     if (NewPositionY > (PopupDocument.body.scrollTop + VisibleOffsetY))
  265.     {
  266.       NewPositionY = PopupDocument.body.scrollTop + VisibleOffsetY;
  267.     }
  268.   }
  269.  
  270.   // Relocate popup if it will overlay the current mouse position
  271.   //
  272.   if ((this.mPositionY >= NewPositionY) &&
  273.       (this.mPositionY <= (NewPositionY + PopupHeight)))
  274.   {
  275.     DeltaY = (NewPositionY + PopupHeight) - this.mPositionY;
  276.     if (NewPositionY - (DeltaY + Margin) > ScrollTop)
  277.     {
  278.       NewPositionY -= DeltaY + Margin;
  279.     }
  280.   }
  281.  
  282.   // Set popup position
  283.   //
  284.   this.fPositionAt(NewPositionX, NewPositionY);
  285. }
  286.  
  287. function  HTMLHelpPopup_Reveal()
  288. {
  289.   var  PopupDocument = eval(this.mWindowRef + ".document");
  290.  
  291.  
  292.   if (this.mSetTimeoutID != null)
  293.   {
  294.     // Position the popup
  295.     //
  296.     this.fPosition();
  297.  
  298.     // Show the popup
  299.     //
  300.     PopupDocument.all[this.mDivID].style.zIndex = 1;
  301.     PopupDocument.all[this.mDivID].style.visibility = "visible";
  302.     this.mbVisible = true;
  303.   }
  304.  
  305.   // Clear the setTimeout ID tracking field
  306.   // to indicate that we're done.
  307.   //
  308.   this.mSetTimeoutID = null;
  309. }
  310.  
  311. function  HTMLHelpPopup_Hide()
  312. {
  313.   var  PopupDocument;
  314.  
  315.  
  316.   // Cancel the setTimeout value that would have
  317.   // displayed the popup
  318.   //
  319.   if (this.mSetTimeoutID != null)
  320.   {
  321.     clearTimeout(this.mSetTimeoutID);
  322.     this.mSetTimeoutID = null;
  323.   }
  324.  
  325.   // Shutdown the popup
  326.   //
  327.   if (this.mbVisible == true)
  328.   {
  329.     PopupDocument = eval(this.mWindowRef + ".document");
  330.  
  331.     PopupDocument.all[this.mDivID].style.zIndex = -1;
  332.     PopupDocument.all[this.mDivID].style.visibility = "hidden";
  333.     PopupDocument.all[this.mDivID].style.display    = "none";
  334.   }
  335.  
  336.   this.mbVisible = false;
  337. }
  338.