home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / communicator / alerts / alert.js next >
Text File  |  2003-06-08  |  5KB  |  130 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Netscape Public License
  5.  * Version 1.1 (the "License"); you may not use this file except in
  6.  * compliance with the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/NPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.org code.
  15.  *
  16.  * The Initial Developer of the Original Code is 
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 1998
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *  Scott MacGregor <mscott@netscape.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the NPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the NPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. var gCurrentHeight = 0;
  39. var gFinalHeight = 50;
  40. var gSlideIncrement = 1;
  41. var gSlideTime = 10;
  42. var gOpenTime = 3000; // total time the alert should stay up once we are done animating.
  43.  
  44. var gAlertListener = null;
  45. var gAlertTextClickable = false;
  46. var gAlertCookie = "";
  47.  
  48. function prefillAlertInfo()
  49. {
  50.   // unwrap all the args....
  51.   // arguments[0] --> the image src url
  52.   // arguments[1] --> the alert title
  53.   // arguments[2] --> the alert text
  54.   // arguments[3] --> is the text clickable? 
  55.   // arguments[4] --> the alert cookie to be passed back to the listener
  56.   // arguments[5] --> an optional callback listener (nsIAlertListener)
  57.  
  58.   document.getElementById('alertImage').setAttribute('src', window.arguments[0]);
  59.   document.getElementById('alertTitleLabel').setAttribute('value', window.arguments[1]);
  60.   document.getElementById('alertTextLabel').setAttribute('value', window.arguments[2]);
  61.   gAlertTextClickable = window.arguments[3];
  62.   gAlertCookie = window.arguments[4];
  63.  
  64.   if (gAlertTextClickable)
  65.     document.getElementById('alertTextLabel').setAttribute('clickable', true);
  66.   
  67.   // the 5th argument is optional
  68.   if (window.arguments[5])
  69.    gAlertListener = window.arguments[5].QueryInterface(Components.interfaces.nsIAlertListener);
  70. }
  71.  
  72. function onAlertLoad()
  73. {
  74.   // read out our initial settings from prefs.
  75.   try 
  76.   {
  77.     var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService();
  78.     prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
  79.     var prefBranch = prefService.getBranch(null);
  80.     gSlideIncrement = prefBranch.getIntPref("alerts.slideIncrement");
  81.     gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
  82.     gOpenTime = prefBranch.getIntPref("alerts.totalOpenTime");
  83.   } catch (ex) {}
  84.  
  85.   sizeToContent();
  86.   gFinalHeight = window.outerHeight;
  87.   window.outerHeight = 0;
  88.   // be sure to offset the alert by 10 pixels from the far right edge of the screen
  89.   window.moveTo( (screen.availLeft + screen.availWidth - window.outerWidth) - 10, screen.availTop + screen.availHeight - window.outerHeight);
  90.   setTimeout(animateAlert, gSlideTime);
  91. }
  92.  
  93. function animateAlert()
  94. {
  95.   if (gCurrentHeight < gFinalHeight)
  96.   {
  97.     gCurrentHeight += gSlideIncrement;
  98.  
  99.     window.screenY -= gSlideIncrement;
  100.     window.outerHeight += gSlideIncrement;
  101.     setTimeout(animateAlert, gSlideTime);
  102.   }
  103.   else
  104.    setTimeout(closeAlert, gOpenTime);  
  105. }
  106.  
  107. function closeAlert()
  108. {
  109.   if (gCurrentHeight)
  110.   {
  111.     gCurrentHeight -= gSlideIncrement;
  112.  
  113.     window.screenY += gSlideIncrement;
  114.     window.outerHeight -= gSlideIncrement;
  115.     setTimeout(closeAlert, gSlideTime);
  116.   }
  117.   else
  118.   {
  119.     if (gAlertListener)
  120.       gAlertListener.onAlertFinished(gAlertCookie); 
  121.     window.close(); 
  122.   }
  123. }
  124.  
  125. function onAlertClick()
  126. {
  127.   if (gAlertListener && gAlertTextClickable)
  128.     gAlertListener.onAlertClickCallback(gAlertCookie);
  129. }
  130.