content.js
Go to the documentation of this file.
1 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 #
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
9 #
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
14 #
15 # The Original Code is the Firefox Preferences System.
16 #
17 # The Initial Developer of the Original Code is
18 # Google Inc.
19 # Portions created by the Initial Developer are Copyright (C) 2005
20 # the Initial Developer. All Rights Reserved.
21 #
22 # Contributor(s):
23 # Ben Goodger <ben@mozilla.org>
24 # Asaf Romano <mozilla.mano@sent.com>
25 # Jeff Walden <jwalden+code@mit.edu>
26 #
27 # Alternatively, the contents of this file may be used under the terms of
28 # either the GNU General Public License Version 2 or later (the "GPL"), or
29 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 # in which case the provisions of the GPL or the LGPL are applicable instead
31 # of those above. If you wish to allow use of your version of this file only
32 # under the terms of either the GPL or the LGPL, and not to allow others to
33 # use your version of this file under the terms of the MPL, indicate your
34 # decision by deleting the provisions above and replace them with the notice
35 # and other provisions required by the GPL or the LGPL. If you do not delete
36 # the provisions above, a recipient may use your version of this file under
37 # the terms of any one of the MPL, the GPL or the LGPL.
38 #
39 # ***** END LICENSE BLOCK *****
40 
41 var gContentPane = {
42 
46  init: function ()
47  {
48  this._rebuildFonts();
49  var menulist = document.getElementById("defaultFont");
50  if (menulist.selectedIndex == -1) {
51  menulist.insertItemAt(0, "", "", "");
52  menulist.selectedIndex = 0;
53  }
54  },
55 
56  // UTILITY FUNCTIONS
57 
62  updateButtons: function (aButtonID, aPreferenceID)
63  {
64  var button = document.getElementById(aButtonID);
65  var preference = document.getElementById(aPreferenceID);
66  button.disabled = preference.value != true;
67  return undefined;
68  },
69 
73  _exceptionsParams: {
74  popup: { blockVisible: false, sessionVisible: false, allowVisible: true, prefilledHost: "", permissionType: "popup" },
75  image: { blockVisible: true, sessionVisible: false, allowVisible: true, prefilledHost: "", permissionType: "image" }
76  },
77 
82  _showExceptions: function (aPermissionType)
83  {
84  var bundlePreferences = document.getElementById("bundlePreferences");
85  var params = this._exceptionsParams[aPermissionType];
86  params.windowTitle = bundlePreferences.getString(aPermissionType + "permissionstitle");
87  params.introText = bundlePreferences.getString(aPermissionType + "permissionstext");
88  document.documentElement.openWindow("Browser:Permissions",
89  "chrome://browser/content/preferences/permissions.xul",
90  "", params);
91  },
92 
93  // BEGIN UI CODE
94 
95  /*
96  * Preferences:
97  *
98  * dom.disable_open_during_load
99  * - true if popups are blocked by default, false otherwise
100  * permissions.default.image
101  * - an integer:
102  * 1 all images should be loaded,
103  * 2 no images should be loaded,
104  * 3 load only images from the site on which the current page resides
105  * (i.e., if viewing foo.example.com, foo.example.com/foo.jpg and
106  * bar.foo.example.com/bar.jpg load but example.com/quux.jpg does not)
107  * javascript.enabled
108  * - true if JavaScript is enabled, false otherwise
109  */
110 
111  // POP-UPS
112 
117  showPopupExceptions: function ()
118  {
119  this._showExceptions("popup");
120  },
121 
122  // IMAGES
123 
129  readLoadImages: function ()
130  {
131  var pref = document.getElementById("permissions.default.image");
132  return (pref.value == 1 || pref.value == 3);
133  },
134 
139  writeLoadImages: function ()
140  {
141  return (document.getElementById("loadImages").checked) ? 1 : 2;
142  },
143 
148  showImageExceptions: function ()
149  {
150  this._showExceptions("image");
151  },
152 
153  // JAVASCRIPT
154 
159  showAdvancedJS: function ()
160  {
161  document.documentElement.openSubDialog("chrome://browser/content/preferences/advanced-scripts.xul",
162  "", null);
163  },
164 
165  // FONTS
166 
170  _rebuildFonts: function ()
171  {
172  var langGroupPref = document.getElementById("font.language.group");
173  this._selectDefaultLanguageGroup(langGroupPref.value,
174  this._readDefaultFontTypeForLanguage(langGroupPref.value) == "serif");
175  },
176 
180  _selectDefaultLanguageGroup: function (aLanguageGroup, aIsSerif)
181  {
182  const kFontNameFmtSerif = "font.name.serif.%LANG%";
183  const kFontNameFmtSansSerif = "font.name.sans-serif.%LANG%";
184  const kFontNameListFmtSerif = "font.name-list.serif.%LANG%";
185  const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%";
186  const kFontSizeFmtVariable = "font.size.variable.%LANG%";
187 
188  var prefs = [{ format : aIsSerif ? kFontNameFmtSerif : kFontNameFmtSansSerif,
189  type : "fontname",
190  element : "defaultFont",
191  fonttype : aIsSerif ? "serif" : "sans-serif" },
192  { format : aIsSerif ? kFontNameListFmtSerif : kFontNameListFmtSansSerif,
193  type : "unichar",
194  element : null,
195  fonttype : aIsSerif ? "serif" : "sans-serif" },
196  { format : kFontSizeFmtVariable,
197  type : "int",
198  element : "defaultFontSize",
199  fonttype : null }];
200  var preferences = document.getElementById("contentPreferences");
201  for (var i = 0; i < prefs.length; ++i) {
202  var preference = document.getElementById(prefs[i].format.replace(/%LANG%/, aLanguageGroup));
203  if (!preference) {
204  preference = document.createElement("preference");
205  var name = prefs[i].format.replace(/%LANG%/, aLanguageGroup);
206  preference.id = name;
207  preference.setAttribute("name", name);
208  preference.setAttribute("type", prefs[i].type);
209  preferences.appendChild(preference);
210  }
211 
212  if (!prefs[i].element)
213  continue;
214 
215  var element = document.getElementById(prefs[i].element);
216  if (element) {
217  element.setAttribute("preference", preference.id);
218 
219  if (prefs[i].fonttype)
220  FontBuilder.buildFontList(aLanguageGroup, prefs[i].fonttype, element);
221 
222  preference.setElementValue(element);
223  }
224  }
225  },
226 
231  _readDefaultFontTypeForLanguage: function (aLanguageGroup)
232  {
233  const kDefaultFontType = "font.default.%LANG%";
234  var defaultFontTypePref = kDefaultFontType.replace(/%LANG%/, aLanguageGroup);
235  var preference = document.getElementById(defaultFontTypePref);
236  if (!preference) {
237  preference = document.createElement("preference");
238  preference.id = defaultFontTypePref;
239  preference.setAttribute("name", defaultFontTypePref);
240  preference.setAttribute("type", "string");
241  preference.setAttribute("onchange", "gContentPane._rebuildFonts();");
242  document.getElementById("contentPreferences").appendChild(preference);
243  }
244  return preference.value;
245  },
246 
251  configureFonts: function ()
252  {
253  document.documentElement.openSubDialog("chrome://browser/content/preferences/fonts.xul",
254  "", null);
255  },
256 
261  configureColors: function ()
262  {
263  document.documentElement.openSubDialog("chrome://browser/content/preferences/colors.xul",
264  "", null);
265  },
266 
267  // LANGUAGES
268 
272  showLanguages: function ()
273  {
274  document.documentElement.openSubDialog("chrome://browser/content/preferences/languages.xul",
275  "", null);
276  }
277 };
const kFontSizeFmtVariable
Definition: fonts.js:49
var pref
Definition: openLocation.js:44
playlistfolders preferences
Definition: preferences.js:13
const kDefaultFontType
Definition: fonts.js:42
_window init
Definition: FeedWriter.js:1144
const kFontNameFmtSansSerif
Definition: fonts.js:44
const kFontNameFmtSerif
Definition: fonts.js:43
const kFontNameListFmtSerif
Definition: fonts.js:46
return null
Definition: FeedWriter.js:1143
var prefs
Definition: FeedWriter.js:1169
const kFontNameListFmtSansSerif
Definition: fonts.js:47
_getSelectedPageStyle s i
var gContentPane
Definition: content.js:41