~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/composer/components/prefwindow/content/pref-composer.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  gDialog.active_charset = document.getElementById("active_charset");
 
73
 
 
74
  browserColors = GetDefaultBrowserColors();
 
75
 
 
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;
 
82
 
 
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");
 
90
  if (backgroundImage)
 
91
    gDialog.BackgroundImageInput.value = backgroundImage;
 
92
 
 
93
  // "value" attribute value is a string conversion of boolean!
 
94
  if( document.getElementById( "useCustomColors" ).value == "true" )
 
95
    UseCustomColors();
 
96
  else
 
97
    UseDefaultColors();
 
98
 
 
99
  return true;
 
100
}                   
 
101
 
 
102
function GetColorAndUpdate(ColorWellID)
 
103
{
 
104
  // Only allow selecting when in custom mode
 
105
  if (!gDialog.CustomColorsRadio.selected) return;
 
106
 
 
107
  var colorWell = document.getElementById(ColorWellID);
 
108
  if (!colorWell) return;
 
109
 
 
110
  // Don't allow a blank color, i.e., using the "default"
 
111
  var colorObj = { NoDefault:true, Type:"", TextColor:0, PageColor:0, Cancel:false };
 
112
 
 
113
  switch( ColorWellID )
 
114
  {
 
115
    case "textCW":
 
116
      colorObj.Type = "Text";
 
117
      colorObj.TextColor = customTextColor;
 
118
      break;
 
119
    case "linkCW":
 
120
      colorObj.Type = "Link";
 
121
      colorObj.TextColor = customLinkColor;
 
122
      break;
 
123
    case "activeCW":
 
124
      colorObj.Type = "ActiveLink";
 
125
      colorObj.TextColor = customActiveColor;
 
126
      break;
 
127
    case "visitedCW":
 
128
      colorObj.Type = "VisitedLink";
 
129
      colorObj.TextColor = customVisitedColor;
 
130
      break;
 
131
    case "backgroundCW":
 
132
      colorObj.Type = "Page";
 
133
      colorObj.PageColor = customBackgroundColor;
 
134
      break;
 
135
  }
 
136
 
 
137
  window.openDialog("chrome://editor/content/EdColorPicker.xul", "_blank", "chrome,close,titlebar,modal", "", colorObj);
 
138
 
 
139
  // User canceled the dialog
 
140
  if (colorObj.Cancel)
 
141
    return;
 
142
 
 
143
  var color = "";
 
144
  switch( ColorWellID )
 
145
  {
 
146
    case "textCW":
 
147
      color = customTextColor = colorObj.TextColor;
 
148
      gDialog.NormalData.setAttribute("value", color); 
 
149
      break;
 
150
    case "linkCW":
 
151
      color = customLinkColor = colorObj.TextColor;
 
152
      gDialog.LinkData.setAttribute("value", color);
 
153
      break;
 
154
    case "activeCW":
 
155
      color = customActiveColor = colorObj.TextColor;
 
156
      gDialog.ActiveLinkData.setAttribute("value", color);
 
157
      break;
 
158
    case "visitedCW":
 
159
      color = customVisitedColor = colorObj.TextColor;
 
160
      gDialog.VisitedLinkData.setAttribute("value", color);
 
161
      break;
 
162
    case "backgroundCW":
 
163
      color = customBackgroundColor = colorObj.BackgroundColor;
 
164
      gDialog.BackgroundColorData.setAttribute("value", color);
 
165
      break;
 
166
  }
 
167
  setColorWell(ColorWellID, color); 
 
168
  SetColorPreview(ColorWellID, color);
 
169
}
 
170
 
 
171
function SetColorPreview(ColorWellID, color)
 
172
{
 
173
  switch( ColorWellID )
 
174
  {
 
175
    case "textCW":
 
176
      gDialog.NormalText.setAttribute(styleStr,colorStyle+color);
 
177
      break;
 
178
    case "linkCW":
 
179
      gDialog.LinkText.setAttribute(styleStr,colorStyle+color);
 
180
      break;
 
181
    case "activeCW":
 
182
      gDialog.ActiveLinkText.setAttribute(styleStr,colorStyle+color);
 
183
      break;
 
184
    case "visitedCW":
 
185
      gDialog.VisitedLinkText.setAttribute(styleStr,colorStyle+color);
 
186
      break;
 
187
    case "backgroundCW":
 
188
      // Must combine background color and image style values
 
189
      var styleValue = backColorStyle+color;
 
190
      if (backgroundImage)
 
191
        styleValue += ";"+backImageStyle+backgroundImage+");";
 
192
 
 
193
      gDialog.ColorPreview.setAttribute(styleStr,styleValue);
 
194
      previewBGColor = color;
 
195
      break;
 
196
  }
 
197
}
 
198
 
 
199
function UseCustomColors()
 
200
{
 
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);
 
211
 
 
212
  SetColorPreview("textCW",       customTextColor);
 
213
  SetColorPreview("linkCW",       customLinkColor);
 
214
  SetColorPreview("activeCW",     customActiveColor);
 
215
  SetColorPreview("visitedCW",    customVisitedColor);
 
216
  SetColorPreview("backgroundCW", customBackgroundColor);
 
217
 
 
218
  setColorWell("textCW",          customTextColor);
 
219
  setColorWell("linkCW",          customLinkColor);
 
220
  setColorWell("activeCW",        customActiveColor);
 
221
  setColorWell("visitedCW",       customVisitedColor);
 
222
  setColorWell("backgroundCW",    customBackgroundColor);
 
223
 
 
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);
 
229
}
 
230
 
 
231
function UseDefaultColors()
 
232
{
 
233
  SetColorPreview("textCW",       defaultTextColor);
 
234
  SetColorPreview("linkCW",       defaultLinkColor);
 
235
  SetColorPreview("activeCW",     defaultActiveColor);
 
236
  SetColorPreview("visitedCW",    defaultVisitedColor);
 
237
  SetColorPreview("backgroundCW", defaultBackgroundColor);
 
238
 
 
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", "");
 
245
 
 
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);
 
257
  
 
258
  // Note that we leave custom colors set even if 
 
259
  //  custom colors pref is false (we just ignore the colors)
 
260
}
 
261
  
 
262
function ChooseImageFile()
 
263
{
 
264
  // Get a local image file, converted into URL format
 
265
  var fileName = GetLocalFileURL("img");
 
266
  if (fileName)
 
267
  {
 
268
    gDialog.BackgroundImageInput.value = fileName;
 
269
    ValidateAndPreviewImage(true);
 
270
  }
 
271
  SetTextboxFocus(gDialog.BackgroundImageInput);
 
272
}
 
273
 
 
274
function ChangeBackgroundImage()
 
275
{
 
276
  // Don't show error message for image while user is typing
 
277
  ValidateAndPreviewImage(false);
 
278
}
 
279
 
 
280
function ValidateAndPreviewImage(ShowErrorMessage)
 
281
{
 
282
  // First make a string with just background color
 
283
  var styleValue = backColorStyle+previewBGColor+";";
 
284
 
 
285
  var image = TrimString(gDialog.BackgroundImageInput.value);
 
286
  if (image)
 
287
  {
 
288
    backgroundImage = image;
 
289
    // Append image style
 
290
    styleValue += backImageStyle+backgroundImage+");";
 
291
  }
 
292
  else
 
293
    backgroundImage = "";
 
294
 
 
295
  // Set style on preview (removes image if not valid)
 
296
  gDialog.ColorPreview.setAttribute(styleStr, styleValue);
 
297
  
 
298
  // Set the pref data so pref code saves it 
 
299
  gDialog.BackgroundImageData.setAttribute("value", backgroundImage ? backgroundImage : "");
 
300
}
 
301
 
 
302
function ChooseLanguage()
 
303
{
 
304
  window.openDialog("chrome://communicator/content/pref/pref-languages-add.xul","_blank","modal,chrome,centerscreen,titlebar", "addlangwindow");
 
305
}
 
306
 
 
307
function ChooseCharset()
 
308
{
 
309
  window.openDialog("chrome://communicator/content/pref/pref-charset-add.xul","_blank","modal,chrome,centerscreen,titlebar", gDialog.active_charset.value);
 
310
}
 
311
 
 
312
function SelectCharset(charset)
 
313
{
 
314
  gDialog.active_charset.value = charset;
 
315
}