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