home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 November / Chip_2003-11_cd2.bin / ruzne / painter / PAINTE~2.cab / _9EAAF78A1C204AAB8C35FFC1B537FF59 < prev    next >
Text File  |  2003-01-06  |  12KB  |  405 lines

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