1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/content/flyoutpanels/FlyoutPanelsUI.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,120 @@ 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 +'use strict'; 1.9 + 1.10 +let FlyoutPanelsUI = { 1.11 + _isInitialized: false, 1.12 + 1.13 + init: function() { 1.14 + if (this._isInitialized) { 1.15 + Cu.reportError("Attempted to initialize FlyoutPanelsUI more than once"); 1.16 + return; 1.17 + } 1.18 + 1.19 + Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.20 + Cu.import("resource://gre/modules/Services.jsm"); 1.21 + 1.22 + this._isInitialized = true; 1.23 + let scriptContexts = {}; 1.24 + let scripts = 1.25 + [ 1.26 + ['AboutFlyoutPanel', 'chrome://browser/content/flyoutpanels/AboutFlyoutPanel.js'], 1.27 + ['PrefsFlyoutPanel', 'chrome://browser/content/flyoutpanels/PrefsFlyoutPanel.js'], 1.28 + ['SearchFlyoutPanel', 'chrome://browser/content/flyoutpanels/SearchFlyoutPanel.js'], 1.29 +#ifdef MOZ_SERVICES_SYNC 1.30 + ['SyncFlyoutPanel', 'chrome://browser/content/flyoutpanels/SyncFlyoutPanel.js'], 1.31 +#endif 1.32 + ]; 1.33 + 1.34 + scripts.forEach(function (aScript) { 1.35 + let [name, script] = aScript; 1.36 + XPCOMUtils.defineLazyGetter(FlyoutPanelsUI, name, function() { 1.37 + let sandbox = {}; 1.38 + Services.scriptloader.loadSubScript(script, sandbox); 1.39 + sandbox[name].init(); 1.40 + return sandbox[name]; 1.41 + }); 1.42 + }); 1.43 + 1.44 + Services.obs.addObserver(this, "metro_viewstate_changed", false); 1.45 + window.addEventListener("TabOpen", this, false); 1.46 + }, 1.47 + 1.48 + uninit: function () { 1.49 + Services.obs.removeObserver(this, "metro_viewstate_changed"); 1.50 + window.removeEventListener("TabOpen", this, false); 1.51 + }, 1.52 + 1.53 + show: function(aToShow) { 1.54 + if (!this[aToShow]) { 1.55 + throw("FlyoutPanelsUI asked to show '" + aToShow + "' which does not exist"); 1.56 + } 1.57 + 1.58 + if (this._currentFlyout) { 1.59 + if (this._currentFlyout == this[aToShow]) { 1.60 + return; 1.61 + } else { 1.62 + this.hide(); 1.63 + } 1.64 + } 1.65 + 1.66 + this._currentFlyout = this[aToShow]; 1.67 + if (this._currentFlyout._show) { 1.68 + this._currentFlyout._show(); 1.69 + } else { 1.70 + this._currentFlyout._topmostElement.show(); 1.71 + } 1.72 + DialogUI.pushPopup(this, this._currentFlyout._topmostElement); 1.73 + }, 1.74 + 1.75 + onBackButton: function() { 1.76 + if (this._currentFlyout._onBackButton) { 1.77 + this._currentFlyout._onBackButton(); 1.78 + } else { 1.79 + this.hide(); 1.80 + Services.metro.showSettingsFlyout(); 1.81 + } 1.82 + }, 1.83 + 1.84 + get isVisible() { 1.85 + return this._currentFlyout ? true : false; 1.86 + }, 1.87 + 1.88 + handleEvent: function (aEvent) { 1.89 + switch (aEvent.type) { 1.90 + case "TabOpen": 1.91 + this.hide() 1.92 + break; 1.93 + } 1.94 + }, 1.95 + 1.96 + observe: function (aSubject, aTopic, aData) { 1.97 + switch (aTopic) { 1.98 + case "metro_viewstate_changed": 1.99 + if (aData == "snapped") { 1.100 + this.hide(); 1.101 + } 1.102 + break; 1.103 + } 1.104 + }, 1.105 + 1.106 + dispatchEvent: function(aEvent) { 1.107 + if (this._currentFlyout) { 1.108 + this._currentFlyout._topmostElement.dispatchEvent(aEvent); 1.109 + } 1.110 + }, 1.111 + 1.112 + hide: function() { 1.113 + if (this._currentFlyout) { 1.114 + if (this._currentFlyout._hide) { 1.115 + this._currentFlyout._hide(); 1.116 + } else { 1.117 + this._currentFlyout._topmostElement.hide(); 1.118 + } 1.119 + DialogUI.popPopup(this); 1.120 + delete this._currentFlyout; 1.121 + } 1.122 + } 1.123 +};