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/
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.
12
* The Original Code is Mozilla Communicator client code, released
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
22
// This is mostly a modified version of code in EdColorProps.xul
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";
33
var customActiveColor;
34
var customVisitedColor;
35
var customBackgroundColor;
37
var backgroundImage = "";
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(";
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");
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
gDialog.active_charset = document.getElementById("active_charset");
74
browserColors = GetDefaultBrowserColors();
76
// Use author's browser pref colors passed into dialog
77
defaultTextColor = browserColors.TextColor;
78
defaultLinkColor = browserColors.LinkColor;
79
defaultActiveColor = browserColors.ActiveLinkColor;
80
defaultVisitedColor = browserColors.VisitedLinkColor;
81
defaultBackgroundColor= browserColors.BackgroundColor;
83
// Get the colors and image set by prefs init code
84
customTextColor = gDialog.NormalData.getAttribute("value");
85
customLinkColor = gDialog.LinkData.getAttribute("value");
86
customActiveColor = gDialog.ActiveLinkData.getAttribute("value");
87
customVisitedColor = gDialog.VisitedLinkData.getAttribute("value");
88
customBackgroundColor = gDialog.BackgroundColorData.getAttribute("value");
89
backgroundImage = gDialog.BackgroundImageData.getAttribute("value");
91
gDialog.BackgroundImageInput.value = backgroundImage;
93
// "value" attribute value is a string conversion of boolean!
94
if( document.getElementById( "useCustomColors" ).value == "true" )
102
function GetColorAndUpdate(ColorWellID)
104
// Only allow selecting when in custom mode
105
if (!gDialog.CustomColorsRadio.selected) return;
107
var colorWell = document.getElementById(ColorWellID);
108
if (!colorWell) return;
110
// Don't allow a blank color, i.e., using the "default"
111
var colorObj = { NoDefault:true, Type:"", TextColor:0, PageColor:0, Cancel:false };
113
switch( ColorWellID )
116
colorObj.Type = "Text";
117
colorObj.TextColor = customTextColor;
120
colorObj.Type = "Link";
121
colorObj.TextColor = customLinkColor;
124
colorObj.Type = "ActiveLink";
125
colorObj.TextColor = customActiveColor;
128
colorObj.Type = "VisitedLink";
129
colorObj.TextColor = customVisitedColor;
132
colorObj.Type = "Page";
133
colorObj.PageColor = customBackgroundColor;
137
window.openDialog("chrome://editor/content/EdColorPicker.xul", "_blank", "chrome,close,titlebar,modal", "", colorObj);
139
// User canceled the dialog
144
switch( ColorWellID )
147
color = customTextColor = colorObj.TextColor;
148
gDialog.NormalData.setAttribute("value", color);
151
color = customLinkColor = colorObj.TextColor;
152
gDialog.LinkData.setAttribute("value", color);
155
color = customActiveColor = colorObj.TextColor;
156
gDialog.ActiveLinkData.setAttribute("value", color);
159
color = customVisitedColor = colorObj.TextColor;
160
gDialog.VisitedLinkData.setAttribute("value", color);
163
color = customBackgroundColor = colorObj.BackgroundColor;
164
gDialog.BackgroundColorData.setAttribute("value", color);
167
setColorWell(ColorWellID, color);
168
SetColorPreview(ColorWellID, color);
171
function SetColorPreview(ColorWellID, color)
173
switch( ColorWellID )
176
gDialog.NormalText.setAttribute(styleStr,colorStyle+color);
179
gDialog.LinkText.setAttribute(styleStr,colorStyle+color);
182
gDialog.ActiveLinkText.setAttribute(styleStr,colorStyle+color);
185
gDialog.VisitedLinkText.setAttribute(styleStr,colorStyle+color);
188
// Must combine background color and image style values
189
var styleValue = backColorStyle+color;
191
styleValue += ";"+backImageStyle+backgroundImage+");";
193
gDialog.ColorPreview.setAttribute(styleStr,styleValue);
194
previewBGColor = color;
199
function UseCustomColors()
201
SetElementEnabledById("TextButton", true);
202
SetElementEnabledById("LinkButton", true);
203
SetElementEnabledById("ActiveLinkButton", true);
204
SetElementEnabledById("VisitedLinkButton", true);
205
SetElementEnabledById("BackgroundButton", true);
206
SetElementEnabledById("Text", true);
207
SetElementEnabledById("Link", true);
208
SetElementEnabledById("Active", true);
209
SetElementEnabledById("Visited", true);
210
SetElementEnabledById("Background", true);
212
SetColorPreview("textCW", customTextColor);
213
SetColorPreview("linkCW", customLinkColor);
214
SetColorPreview("activeCW", customActiveColor);
215
SetColorPreview("visitedCW", customVisitedColor);
216
SetColorPreview("backgroundCW", customBackgroundColor);
218
setColorWell("textCW", customTextColor);
219
setColorWell("linkCW", customLinkColor);
220
setColorWell("activeCW", customActiveColor);
221
setColorWell("visitedCW", customVisitedColor);
222
setColorWell("backgroundCW", customBackgroundColor);
224
gDialog.NormalData.setAttribute("value", customTextColor);
225
gDialog.LinkData.setAttribute("value", customLinkColor);
226
gDialog.ActiveLinkData.setAttribute("value", customActiveColor);
227
gDialog.VisitedLinkData.setAttribute("value", customVisitedColor);
228
gDialog.BackgroundColorData.setAttribute("value", customBackgroundColor);
231
function UseDefaultColors()
233
SetColorPreview("textCW", defaultTextColor);
234
SetColorPreview("linkCW", defaultLinkColor);
235
SetColorPreview("activeCW", defaultActiveColor);
236
SetColorPreview("visitedCW", defaultVisitedColor);
237
SetColorPreview("backgroundCW", defaultBackgroundColor);
239
// Setting to blank color will remove color from buttons,
240
setColorWell("textCW", "");
241
setColorWell("linkCW", "");
242
setColorWell("activeCW", "");
243
setColorWell("visitedCW", "");
244
setColorWell("backgroundCW", "");
246
// Disable color buttons and labels
247
SetElementEnabledById("TextButton", false);
248
SetElementEnabledById("LinkButton", false);
249
SetElementEnabledById("ActiveLinkButton", false);
250
SetElementEnabledById("VisitedLinkButton", false);
251
SetElementEnabledById("BackgroundButton", false);
252
SetElementEnabledById("Text", false);
253
SetElementEnabledById("Link", false);
254
SetElementEnabledById("Active", false);
255
SetElementEnabledById("Visited", false);
256
SetElementEnabledById("Background", false);
258
// Note that we leave custom colors set even if
259
// custom colors pref is false (we just ignore the colors)
262
function ChooseImageFile()
264
// Get a local image file, converted into URL format
265
var fileName = GetLocalFileURL("img");
268
gDialog.BackgroundImageInput.value = fileName;
269
ValidateAndPreviewImage(true);
271
SetTextboxFocus(gDialog.BackgroundImageInput);
274
function ChangeBackgroundImage()
276
// Don't show error message for image while user is typing
277
ValidateAndPreviewImage(false);
280
function ValidateAndPreviewImage(ShowErrorMessage)
282
// First make a string with just background color
283
var styleValue = backColorStyle+previewBGColor+";";
285
var image = TrimString(gDialog.BackgroundImageInput.value);
288
backgroundImage = image;
289
// Append image style
290
styleValue += backImageStyle+backgroundImage+");";
293
backgroundImage = "";
295
// Set style on preview (removes image if not valid)
296
gDialog.ColorPreview.setAttribute(styleStr, styleValue);
298
// Set the pref data so pref code saves it
299
gDialog.BackgroundImageData.setAttribute("value", backgroundImage ? backgroundImage : "");
302
function ChooseLanguage()
304
window.openDialog("chrome://communicator/content/pref/pref-languages-add.xul","_blank","modal,chrome,centerscreen,titlebar", "addlangwindow");
307
function ChooseCharset()
309
window.openDialog("chrome://communicator/content/pref/pref-charset-add.xul","_blank","modal,chrome,centerscreen,titlebar", gDialog.active_charset.value);
312
function SelectCharset(charset)
314
gDialog.active_charset.value = charset;