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