home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Complet / thunderbird / chrome / mail.jar / content / editor / pref-composer.js < prev    next >
Encoding:
Text File  |  2003-10-14  |  10.4 KB  |  301 lines

  1. /*
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  */
  22. // This is mostly a modified version of code in EdColorProps.xul
  23.  
  24. // Initialize in case we can't get them from prefs???
  25. const defaultTextColor="#000000";
  26. const defaultLinkColor="#000099";
  27. const defaultActiveColor="#000099";
  28. const defaultVisitedColor="#990099";
  29. const defaultBackgroundColor="#FFFFFF";
  30.  
  31. var customTextColor;
  32. var customLinkColor;
  33. var customActiveColor;
  34. var customVisitedColor;
  35. var customBackgroundColor;
  36. var previewBGColor;
  37. var backgroundImage = "";
  38.  
  39. // Strings we use often
  40. const styleStr =       "style";
  41. const textStr =        "text";
  42. const linkStr =        "link";
  43. const vlinkStr =       "vlink";
  44. const alinkStr =       "alink";
  45. const bgcolorStr =     "bgcolor";
  46. const backgroundStr =  "background";
  47. const colorStyle =     "color: ";
  48. const backColorStyle = "background-color: ";
  49. const backImageStyle = "; background-image: url(";
  50.  
  51. var browserColors;
  52. var dialog;
  53.  
  54. function Startup()
  55. {
  56.   gDialog.ColorPreview = document.getElementById("ColorPreview");
  57.   gDialog.NormalText = document.getElementById("NormalText");
  58.   gDialog.LinkText = document.getElementById("LinkText");
  59.   gDialog.ActiveLinkText = document.getElementById("ActiveLinkText");
  60.   gDialog.VisitedLinkText = document.getElementById("VisitedLinkText");
  61.   gDialog.DefaultColorsRadio = document.getElementById("DefaultColorsRadio");
  62.   gDialog.CustomColorsRadio = document.getElementById("CustomColorsRadio");
  63.   gDialog.BackgroundImageInput = document.getElementById("BackgroundImageInput");
  64.  
  65.   // The data elements that hold the pref values
  66.   gDialog.NormalData = document.getElementById("textData");
  67.   gDialog.LinkData = document.getElementById("linkData");
  68.   gDialog.ActiveLinkData = document.getElementById("aLinkData");
  69.   gDialog.VisitedLinkData = document.getElementById("fLinkData");
  70.   gDialog.BackgroundColorData = document.getElementById("backgroundColorData");
  71.   gDialog.BackgroundImageData = document.getElementById("backgroundImageData");
  72.  
  73.   browserColors = GetDefaultBrowserColors();
  74.  
  75.   // Use author's browser pref colors passed into dialog
  76.   defaultTextColor = browserColors.TextColor;
  77.   defaultLinkColor = browserColors.LinkColor;
  78.   defaultActiveColor = browserColors.ActiveLinkColor;
  79.   defaultVisitedColor =  browserColors.VisitedLinkColor;
  80.   defaultBackgroundColor=  browserColors.BackgroundColor;
  81.  
  82.   // Get the colors and image set by prefs init code 
  83.   customTextColor = gDialog.NormalData.getAttribute("value"); 
  84.   customLinkColor = gDialog.LinkData.getAttribute("value");
  85.   customActiveColor = gDialog.ActiveLinkData.getAttribute("value");
  86.   customVisitedColor = gDialog.VisitedLinkData.getAttribute("value");
  87.   customBackgroundColor = gDialog.BackgroundColorData.getAttribute("value");
  88.   backgroundImage = gDialog.BackgroundImageData.getAttribute("value");
  89.   if (backgroundImage)
  90.     gDialog.BackgroundImageInput.value = backgroundImage;
  91.  
  92.   // "value" attribute value is a string conversion of boolean!
  93.   if( document.getElementById( "useCustomColors" ).value == "true" )
  94.     UseCustomColors();
  95.   else
  96.     UseDefaultColors();
  97.  
  98.   return true;
  99. }                   
  100.  
  101. function GetColorAndUpdate(ColorWellID)
  102. {
  103.   // Only allow selecting when in custom mode
  104.   if (!gDialog.CustomColorsRadio.selected) return;
  105.  
  106.   var colorWell = document.getElementById(ColorWellID);
  107.   if (!colorWell) return;
  108.  
  109.   // Don't allow a blank color, i.e., using the "default"
  110.   var colorObj = { NoDefault:true, Type:"", TextColor:0, PageColor:0, Cancel:false };
  111.  
  112.   switch( ColorWellID )
  113.   {
  114.     case "textCW":
  115.       colorObj.Type = "Text";
  116.       colorObj.TextColor = customTextColor;
  117.       break;
  118.     case "linkCW":
  119.       colorObj.Type = "Link";
  120.       colorObj.TextColor = customLinkColor;
  121.       break;
  122.     case "activeCW":
  123.       colorObj.Type = "ActiveLink";
  124.       colorObj.TextColor = customActiveColor;
  125.       break;
  126.     case "visitedCW":
  127.       colorObj.Type = "VisitedLink";
  128.       colorObj.TextColor = customVisitedColor;
  129.       break;
  130.     case "backgroundCW":
  131.       colorObj.Type = "Page";
  132.       colorObj.PageColor = customBackgroundColor;
  133.       break;
  134.   }
  135.  
  136.   window.openDialog("chrome://editor/content/EdColorPicker.xul", "_blank", "chrome,close,titlebar,modal", "", colorObj);
  137.  
  138.   // User canceled the dialog
  139.   if (colorObj.Cancel)
  140.     return;
  141.  
  142.   var color = "";
  143.   switch( ColorWellID )
  144.   {
  145.     case "textCW":
  146.       color = customTextColor = colorObj.TextColor;
  147.       gDialog.NormalData.setAttribute("value", color); 
  148.       break;
  149.     case "linkCW":
  150.       color = customLinkColor = colorObj.TextColor;
  151.       gDialog.LinkData.setAttribute("value", color);
  152.       break;
  153.     case "activeCW":
  154.       color = customActiveColor = colorObj.TextColor;
  155.       gDialog.ActiveLinkData.setAttribute("value", color);
  156.       break;
  157.     case "visitedCW":
  158.       color = customVisitedColor = colorObj.TextColor;
  159.       gDialog.VisitedLinkData.setAttribute("value", color);
  160.       break;
  161.     case "backgroundCW":
  162.       color = customBackgroundColor = colorObj.BackgroundColor;
  163.       gDialog.BackgroundColorData.setAttribute("value", color);
  164.       break;
  165.   }
  166.   setColorWell(ColorWellID, color); 
  167.   SetColorPreview(ColorWellID, color);
  168. }
  169.  
  170. function SetColorPreview(ColorWellID, color)
  171. {
  172.   switch( ColorWellID )
  173.   {
  174.     case "textCW":
  175.       gDialog.NormalText.setAttribute(styleStr,colorStyle+color);
  176.       break;
  177.     case "linkCW":
  178.       gDialog.LinkText.setAttribute(styleStr,colorStyle+color);
  179.       break;
  180.     case "activeCW":
  181.       gDialog.ActiveLinkText.setAttribute(styleStr,colorStyle+color);
  182.       break;
  183.     case "visitedCW":
  184.       gDialog.VisitedLinkText.setAttribute(styleStr,colorStyle+color);
  185.       break;
  186.     case "backgroundCW":
  187.       // Must combine background color and image style values
  188.       var styleValue = backColorStyle+color;
  189.       if (backgroundImage)
  190.         styleValue += ";"+backImageStyle+backgroundImage+");";
  191.  
  192.       gDialog.ColorPreview.setAttribute(styleStr,styleValue);
  193.       previewBGColor = color;
  194.       break;
  195.   }
  196. }
  197.  
  198. function UseCustomColors()
  199. {
  200.   SetElementEnabledById("TextButton", true);
  201.   SetElementEnabledById("LinkButton", true);
  202.   SetElementEnabledById("ActiveLinkButton", true);
  203.   SetElementEnabledById("VisitedLinkButton", true);
  204.   SetElementEnabledById("BackgroundButton", true);
  205.   SetElementEnabledById("Text", true);
  206.   SetElementEnabledById("Link", true);
  207.   SetElementEnabledById("Active", true);
  208.   SetElementEnabledById("Visited", true);
  209.   SetElementEnabledById("Background", true);
  210.  
  211.   SetColorPreview("textCW",       customTextColor);
  212.   SetColorPreview("linkCW",       customLinkColor);
  213.   SetColorPreview("activeCW",     customActiveColor);
  214.   SetColorPreview("visitedCW",    customVisitedColor);
  215.   SetColorPreview("backgroundCW", customBackgroundColor);
  216.  
  217.   setColorWell("textCW",          customTextColor);
  218.   setColorWell("linkCW",          customLinkColor);
  219.   setColorWell("activeCW",        customActiveColor);
  220.   setColorWell("visitedCW",       customVisitedColor);
  221.   setColorWell("backgroundCW",    customBackgroundColor);
  222.  
  223.   gDialog.NormalData.setAttribute("value",          customTextColor); 
  224.   gDialog.LinkData.setAttribute("value",            customLinkColor);
  225.   gDialog.ActiveLinkData.setAttribute("value",      customActiveColor);
  226.   gDialog.VisitedLinkData.setAttribute("value",     customVisitedColor);
  227.   gDialog.BackgroundColorData.setAttribute("value", customBackgroundColor);
  228. }
  229.  
  230. function UseDefaultColors()
  231. {
  232.   SetColorPreview("textCW",       defaultTextColor);
  233.   SetColorPreview("linkCW",       defaultLinkColor);
  234.   SetColorPreview("activeCW",     defaultActiveColor);
  235.   SetColorPreview("visitedCW",    defaultVisitedColor);
  236.   SetColorPreview("backgroundCW", defaultBackgroundColor);
  237.  
  238.   // Setting to blank color will remove color from buttons,
  239.   setColorWell("textCW",       "");
  240.   setColorWell("linkCW",       "");
  241.   setColorWell("activeCW",     "");
  242.   setColorWell("visitedCW",    "");
  243.   setColorWell("backgroundCW", "");
  244.  
  245.   // Disable color buttons and labels
  246.   SetElementEnabledById("TextButton", false);
  247.   SetElementEnabledById("LinkButton", false);
  248.   SetElementEnabledById("ActiveLinkButton", false);
  249.   SetElementEnabledById("VisitedLinkButton", false);
  250.   SetElementEnabledById("BackgroundButton", false);
  251.   SetElementEnabledById("Text", false);
  252.   SetElementEnabledById("Link", false);
  253.   SetElementEnabledById("Active", false);
  254.   SetElementEnabledById("Visited", false);
  255.   SetElementEnabledById("Background", false);
  256.   
  257.   // Note that we leave custom colors set even if 
  258.   //  custom colors pref is false (we just ignore the colors)
  259. }
  260.   
  261. function ChooseImageFile()
  262. {
  263.   // Get a local image file, converted into URL format
  264.   var fileName = GetLocalFileURL("img");
  265.   if (fileName)
  266.   {
  267.     gDialog.BackgroundImageInput.value = fileName;
  268.     ValidateAndPreviewImage(true);
  269.   }
  270.   SetTextboxFocus(gDialog.BackgroundImageInput);
  271. }
  272.  
  273. function ChangeBackgroundImage()
  274. {
  275.   // Don't show error message for image while user is typing
  276.   ValidateAndPreviewImage(false);
  277. }
  278.  
  279. function ValidateAndPreviewImage(ShowErrorMessage)
  280. {
  281.   // First make a string with just background color
  282.   var styleValue = backColorStyle+previewBGColor+";";
  283.  
  284.   var image = TrimString(gDialog.BackgroundImageInput.value);
  285.   if (image)
  286.   {
  287.     backgroundImage = image;
  288.     // Append image style
  289.     styleValue += backImageStyle+backgroundImage+");";
  290.   }
  291.   else
  292.     backgroundImage = "";
  293.  
  294.   // Set style on preview (removes image if not valid)
  295.   gDialog.ColorPreview.setAttribute(styleStr, styleValue);
  296.   
  297.   // Set the pref data so pref code saves it 
  298.   gDialog.BackgroundImageData.setAttribute("value", backgroundImage ? backgroundImage : "");
  299. }
  300.  
  301.