home *** CD-ROM | disk | FTP | other *** search
/ Thomson (Residential) / TGSTPv7203.iso / mac / Documentation / HTML / TG587n_pt / wwhelp / wwhimpl / common / scripts / popup.js < prev    next >
Text File  |  2007-06-22  |  13KB  |  464 lines

  1. // Copyright (c) 2000-2001 Quadralay Corporation.  All rights reserved.
  2. //
  3.  
  4. function  WWHPopup_Object(ParamThisPopupRef,
  5.                           ParamWindowRef,
  6.                           ParamPopupTranslateFunc,
  7.                           ParamPopupFormatFunc,
  8.                           ParamDivID,
  9.                           ParamTextID,
  10.                           ParamTimeout,
  11.                           ParamOffsetX,
  12.                           ParamOffsetY,
  13.                           ParamWidth)
  14. {
  15.   this.mThisPopupRef = ParamThisPopupRef;
  16.   this.mWindowRef    = ParamWindowRef;
  17.   this.mDivID        = ParamDivID;
  18.   this.mTextID       = ParamTextID;
  19.   this.mTimeout      = (ParamTimeout > 0) ? ParamTimeout : 0;
  20.   this.mOffsetX      = ParamOffsetX;
  21.   this.mOffsetY      = ParamOffsetY;
  22.   this.mWidth        = ParamWidth;
  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.fTranslate     = ParamPopupTranslateFunc;
  34.   this.fFormat        = ParamPopupFormatFunc;
  35.   this.fEventString   = WWHPopup_EventString;
  36.   this.fDivTagText    = WWHPopup_DivTagText;
  37.   this.fShow          = WWHPopup_Show;
  38.   this.fPositionPopup = WWHPopup_PositionPopup;
  39.   this.fPopup         = WWHPopup_Popup;
  40.   this.fHide          = WWHPopup_Hide;
  41. }
  42.  
  43. function  WWHPopup_EventString()
  44. {
  45.   var  EventString = "null";
  46.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  47.  
  48.  
  49.   // Set event string based on browser type
  50.   //
  51.   if ((Browser == 1) ||  // Shorthand for Netscape
  52.       (Browser == 2) ||  // Shorthand for IE
  53.       (Browser == 4))    // Shorthand for Netscape 6.0
  54.   {
  55.     EventString = "event";
  56.   }
  57.   else
  58.   {
  59.     EventString = "null";
  60.   }
  61.  
  62.   return EventString;
  63. }
  64.  
  65. function  WWHPopup_DivTagText()
  66. {
  67.   var  DivTagText = "";
  68.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  69.   var  VisibleAttribute = "visibility: hidden";
  70.  
  71.  
  72.   // Update VisibleAttribute based on browser
  73.   //
  74.   if ((Browser == 3) ||  // Shorthand for iCab
  75.       (Browser == 4))    // Shorthand for Netscape 6.0 (Mozilla)
  76.   {
  77.     VisibleAttribute = "display: none";
  78.   }
  79.  
  80.   // Open DIV tag
  81.   //
  82.   DivTagText += "<div id=\"" + this.mDivID + "\" style=\"position: absolute ; z-index: 1 ; " + VisibleAttribute + " ; top: 0px ; left: 0px\">\n";
  83.  
  84.   // Expand out popup in browsers that support innerHTML accessor
  85.   //
  86.   if ((Browser == 2) ||  // Shortcut for IE
  87.       (Browser == 3) ||  // Shortcut for iCab
  88.       (Browser == 4))    // Shortcut for Netscape 6 (Mozilla)
  89.   {
  90.     DivTagText += this.fFormat(this.mWidth, this.mTextID,
  91.                                "Popup");
  92.   }
  93.  
  94.   // Close out DIV tag
  95.   //
  96.   DivTagText += "</div>\n";
  97.  
  98.   return DivTagText;
  99. }
  100.  
  101. function  WWHPopup_Show(ParamText,
  102.                         ParamEvent)
  103. {
  104.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  105.  
  106.  
  107.   // Reset the timeout operation to display the popup
  108.   //
  109.   if (this.mSetTimeoutID != null)
  110.   {
  111.     clearTimeout(this.mSetTimeoutID);
  112.  
  113.     this.mSetTimeoutID = null;
  114.   }
  115.  
  116.   // Check to see if there is anything to display
  117.   //
  118.   if ((ParamText != null) &&
  119.       (ParamEvent != null))
  120.   {
  121.     var  bStartTimer = false;
  122.     var  PopupWindow   = eval(this.mWindowRef);
  123.     var  PopupDocument = eval(this.mWindowRef + ".document");
  124.  
  125.  
  126.     if (Browser == 1)  // Shorthand for Netscape 4.x
  127.     {
  128.       this.mPositionX = ParamEvent.layerX;
  129.       this.mPositionY = ParamEvent.layerY;
  130.  
  131.       this.mText = ParamText;
  132.  
  133.       bStartTimer = true;
  134.     }
  135.     else if (Browser == 2)  // Shorthand for IE
  136.     {
  137.       var  PopupDocument = eval(this.mWindowRef + ".document");
  138.       var  TranslatedText;
  139.  
  140.  
  141.       this.mPositionX = PopupDocument.body.scrollLeft + ParamEvent.x;
  142.       this.mPositionY = PopupDocument.body.scrollTop  + ParamEvent.y;
  143.  
  144.       // Workaround for IE 4.0 on Windows
  145.       //
  146.       if (WWHFrame.WWHBrowserInfo.mbWindowsIE40)
  147.       {
  148.         this.mPositionX = ParamEvent.x;
  149.         this.mPositionY = ParamEvent.y;
  150.       }
  151.  
  152.       this.mText = ParamText;
  153.  
  154.       if (WWHFrame.WWHBrowserInfo.mPlatform == 2)  // Shorthand for Macintosh
  155.       {
  156.         // Setting the position here before it is displayed
  157.         // corrects a bug under IE 5 on the Macintosh
  158.         //
  159.         PopupDocument.all[this.mDivID].style.pixelLeft = 0;
  160.         PopupDocument.all[this.mDivID].style.pixelTop  = 0;
  161.         TranslatedText = this.fTranslate(this.mText);
  162.         PopupDocument.all[this.mTextID].innerHTML = TranslatedText;
  163.         this.fPositionPopup();
  164.       }
  165.  
  166.       bStartTimer = true;
  167.     }
  168.     else if (Browser == 4)  // Shorthand for Netscape 6.x (Mozilla)
  169.     {
  170.       this.mPositionX = ParamEvent.layerX;
  171.       this.mPositionY = ParamEvent.layerY;
  172.  
  173.       this.mText = ParamText;
  174.  
  175.       bStartTimer = true;
  176.     }
  177.  
  178.     if (bStartTimer == true)
  179.     {
  180.       this.mSetTimeoutID = setTimeout(this.mThisPopupRef + ".fPopup()", this.mTimeout);
  181.     }
  182.   }
  183. }
  184.  
  185. function  WWHPopup_PositionPopup()
  186. {
  187.   var  PopupWindow   = eval(this.mWindowRef);
  188.   var  PopupDocument = eval(this.mWindowRef + ".document");
  189.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  190.   var  NewPositionX;
  191.   var  NewPositionY;
  192.   var  VisibleOffsetX;
  193.   var  VisibleOffsetY;
  194.   var  PopupWidth;
  195.   var  PopupHeight;
  196.  
  197.  
  198.   // Calculate new position for popup
  199.   //
  200.   NewPositionX = this.mPositionX + this.mOffsetX;
  201.   NewPositionY = this.mPositionY + this.mOffsetY;
  202.  
  203.   if (Browser == 1)  // Shorthand for Netscape 4.x
  204.   {
  205.     // Attempt to determine DIV tag dimensions
  206.     //
  207.     PopupWidth = this.mWidth;
  208.     if (PopupDocument.layers[this.mDivID].clip.width > PopupWidth)
  209.     {
  210.       PopupWidth = PopupDocument.layers[this.mDivID].clip.width;
  211.     }
  212.     PopupHeight = 60;  // Guess a value
  213.     if (PopupDocument.layers[this.mDivID].clip.height > PopupHeight)
  214.     {
  215.       PopupHeight = PopupDocument.layers[this.mDivID].clip.height;
  216.     }
  217.  
  218.     // Calculate maximum values for X and Y such that the
  219.     // popup will remain visible
  220.     //
  221.     VisibleOffsetX = PopupWindow.innerWidth  - this.mOffsetX - PopupWidth;
  222.     if (VisibleOffsetX < 0)
  223.     {
  224.       VisibleOffsetX = 0;
  225.     }
  226.     VisibleOffsetY = PopupWindow.innerHeight - this.mOffsetY - PopupHeight;
  227.     if (VisibleOffsetY < 0)
  228.     {
  229.       VisibleOffsetY = 0;
  230.     }
  231.  
  232.     // Confirm popup will be visible and adjust if necessary
  233.     //
  234.     if (NewPositionX > (PopupWindow.pageXOffset + VisibleOffsetX))
  235.     {
  236.       NewPositionX = PopupWindow.pageXOffset + VisibleOffsetX;
  237.     }
  238.     if (NewPositionY > (PopupWindow.pageYOffset + VisibleOffsetY))
  239.     {
  240.       NewPositionY = PopupWindow.pageYOffset + VisibleOffsetY;
  241.     }
  242.  
  243.     // Set popup position
  244.     //
  245.     PopupDocument.layers[this.mDivID].left = NewPositionX;
  246.     PopupDocument.layers[this.mDivID].top  = NewPositionY;
  247.   }
  248.   else if (Browser == 2)  // Shorthand for IE
  249.   {
  250.     // Attempt to determine DIV tag dimensions
  251.     //
  252.     PopupWidth = this.mWidth;
  253.     if (PopupDocument.all[this.mDivID].offsetWidth > PopupWidth)
  254.     {
  255.       PopupWidth = PopupDocument.all[this.mDivID].offsetWidth;
  256.     }
  257.     PopupHeight = 60;  // Guess a value
  258.     if (PopupDocument.all[this.mDivID].offsetHeight > PopupHeight)
  259.     {
  260.       PopupHeight = PopupDocument.all[this.mDivID].offsetHeight;
  261.     }
  262.  
  263.     // Calculate maximum values for X and Y such that the
  264.     // popup will remain visible
  265.     //
  266.     VisibleOffsetX = PopupDocument.body.clientWidth  - this.mOffsetX - PopupWidth;
  267.     if (VisibleOffsetX < 0)
  268.     {
  269.       VisibleOffsetX = 0;
  270.     }
  271.     VisibleOffsetY = PopupDocument.body.clientHeight - this.mOffsetY - PopupHeight;
  272.     if (VisibleOffsetY < 0)
  273.     {
  274.       VisibleOffsetY = 0;
  275.     }
  276.  
  277.     // Confirm popup will be visible and adjust if necessary
  278.     //
  279.     if (NewPositionX > (PopupDocument.body.scrollLeft + VisibleOffsetX))
  280.     {
  281.       NewPositionX = PopupDocument.body.scrollLeft + VisibleOffsetX;
  282.     }
  283.     if (NewPositionY > (PopupDocument.body.scrollTop + VisibleOffsetY))
  284.     {
  285.       NewPositionY = PopupDocument.body.scrollTop + VisibleOffsetY;
  286.     }
  287.  
  288.     // Set popup position
  289.     //
  290.     PopupDocument.all[this.mDivID].style.pixelLeft = NewPositionX;
  291.     PopupDocument.all[this.mDivID].style.pixelTop  = NewPositionY;
  292.   }
  293.   else if (Browser == 4)  // Shorthand for Netscape 6.x (Mozilla)
  294.   {
  295.     // Attempt to determine DIV tag dimensions
  296.     //
  297.     PopupWidth = this.mWidth;
  298.     if (PopupDocument.getElementById(this.mDivID).offsetWidth > PopupWidth)
  299.     {
  300.       PopupWidth = PopupDocument.getElementById(this.mDivID).offsetWidth;
  301.     }
  302.     PopupHeight = 60;  // Guess a value
  303.     if (PopupDocument.getElementById(this.mDivID).offsetHeight > PopupHeight)
  304.     {
  305.       PopupHeight = PopupDocument.getElementById(this.mDivID).offsetHeight;
  306.     }
  307.  
  308.     // Calculate maximum values for X and Y such that the
  309.     // popup will remain visible
  310.     //
  311.     VisibleOffsetX = PopupWindow.innerWidth  - this.mOffsetX - PopupWidth;
  312.     if (VisibleOffsetX < 0)
  313.     {
  314.       VisibleOffsetX = 0;
  315.     }
  316.     VisibleOffsetY = PopupWindow.innerHeight - this.mOffsetY - PopupHeight;
  317.     if (VisibleOffsetY < 0)
  318.     {
  319.       VisibleOffsetY = 0;
  320.     }
  321.  
  322.     // Confirm popup will be visible and adjust if necessary
  323.     //
  324.     if (NewPositionX > (PopupWindow.scrollX + VisibleOffsetX))
  325.     {
  326.       NewPositionX = PopupWindow.scrollX + VisibleOffsetX;
  327.     }
  328.     if (NewPositionY > (PopupWindow.scrollY + VisibleOffsetY))
  329.     {
  330.       NewPositionY = PopupWindow.scrollY + VisibleOffsetY;
  331.     }
  332.  
  333.     // Set popup position
  334.     //
  335.     PopupDocument.getElementById(this.mDivID).style.left = NewPositionX + "px";
  336.     PopupDocument.getElementById(this.mDivID).style.top  = NewPositionY + "px";
  337.   }
  338. }
  339.  
  340. function  WWHPopup_Popup()
  341. {
  342.   var  PopupDocument = eval(this.mWindowRef + ".document");
  343.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  344.  
  345.  
  346.   if (this.mSetTimeoutID != null)
  347.   {
  348.     if (Browser == 1)  // Shorthand for Netscape 4.x
  349.     {
  350.       var  FormattedText;
  351.  
  352.  
  353.       // Format popup contents for browser
  354.       //
  355.       FormattedText = this.fFormat(this.mWidth, this.mTextID,
  356.                                    this.fTranslate(this.mText));
  357.  
  358.       // Set popup contents
  359.       //
  360.       PopupDocument.layers[this.mDivID].document.open();
  361.       PopupDocument.layers[this.mDivID].document.write(FormattedText);
  362.       PopupDocument.layers[this.mDivID].document.close();
  363.  
  364.       // Position the popup
  365.       //
  366.       this.fPositionPopup();
  367.  
  368.       // Show the popup
  369.       //
  370.       PopupDocument.layers[this.mDivID].visibility = "visible";
  371.       this.mbVisible = true;
  372.     }
  373.     else if (Browser == 2)  // Shorthand for IE
  374.     {
  375.       var  TranslatedText;
  376.  
  377.  
  378.       // Format popup contents for browser
  379.       // Set popup contents
  380.       //
  381.       TranslatedText = this.fTranslate(this.mText);
  382.       PopupDocument.all[this.mTextID].innerHTML = TranslatedText;
  383.  
  384.       // Position the popup
  385.       //
  386.       this.fPositionPopup();
  387.  
  388.       // Show the popup
  389.       //
  390.       PopupDocument.all[this.mDivID].style.visibility = "visible";
  391.       this.mbVisible = true;
  392.     }
  393.     else if (Browser == 4)  // Shorthand for Netscape 6.x (Mozilla)
  394.     {
  395.       var  TranslatedText;
  396.  
  397.  
  398.       // Format popup contents for browser
  399.       // Set popup contents
  400.       //
  401.       TranslatedText = this.fTranslate(this.mText);
  402.       PopupDocument.getElementById(this.mTextID).innerHTML = TranslatedText;
  403.  
  404.       // Initial popup positioning before object size can be determined
  405.       //
  406.       this.fPositionPopup();
  407.  
  408.       // Show the popup
  409.       //
  410.       PopupDocument.getElementById(this.mDivID).style.display = "block";
  411.       this.mbVisible = true;
  412.  
  413.       // Position the popup
  414.       // Offset calculations may be off so we might need to reposition the popup
  415.       //
  416.       this.fPositionPopup();
  417.     }
  418.   }
  419.  
  420.   // Clear the setTimeout ID tracking field
  421.   // to indicate that we're done.
  422.   //
  423.   this.mSetTimeoutID = null;
  424. }
  425.  
  426. function  WWHPopup_Hide()
  427. {
  428.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  429.  
  430.  
  431.   // Cancel the setTimeout value that would have
  432.   // displayed the popup
  433.   //
  434.   if (this.mSetTimeoutID != null)
  435.   {
  436.     clearTimeout(this.mSetTimeoutID);
  437.  
  438.     this.mSetTimeoutID = null;
  439.   }
  440.  
  441.   // Shutdown the popup
  442.   //
  443.   if (this.mbVisible == true)
  444.   {
  445.     var  PopupDocument = eval(this.mWindowRef + ".document");
  446.  
  447.  
  448.     if (Browser == 1)  // Shorthand for Netscape 4.x
  449.     {
  450.       PopupDocument.layers[this.mDivID].visibility = "hidden";
  451.     }
  452.     else if (Browser == 2)  // Shorthand for IE
  453.     {
  454.       PopupDocument.all[this.mDivID].style.visibility = "hidden";
  455.     }
  456.     else if (Browser == 4)  // Shorthand for Netscape 6.x (Mozilla)
  457.     {
  458.       PopupDocument.getElementById(this.mDivID).style.display = "none";
  459.     }
  460.   }
  461.  
  462.   this.mbVisible = false;
  463. }
  464.