|
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/. */ |
|
5 |
|
6 "use strict"; |
|
7 |
|
8 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
9 |
|
10 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; |
|
11 |
|
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 }, |
|
23 |
|
24 checked: function checked(aId) { |
|
25 aId = aId.replace("search-", ""); |
|
26 Services.search.defaultEngine = this._engines[parseInt(aId)]; |
|
27 this.updateSearchEngines(); |
|
28 }, |
|
29 |
|
30 updateSearchEngines: function () { |
|
31 // Clear the list |
|
32 let setting = document.getElementById("search-options"); |
|
33 while(setting.hasChildNodes()) { |
|
34 setting.removeChild(setting.firstChild); |
|
35 } |
|
36 |
|
37 // Build up the list and check the default |
|
38 this._engines = Services.search.getVisibleEngines(); |
|
39 let defaultEngine = Services.search.defaultEngine; |
|
40 |
|
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 }, |
|
52 |
|
53 _show: function() { |
|
54 if (!this._hasShown) { |
|
55 this._hasShown = true; |
|
56 this.updateSearchEngines(); |
|
57 } |
|
58 this._topmostElement.show(); |
|
59 } |
|
60 }; |