This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
settings.js
112 lines (93 loc) · 3.48 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict';
/**
* Debug note: to test this app in a desktop browser, you'll have to set
* the `dom.mozSettings.enabled' preference to false in order to avoid an
* `uncaught exception: 2147500033' message (= 0x80004001).
*/
window.Settings = {
get hasMozSettings() {
// return navigator.mozSettings when properly supported, null otherwise
// (e.g. when debugging on a browser...)
var settings = navigator.mozSettings;
return (settings && typeof(settings.createLock) == 'function') ?
settings : null;
},
isTabletAndLandscape: function is_tablet_and_landscape() {
// XXX: force to use phone layout.
//return this.ScreenLayout.getCurrentLayout('tabletAndLandscaped');
return false;
},
_isTabletAndLandscapeLastTime: null,
rotate: function rotate(evt) {
var isTabletAndLandscapeThisTime = Settings.isTabletAndLandscape();
var panelsWithCurrentClass;
if (Settings._isTabletAndLandscapeLastTime !==
isTabletAndLandscapeThisTime) {
panelsWithCurrentClass = document.querySelectorAll(
'section[role="region"].current');
// in two column style if we have only 'root' panel displayed,
// (left: root panel, right: blank)
// then show default panel too
if (panelsWithCurrentClass.length === 1 &&
panelsWithCurrentClass[0].id === 'root') {
// go to default panel
Settings.currentPanel = Settings.initialPanelForTablet;
}
}
Settings._isTabletAndLandscapeLastTime = isTabletAndLandscapeThisTime;
},
initialPanelForTablet: '#wifi',
_currentPanel: null,
get currentPanel() {
return this._currentPanel;
},
set currentPanel(hash) {
if (!hash.startsWith('#')) {
hash = '#' + hash;
}
if (hash === this._currentPanel) {
return;
}
// take off # first
var panelID = hash;
if (panelID.startsWith('#')) {
panelID = panelID.substring(1);
}
this.SettingsService.navigate(panelID, this._initialOptions);
},
get _initialOptions() {
// After initial navigation, initial panel options are not necessary.
delete this._initialOptions;
// If initial panel has options, use them once at initial navigation.
return window.LaunchContext.activityHandler &&
window.LaunchContext.activityHandler.targetPanelOptions;
},
init: function settings_init(options) {
if (!this.hasMozSettings) {
return;
}
this.SettingsService = options.SettingsService;
this.ScreenLayout = options.ScreenLayout;
// XXX: We need to set to currentPanel here although SettingsService already
// knows the default panel id. This line will be removed along with
// "currentPanel" soon.
this.currentPanel = window.LaunchContext.initialPanelId;
// make operations not block the load time
setTimeout((function nextTick() {
// With async pan zoom enable, the page starts with a viewport
// of 980px before beeing resize to device-width. So let's delay
// the rotation listener to make sure it is not triggered by fake
// positive.
this.ScreenLayout.watch(
'tabletAndLandscaped',
'(min-width: 768px) and (orientation: landscape)');
window.addEventListener('screenlayoutchange', this.rotate);
// WifiHelper is guaranteed to be loaded in main.js before calling to
// this line.
if (this.isTabletAndLandscape()) {
this.currentPanel = this.initialPanelForTablet;
}
}).bind(this));
window.performance.mark('startupPathEnd');
}
};