browser/metro/base/content/flyoutpanels/SearchFlyoutPanel.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/content/flyoutpanels/SearchFlyoutPanel.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +"use strict";
    1.10 +
    1.11 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.12 +
    1.13 +const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
    1.14 +
    1.15 +let SearchFlyoutPanel = {
    1.16 +  _isInitialized: false,
    1.17 +  _hasShown: false,
    1.18 +  init: function pv_init() {
    1.19 +    if (this._isInitialized) {
    1.20 +      Cu.reportError("Attempting to re-initialize PreferencesPanelView");
    1.21 +      return;
    1.22 +    }
    1.23 +    this._topmostElement = document.getElementById("search-flyoutpanel");
    1.24 +    this._isInitialized = true;
    1.25 +  },
    1.26 +
    1.27 +  checked: function checked(aId) {
    1.28 +    aId = aId.replace("search-", "");
    1.29 +    Services.search.defaultEngine = this._engines[parseInt(aId)];
    1.30 +    this.updateSearchEngines();
    1.31 +  },
    1.32 +
    1.33 +  updateSearchEngines: function () {
    1.34 +    // Clear the list
    1.35 +    let setting = document.getElementById("search-options");
    1.36 +    while(setting.hasChildNodes()) {
    1.37 +      setting.removeChild(setting.firstChild);
    1.38 +    }
    1.39 +
    1.40 +    // Build up the list and check the default
    1.41 +    this._engines = Services.search.getVisibleEngines();
    1.42 +    let defaultEngine = Services.search.defaultEngine;
    1.43 +
    1.44 +    this._engines.forEach(function (aEngine, aIndex) {
    1.45 +      let radio = document.createElementNS(XUL_NS, "radio");
    1.46 +      radio.setAttribute("id", "search-" + aIndex);
    1.47 +      radio.setAttribute("label", aEngine.name);
    1.48 +      radio.setAttribute("oncommand", "FlyoutPanelsUI.SearchFlyoutPanel.checked(this.id)");
    1.49 +      if (defaultEngine == aEngine) {
    1.50 +        radio.setAttribute("selected", true);
    1.51 +      }
    1.52 +      setting.appendChild(radio);
    1.53 +    }.bind(this));
    1.54 +  },
    1.55 +
    1.56 +  _show: function() {
    1.57 +    if (!this._hasShown) {
    1.58 +      this._hasShown = true;
    1.59 +      this.updateSearchEngines();
    1.60 +    }
    1.61 +    this._topmostElement.show();
    1.62 +  }
    1.63 +};

mercurial