browser/metro/base/content/pages/config.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 "use strict";
michael@0 5
michael@0 6 const {classes: Cc, interfaces: Ci, manager: Cm, utils: Cu} = Components;
michael@0 7 Cu.import("resource://gre/modules/Services.jsm");
michael@0 8
michael@0 9 const INITIAL_PAGE_DELAY = 500; // Initial pause on program start for scroll alignment
michael@0 10 const PREFS_BUFFER_MAX = 100; // Max prefs buffer size for getPrefsBuffer()
michael@0 11 const PAGE_SCROLL_TRIGGER = 200; // Triggers additional getPrefsBuffer() on user scroll-to-bottom
michael@0 12 const FILTER_CHANGE_TRIGGER = 200; // Delay between responses to filterInput changes
michael@0 13 const INNERHTML_VALUE_DELAY = 100; // Delay before providing prefs innerHTML value
michael@0 14
michael@0 15 let gStringBundle = Services.strings.createBundle("chrome://browser/locale/config.properties");
michael@0 16 let gClipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
michael@0 17
michael@0 18
michael@0 19 /* ============================== NewPrefDialog ==============================
michael@0 20 *
michael@0 21 * New Preference Dialog Object and methods
michael@0 22 *
michael@0 23 * Implements User Interfaces for creation of a single(new) Preference setting
michael@0 24 *
michael@0 25 */
michael@0 26 var NewPrefDialog = {
michael@0 27
michael@0 28 _prefsShield: null,
michael@0 29
michael@0 30 _newPrefsDialog: null,
michael@0 31 _newPrefItem: null,
michael@0 32 _prefNameInputElt: null,
michael@0 33 _prefTypeSelectElt: null,
michael@0 34
michael@0 35 _booleanValue: null,
michael@0 36 _booleanToggle: null,
michael@0 37 _stringValue: null,
michael@0 38 _intValue: null,
michael@0 39
michael@0 40 _positiveButton: null,
michael@0 41
michael@0 42 get type() {
michael@0 43 return this._prefTypeSelectElt.value;
michael@0 44 },
michael@0 45
michael@0 46 set type(aType) {
michael@0 47 this._prefTypeSelectElt.value = aType;
michael@0 48 switch(this._prefTypeSelectElt.value) {
michael@0 49 case "boolean":
michael@0 50 this._prefTypeSelectElt.selectedIndex = 0;
michael@0 51 break;
michael@0 52 case "string":
michael@0 53 this._prefTypeSelectElt.selectedIndex = 1;
michael@0 54 break;
michael@0 55 case "int":
michael@0 56 this._prefTypeSelectElt.selectedIndex = 2;
michael@0 57 break;
michael@0 58 }
michael@0 59
michael@0 60 this._newPrefItem.setAttribute("typestyle", aType);
michael@0 61 },
michael@0 62
michael@0 63 // Init the NewPrefDialog
michael@0 64 init: function AC_init() {
michael@0 65 this._prefsShield = document.getElementById("prefs-shield");
michael@0 66
michael@0 67 this._newPrefsDialog = document.getElementById("new-pref-container");
michael@0 68 this._newPrefItem = document.getElementById("new-pref-item");
michael@0 69 this._prefNameInputElt = document.getElementById("new-pref-name");
michael@0 70 this._prefTypeSelectElt = document.getElementById("new-pref-type");
michael@0 71
michael@0 72 this._booleanValue = document.getElementById("new-pref-value-boolean");
michael@0 73 this._stringValue = document.getElementById("new-pref-value-string");
michael@0 74 this._intValue = document.getElementById("new-pref-value-int");
michael@0 75
michael@0 76 this._positiveButton = document.getElementById("positive-button");
michael@0 77 },
michael@0 78
michael@0 79 // Called to update positive button to display text ("Create"/"Change), and enabled/disabled status
michael@0 80 // As new pref name is initially displayed, re-focused, or modifed during user input
michael@0 81 _updatePositiveButton: function AC_updatePositiveButton(aPrefName) {
michael@0 82 this._positiveButton.textContent = gStringBundle.GetStringFromName("newPref.createButton");
michael@0 83 this._positiveButton.setAttribute("disabled", true);
michael@0 84 if (aPrefName == "") {
michael@0 85 return;
michael@0 86 }
michael@0 87
michael@0 88 // If item already in list, it's being changed, else added
michael@0 89 let item = document.querySelector(".pref-item[name=" + aPrefName.quote() + "]");
michael@0 90 if (item) {
michael@0 91 this._positiveButton.textContent = gStringBundle.GetStringFromName("newPref.changeButton");
michael@0 92 } else {
michael@0 93 this._positiveButton.removeAttribute("disabled");
michael@0 94 }
michael@0 95 },
michael@0 96
michael@0 97 // When we want to cancel/hide an existing, or show a new pref dialog
michael@0 98 toggleShowHide: function AC_toggleShowHide() {
michael@0 99 if (this._newPrefsDialog.classList.contains("show")) {
michael@0 100 this.hide();
michael@0 101 } else {
michael@0 102 this._show();
michael@0 103 }
michael@0 104 },
michael@0 105
michael@0 106 // When we want to show the new pref dialog / shield the prefs list
michael@0 107 _show: function AC_show() {
michael@0 108 this._newPrefsDialog.classList.add("show");
michael@0 109 this._prefsShield.setAttribute("shown", true);
michael@0 110
michael@0 111 // Initial default field values
michael@0 112 this._prefNameInputElt.value = "";
michael@0 113 this._updatePositiveButton(this._prefNameInputElt.value);
michael@0 114
michael@0 115 this.type = "boolean";
michael@0 116 this._booleanValue.value = "false";
michael@0 117 this._stringValue.value = "";
michael@0 118 this._intValue.value = "";
michael@0 119
michael@0 120 this._prefNameInputElt.focus();
michael@0 121
michael@0 122 window.addEventListener("keypress", this.handleKeypress, false);
michael@0 123 },
michael@0 124
michael@0 125 // When we want to cancel/hide the new pref dialog / un-shield the prefs list
michael@0 126 hide: function AC_hide() {
michael@0 127 this._newPrefsDialog.classList.remove("show");
michael@0 128 this._prefsShield.removeAttribute("shown");
michael@0 129
michael@0 130 window.removeEventListener("keypress", this.handleKeypress, false);
michael@0 131 },
michael@0 132
michael@0 133 // Watch user key input so we can provide Enter key action, commit input values
michael@0 134 handleKeypress: function AC_handleKeypress(aEvent) {
michael@0 135 // Close our VKB on new pref enter key press
michael@0 136 if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN)
michael@0 137 aEvent.target.blur();
michael@0 138 },
michael@0 139
michael@0 140 // New prefs create dialog only allows creating a non-existing preference, doesn't allow for
michael@0 141 // Changing an existing one on-the-fly, tap existing/displayed line item pref for that
michael@0 142 create: function AC_create(aEvent) {
michael@0 143 if (this._positiveButton.getAttribute("disabled") == "true") {
michael@0 144 return;
michael@0 145 }
michael@0 146
michael@0 147 switch(this.type) {
michael@0 148 case "boolean":
michael@0 149 Services.prefs.setBoolPref(this._prefNameInputElt.value, (this._booleanValue.value == "true") ? true : false);
michael@0 150 break;
michael@0 151 case "string":
michael@0 152 Services.prefs.setCharPref(this._prefNameInputElt.value, this._stringValue.value);
michael@0 153 break;
michael@0 154 case "int":
michael@0 155 Services.prefs.setIntPref(this._prefNameInputElt.value, this._intValue.value);
michael@0 156 break;
michael@0 157 }
michael@0 158
michael@0 159 this.hide();
michael@0 160 },
michael@0 161
michael@0 162 // Display proper positive button text/state on new prefs name input focus
michael@0 163 focusName: function AC_focusName(aEvent) {
michael@0 164 this._updatePositiveButton(aEvent.target.value);
michael@0 165 },
michael@0 166
michael@0 167 // Display proper positive button text/state as user changes new prefs name
michael@0 168 updateName: function AC_updateName(aEvent) {
michael@0 169 this._updatePositiveButton(aEvent.target.value);
michael@0 170 },
michael@0 171
michael@0 172 // In new prefs dialog, bool prefs are <input type="text">, as they aren't yet tied to an
michael@0 173 // Actual Services.prefs.*etBoolPref()
michael@0 174 toggleBoolValue: function AC_toggleBoolValue() {
michael@0 175 this._booleanValue.value = (this._booleanValue.value == "true" ? "false" : "true");
michael@0 176 }
michael@0 177 }
michael@0 178
michael@0 179
michael@0 180 /* ============================== AboutConfig ==============================
michael@0 181 *
michael@0 182 * Main AboutConfig object and methods
michael@0 183 *
michael@0 184 * Implements User Interfaces for maintenance of a list of Preference settings
michael@0 185 *
michael@0 186 */
michael@0 187 var AboutConfig = {
michael@0 188
michael@0 189 filterInput: null,
michael@0 190 _filterPrevInput: null,
michael@0 191 _filterChangeTimer: null,
michael@0 192 _prefsContainer: null,
michael@0 193 _loadingContainer: null,
michael@0 194 _list: null,
michael@0 195
michael@0 196 // Init the main AboutConfig dialog
michael@0 197 init: function AC_init() {
michael@0 198 this.filterInput = document.getElementById("filter-input");
michael@0 199 this._prefsContainer = document.getElementById("prefs-container");
michael@0 200 this._loadingContainer = document.getElementById("loading-container");
michael@0 201
michael@0 202 let list = Services.prefs.getChildList("");
michael@0 203 this._list = list.sort().map( function AC_getMapPref(aPref) {
michael@0 204 return new Pref(aPref);
michael@0 205 }, this);
michael@0 206
michael@0 207 // Display the current prefs list (retains searchFilter value)
michael@0 208 this.bufferFilterInput();
michael@0 209
michael@0 210 // Setup the prefs observers
michael@0 211 Services.prefs.addObserver("", this, false);
michael@0 212 },
michael@0 213
michael@0 214 // Uninit the main AboutConfig dialog
michael@0 215 uninit: function AC_uninit() {
michael@0 216 // Remove the prefs observer
michael@0 217 Services.prefs.removeObserver("", this);
michael@0 218 },
michael@0 219
michael@0 220 // Clear the filterInput value, to display the entire list
michael@0 221 clearFilterInput: function AC_clearFilterInput() {
michael@0 222 this.filterInput.value = "";
michael@0 223 this.bufferFilterInput();
michael@0 224 },
michael@0 225
michael@0 226 // Buffer down rapid changes in filterInput value from keyboard
michael@0 227 bufferFilterInput: function AC_bufferFilterInput() {
michael@0 228 if (this._filterChangeTimer) {
michael@0 229 clearTimeout(this._filterChangeTimer);
michael@0 230 }
michael@0 231
michael@0 232 this._filterChangeTimer = setTimeout((function() {
michael@0 233 this._filterChangeTimer = null;
michael@0 234 // Display updated prefs list when filterInput value settles
michael@0 235 this._displayNewList();
michael@0 236 }).bind(this), FILTER_CHANGE_TRIGGER);
michael@0 237 },
michael@0 238
michael@0 239 // Update displayed list when filterInput value changes
michael@0 240 _displayNewList: function AC_displayNewList() {
michael@0 241 // This survives the search filter value past a page refresh
michael@0 242 this.filterInput.setAttribute("value", this.filterInput.value);
michael@0 243
michael@0 244 // Don't start new filter search if same as last
michael@0 245 if (this.filterInput.value == this._filterPrevInput) {
michael@0 246 return;
michael@0 247 }
michael@0 248 this._filterPrevInput = this.filterInput.value;
michael@0 249
michael@0 250 // Clear list item selection and prefs list, get first buffer, set scrolling on
michael@0 251 this.selected = "";
michael@0 252 this._clearPrefsContainer();
michael@0 253 this._addMorePrefsToContainer();
michael@0 254 window.onscroll = this.onScroll.bind(this);
michael@0 255
michael@0 256 // Pause for screen to settle, then ensure at top
michael@0 257 setTimeout((function() {
michael@0 258 window.scrollTo(0, 0);
michael@0 259 }).bind(this), INITIAL_PAGE_DELAY);
michael@0 260 },
michael@0 261
michael@0 262 // Clear the displayed preferences list
michael@0 263 _clearPrefsContainer: function AC_clearPrefsContainer() {
michael@0 264 // Quick clear the prefsContainer list
michael@0 265 let empty = this._prefsContainer.cloneNode(false);
michael@0 266 this._prefsContainer.parentNode.replaceChild(empty, this._prefsContainer);
michael@0 267 this._prefsContainer = empty;
michael@0 268
michael@0 269 // Quick clear the prefs li.HTML list
michael@0 270 this._list.forEach(function(item) {
michael@0 271 delete item.li;
michael@0 272 });
michael@0 273 },
michael@0 274
michael@0 275 // Get a small manageable block of prefs items, and add them to the displayed list
michael@0 276 _addMorePrefsToContainer: function AC_addMorePrefsToContainer() {
michael@0 277 // Create filter regex
michael@0 278 let filterExp = this.filterInput.value ?
michael@0 279 new RegExp(this.filterInput.value, "i") : null;
michael@0 280
michael@0 281 // Get a new block for the display list
michael@0 282 let prefsBuffer = [];
michael@0 283 for (let i = 0; i < this._list.length && prefsBuffer.length < PREFS_BUFFER_MAX; i++) {
michael@0 284 if (!this._list[i].li && this._list[i].test(filterExp)) {
michael@0 285 prefsBuffer.push(this._list[i]);
michael@0 286 }
michael@0 287 }
michael@0 288
michael@0 289 // Add the new block to the displayed list
michael@0 290 for (let i = 0; i < prefsBuffer.length; i++) {
michael@0 291 this._prefsContainer.appendChild(prefsBuffer[i].getOrCreateNewLINode());
michael@0 292 }
michael@0 293
michael@0 294 // Determine if anything left to add later by scrolling
michael@0 295 let anotherPrefsBufferRemains = false;
michael@0 296 for (let i = 0; i < this._list.length; i++) {
michael@0 297 if (!this._list[i].li && this._list[i].test(filterExp)) {
michael@0 298 anotherPrefsBufferRemains = true;
michael@0 299 break;
michael@0 300 }
michael@0 301 }
michael@0 302
michael@0 303 if (anotherPrefsBufferRemains) {
michael@0 304 // If still more could be displayed, show the throbber
michael@0 305 this._loadingContainer.style.display = "block";
michael@0 306 } else {
michael@0 307 // If no more could be displayed, hide the throbber, and stop noticing scroll events
michael@0 308 this._loadingContainer.style.display = "none";
michael@0 309 window.onscroll = null;
michael@0 310 }
michael@0 311 },
michael@0 312
michael@0 313 // If scrolling at the bottom, maybe add some more entries
michael@0 314 onScroll: function AC_onScroll(aEvent) {
michael@0 315 if (this._prefsContainer.scrollHeight - (window.pageYOffset + window.innerHeight) < PAGE_SCROLL_TRIGGER) {
michael@0 316 if (!this._filterChangeTimer) {
michael@0 317 this._addMorePrefsToContainer();
michael@0 318 }
michael@0 319 }
michael@0 320 },
michael@0 321
michael@0 322 // Return currently selected list item node
michael@0 323 get selected() {
michael@0 324 return document.querySelector(".pref-item.selected");
michael@0 325 },
michael@0 326
michael@0 327 // Set list item node as selected
michael@0 328 set selected(aSelection) {
michael@0 329 let currentSelection = this.selected;
michael@0 330 if (aSelection == currentSelection) {
michael@0 331 return;
michael@0 332 }
michael@0 333
michael@0 334 // Clear any previous selection
michael@0 335 if (currentSelection) {
michael@0 336 currentSelection.classList.remove("selected");
michael@0 337 currentSelection.removeEventListener("keypress", this.handleKeypress, false);
michael@0 338 }
michael@0 339
michael@0 340 // Set any current selection
michael@0 341 if (aSelection) {
michael@0 342 aSelection.classList.add("selected");
michael@0 343 aSelection.addEventListener("keypress", this.handleKeypress, false);
michael@0 344 }
michael@0 345 },
michael@0 346
michael@0 347 // Watch user key input so we can provide Enter key action, commit input values
michael@0 348 handleKeypress: function AC_handleKeypress(aEvent) {
michael@0 349 if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN)
michael@0 350 aEvent.target.blur();
michael@0 351 },
michael@0 352
michael@0 353 // Return the target list item node of an action event
michael@0 354 getLINodeForEvent: function AC_getLINodeForEvent(aEvent) {
michael@0 355 let node = aEvent.target;
michael@0 356 while (node && node.nodeName != "li") {
michael@0 357 node = node.parentNode;
michael@0 358 }
michael@0 359
michael@0 360 return node;
michael@0 361 },
michael@0 362
michael@0 363 // Return a pref of a list item node
michael@0 364 _getPrefForNode: function AC_getPrefForNode(aNode) {
michael@0 365 let pref = aNode.getAttribute("name");
michael@0 366
michael@0 367 return new Pref(pref);
michael@0 368 },
michael@0 369
michael@0 370 // When list item name or value are tapped
michael@0 371 selectOrToggleBoolPref: function AC_selectOrToggleBoolPref(aEvent) {
michael@0 372 let node = this.getLINodeForEvent(aEvent);
michael@0 373
michael@0 374 // If not already selected, just do so
michael@0 375 if (this.selected != node) {
michael@0 376 this.selected = node;
michael@0 377 return;
michael@0 378 }
michael@0 379
michael@0 380 // If already selected, and value is boolean, toggle it
michael@0 381 let pref = this._getPrefForNode(node);
michael@0 382 if (pref.type != Services.prefs.PREF_BOOL) {
michael@0 383 return;
michael@0 384 }
michael@0 385
michael@0 386 this.toggleBoolPref(aEvent);
michael@0 387 },
michael@0 388
michael@0 389 // When finalizing list input values due to blur
michael@0 390 setIntOrStringPref: function AC_setIntOrStringPref(aEvent) {
michael@0 391 let node = this.getLINodeForEvent(aEvent);
michael@0 392
michael@0 393 // Skip if locked
michael@0 394 let pref = this._getPrefForNode(node);
michael@0 395 if (pref.locked) {
michael@0 396 return;
michael@0 397 }
michael@0 398
michael@0 399 // Boolean inputs blur to remove focus from "button"
michael@0 400 if (pref.type == Services.prefs.PREF_BOOL) {
michael@0 401 return;
michael@0 402 }
michael@0 403
michael@0 404 // String and Int inputs change / commit on blur
michael@0 405 pref.value = aEvent.target.value;
michael@0 406 },
michael@0 407
michael@0 408 // When we reset a pref to it's default value (note resetting a user created pref will delete it)
michael@0 409 resetDefaultPref: function AC_resetDefaultPref(aEvent) {
michael@0 410 let node = this.getLINodeForEvent(aEvent);
michael@0 411
michael@0 412 // If not already selected, do so
michael@0 413 if (this.selected != node) {
michael@0 414 this.selected = node;
michael@0 415 }
michael@0 416
michael@0 417 // Reset will handle any locked condition
michael@0 418 let pref = this._getPrefForNode(node);
michael@0 419 pref.reset();
michael@0 420 },
michael@0 421
michael@0 422 // When we want to toggle a bool pref
michael@0 423 toggleBoolPref: function AC_toggleBoolPref(aEvent) {
michael@0 424 let node = this.getLINodeForEvent(aEvent);
michael@0 425
michael@0 426 // Skip if locked, or not boolean
michael@0 427 let pref = this._getPrefForNode(node);
michael@0 428 if (pref.locked) {
michael@0 429 return;
michael@0 430 }
michael@0 431
michael@0 432 // Toggle, and blur to remove field focus
michael@0 433 pref.value = !pref.value;
michael@0 434 aEvent.target.blur();
michael@0 435 },
michael@0 436
michael@0 437 // When Int inputs have their Up or Down arrows toggled
michael@0 438 incrOrDecrIntPref: function AC_incrOrDecrIntPref(aEvent, aInt) {
michael@0 439 let node = this.getLINodeForEvent(aEvent);
michael@0 440
michael@0 441 // Skip if locked
michael@0 442 let pref = this._getPrefForNode(node);
michael@0 443 if (pref.locked) {
michael@0 444 return;
michael@0 445 }
michael@0 446
michael@0 447 pref.value += aInt;
michael@0 448 },
michael@0 449
michael@0 450 // Observe preference changes
michael@0 451 observe: function AC_observe(aSubject, aTopic, aPrefName) {
michael@0 452 let pref = new Pref(aPrefName);
michael@0 453
michael@0 454 // Ignore uninteresting changes, and avoid "private" preferences
michael@0 455 if (aTopic != "nsPref:changed") {
michael@0 456 return;
michael@0 457 }
michael@0 458
michael@0 459 // If pref type invalid, refresh display as user reset/removed an item from the list
michael@0 460 if (pref.type == Services.prefs.PREF_INVALID) {
michael@0 461 document.location.reload();
michael@0 462 return;
michael@0 463 }
michael@0 464
michael@0 465 // If pref not already in list, refresh display as it's being added
michael@0 466 let item = document.querySelector(".pref-item[name=" + pref.name.quote() + "]");
michael@0 467 if (!item) {
michael@0 468 document.location.reload();
michael@0 469 return;
michael@0 470 }
michael@0 471
michael@0 472 // Else we're modifying a pref
michael@0 473 item.setAttribute("value", pref.value);
michael@0 474 let input = item.querySelector("input");
michael@0 475 input.setAttribute("value", pref.value);
michael@0 476 input.value = pref.value;
michael@0 477
michael@0 478 pref.default ?
michael@0 479 item.querySelector(".reset").setAttribute("disabled", "true") :
michael@0 480 item.querySelector(".reset").removeAttribute("disabled");
michael@0 481 }
michael@0 482 }
michael@0 483
michael@0 484
michael@0 485 /* ============================== Pref ==============================
michael@0 486 *
michael@0 487 * Individual Preference object / methods
michael@0 488 *
michael@0 489 * Defines a Pref object, a document list item tied to Preferences Services
michael@0 490 * And the methods by which they interact.
michael@0 491 *
michael@0 492 */
michael@0 493 function Pref(aName) {
michael@0 494 this.name = aName;
michael@0 495 }
michael@0 496
michael@0 497 Pref.prototype = {
michael@0 498 get type() {
michael@0 499 return Services.prefs.getPrefType(this.name);
michael@0 500 },
michael@0 501
michael@0 502 get value() {
michael@0 503 switch (this.type) {
michael@0 504 case Services.prefs.PREF_BOOL:
michael@0 505 return Services.prefs.getBoolPref(this.name);
michael@0 506 case Services.prefs.PREF_INT:
michael@0 507 return Services.prefs.getIntPref(this.name);
michael@0 508 case Services.prefs.PREF_STRING:
michael@0 509 default:
michael@0 510 return Services.prefs.getCharPref(this.name);
michael@0 511 }
michael@0 512
michael@0 513 },
michael@0 514
michael@0 515 set value(aPrefValue) {
michael@0 516 switch (this.type) {
michael@0 517 case Services.prefs.PREF_BOOL:
michael@0 518 Services.prefs.setBoolPref(this.name, aPrefValue);
michael@0 519 break;
michael@0 520 case Services.prefs.PREF_INT:
michael@0 521 Services.prefs.setIntPref(this.name, aPrefValue);
michael@0 522 break;
michael@0 523 case Services.prefs.PREF_STRING:
michael@0 524 default:
michael@0 525 Services.prefs.setCharPref(this.name, aPrefValue);
michael@0 526 }
michael@0 527 },
michael@0 528
michael@0 529 get default() {
michael@0 530 return !Services.prefs.prefHasUserValue(this.name);
michael@0 531 },
michael@0 532
michael@0 533 get locked() {
michael@0 534 return Services.prefs.prefIsLocked(this.name);
michael@0 535 },
michael@0 536
michael@0 537 reset: function AC_reset() {
michael@0 538 Services.prefs.clearUserPref(this.name);
michael@0 539 },
michael@0 540
michael@0 541 test: function AC_test(aValue) {
michael@0 542 return aValue ? aValue.test(this.name) : true;
michael@0 543 },
michael@0 544
michael@0 545 // Get existing or create new LI node for the pref
michael@0 546 getOrCreateNewLINode: function AC_getOrCreateNewLINode() {
michael@0 547 if (!this.li) {
michael@0 548 this.li = document.createElement("li");
michael@0 549
michael@0 550 this.li.className = "pref-item";
michael@0 551 this.li.setAttribute("name", this.name);
michael@0 552
michael@0 553 // Click callback to ensure list item selected even on no-action tap events
michael@0 554 this.li.addEventListener("click",
michael@0 555 function(aEvent) {
michael@0 556 AboutConfig.selected = AboutConfig.getLINodeForEvent(aEvent);
michael@0 557 },
michael@0 558 false
michael@0 559 );
michael@0 560
michael@0 561 // Create list item outline, bind to object actions
michael@0 562 this.li.innerHTML =
michael@0 563 "<div class='pref-name' " +
michael@0 564 "onclick='AboutConfig.selectOrToggleBoolPref(event);'>" +
michael@0 565 this.name +
michael@0 566 "</div>" +
michael@0 567 "<div class='pref-item-line'>" +
michael@0 568 "<input class='pref-value' value='' " +
michael@0 569 "onblur='AboutConfig.setIntOrStringPref(event);' " +
michael@0 570 "onclick='AboutConfig.selectOrToggleBoolPref(event);'>" +
michael@0 571 "</input>" +
michael@0 572 "<div class='pref-button reset' " +
michael@0 573 "onclick='AboutConfig.resetDefaultPref(event);'>" +
michael@0 574 gStringBundle.GetStringFromName("pref.resetButton") +
michael@0 575 "</div>" +
michael@0 576 "<div class='pref-button toggle' " +
michael@0 577 "onclick='AboutConfig.toggleBoolPref(event);'>" +
michael@0 578 gStringBundle.GetStringFromName("pref.toggleButton") +
michael@0 579 "</div>" +
michael@0 580 "<div class='pref-button up' " +
michael@0 581 "onclick='AboutConfig.incrOrDecrIntPref(event, 1);'>" +
michael@0 582 "</div>" +
michael@0 583 "<div class='pref-button down' " +
michael@0 584 "onclick='AboutConfig.incrOrDecrIntPref(event, -1);'>" +
michael@0 585 "</div>" +
michael@0 586 "</div>";
michael@0 587
michael@0 588 // Delay providing the list item values, until the LI is returned and added to the document
michael@0 589 setTimeout(this._valueSetup.bind(this), INNERHTML_VALUE_DELAY);
michael@0 590 }
michael@0 591
michael@0 592 return this.li;
michael@0 593 },
michael@0 594
michael@0 595 // Initialize list item object values
michael@0 596 _valueSetup: function AC_valueSetup() {
michael@0 597
michael@0 598 this.li.setAttribute("type", this.type);
michael@0 599 this.li.setAttribute("value", this.value);
michael@0 600
michael@0 601 let valDiv = this.li.querySelector(".pref-value");
michael@0 602 valDiv.value = this.value;
michael@0 603
michael@0 604 switch(this.type) {
michael@0 605 case Services.prefs.PREF_BOOL:
michael@0 606 valDiv.setAttribute("type", "button");
michael@0 607 this.li.querySelector(".up").setAttribute("disabled", true);
michael@0 608 this.li.querySelector(".down").setAttribute("disabled", true);
michael@0 609 break;
michael@0 610 case Services.prefs.PREF_STRING:
michael@0 611 valDiv.setAttribute("type", "text");
michael@0 612 this.li.querySelector(".up").setAttribute("disabled", true);
michael@0 613 this.li.querySelector(".down").setAttribute("disabled", true);
michael@0 614 this.li.querySelector(".toggle").setAttribute("disabled", true);
michael@0 615 break;
michael@0 616 case Services.prefs.PREF_INT:
michael@0 617 valDiv.setAttribute("type", "number");
michael@0 618 this.li.querySelector(".toggle").setAttribute("disabled", true);
michael@0 619 break;
michael@0 620 }
michael@0 621
michael@0 622 this.li.setAttribute("default", this.default);
michael@0 623 if (this.default) {
michael@0 624 this.li.querySelector(".reset").setAttribute("disabled", true);
michael@0 625 }
michael@0 626
michael@0 627 if (this.locked) {
michael@0 628 valDiv.setAttribute("disabled", this.locked);
michael@0 629 this.li.querySelector(".pref-name").setAttribute("locked", true);
michael@0 630 }
michael@0 631 }
michael@0 632 }

mercurial