browser/metro/base/content/flyoutpanels/SearchFlyoutPanel.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.

     1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 "use strict";
     8 Components.utils.import("resource://gre/modules/Services.jsm");
    10 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
    12 let SearchFlyoutPanel = {
    13   _isInitialized: false,
    14   _hasShown: false,
    15   init: function pv_init() {
    16     if (this._isInitialized) {
    17       Cu.reportError("Attempting to re-initialize PreferencesPanelView");
    18       return;
    19     }
    20     this._topmostElement = document.getElementById("search-flyoutpanel");
    21     this._isInitialized = true;
    22   },
    24   checked: function checked(aId) {
    25     aId = aId.replace("search-", "");
    26     Services.search.defaultEngine = this._engines[parseInt(aId)];
    27     this.updateSearchEngines();
    28   },
    30   updateSearchEngines: function () {
    31     // Clear the list
    32     let setting = document.getElementById("search-options");
    33     while(setting.hasChildNodes()) {
    34       setting.removeChild(setting.firstChild);
    35     }
    37     // Build up the list and check the default
    38     this._engines = Services.search.getVisibleEngines();
    39     let defaultEngine = Services.search.defaultEngine;
    41     this._engines.forEach(function (aEngine, aIndex) {
    42       let radio = document.createElementNS(XUL_NS, "radio");
    43       radio.setAttribute("id", "search-" + aIndex);
    44       radio.setAttribute("label", aEngine.name);
    45       radio.setAttribute("oncommand", "FlyoutPanelsUI.SearchFlyoutPanel.checked(this.id)");
    46       if (defaultEngine == aEngine) {
    47         radio.setAttribute("selected", true);
    48       }
    49       setting.appendChild(radio);
    50     }.bind(this));
    51   },
    53   _show: function() {
    54     if (!this._hasShown) {
    55       this._hasShown = true;
    56       this.updateSearchEngines();
    57     }
    58     this._topmostElement.show();
    59   }
    60 };

mercurial