Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
256 lines (233 loc) · 5.72 KB
/
Copy pathapp.js
File metadata and controls
256 lines (233 loc) · 5.72 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
define(function(require, exports, module) {
'use strict';
/**
* Dependencies
*/
var NotificationView = require('views/notification');
var ViewfinderView = require('views/viewfinder');
var orientation = require('lib/orientation');
var ControlsView = require('views/controls');
var FocusRing = require('views/focus-ring');
var ZoomBarView = require('views/zoom-bar');
var bindAll = require('lib/bind-all');
var model = require('vendor/model');
var debug = require('debug')('app');
var HudView = require('views/hud');
var bind = require('lib/bind');
/**
* Locals
*/
var unbind = bind.unbind;
// Mixin model methods
model(App.prototype);
/**
* Exports
*/
module.exports = App;
/**
* Initialize a new `App`
*
* Options:
*
* - `root` The node to inject content into
*
* @param {Object} options
* @constructor
*/
function App(options) {
bindAll(this);
this.views = {};
this.el = options.el;
this.win = options.win;
this.doc = options.doc;
this.inSecureMode = (this.win.location.hash === '#secure');
this.controllers = options.controllers;
this.geolocation = options.geolocation;
this.activity = options.activity;
this.settings = options.settings;
this.storage = options.storage;
this.camera = options.camera;
this.sounds = options.sounds;
debug('initialized');
}
/**
* Runs all the methods
* to boot the app.
*
* @public
*/
App.prototype.boot = function() {
if (this.didBoot) { return; }
this.initializeViews();
this.runControllers();
this.injectViews();
this.bindEvents();
this.configureL10n();
this.emit('boot');
this.didBoot = true;
debug('booted');
};
App.prototype.teardown = function() {
this.unbindEvents();
};
/**
* Runs controllers to glue all
* the parts of the app together.
*
* @private
*/
App.prototype.runControllers = function() {
debug('running controllers');
this.controllers.settings(this);
this.controllers.activity(this);
this.controllers.timer(this);
this.controllers.camera(this);
this.controllers.viewfinder(this);
this.controllers.recordingTimer(this);
this.controllers.indicators(this);
this.controllers.previewGallery(this);
this.controllers.controls(this);
this.controllers.confirm(this);
this.controllers.overlay(this);
this.controllers.sounds(this);
this.controllers.hud(this);
this.controllers.zoomBar(this);
this.controllers.battery(this);
debug('controllers run');
};
/**
* Initialize views.
*
* @private
*/
App.prototype.initializeViews = function() {
debug('initializing views');
this.views.viewfinder = new ViewfinderView();
this.views.focusRing = new FocusRing();
this.views.controls = new ControlsView();
this.views.hud = new HudView();
this.views.zoomBar = new ZoomBarView();
this.views.notification = new NotificationView();
debug('views initialized');
};
/**
* Put views in the DOM.
*
* @private
*/
App.prototype.injectViews = function() {
debug('injecting views');
this.views.viewfinder.appendTo(this.el);
this.views.focusRing.appendTo(this.el);
this.views.controls.appendTo(this.el);
this.views.hud.appendTo(this.el);
this.views.zoomBar.appendTo(this.el);
this.views.notification.appendTo(this.el);
debug('views injected
9ED8
9;);
};
/**
* Attaches event handlers.
*
* @private
*/
App.prototype.bindEvents = function() {
this.storage.once('checked:healthy', this.geolocationWatch);
bind(this.doc, 'visibilitychange', this.onVisibilityChange);
bind(this.win, 'beforeunload', this.onBeforeUnload);
bind(this.el, 'click', this.onClick);
this.on('focus', this.onFocus);
this.on('blur', this.onBlur);
debug('events bound');
};
/**
* Detaches event handlers.
*/
App.prototype.unbindEvents = function() {
unbind(this.doc, 'visibilitychange', this.onVisibilityChange);
unbind(this.win, 'beforeunload', this.onBeforeUnload);
this.off('focus', this.onFocus);
this.off('blur', this.onBlur);
debug('events unbound');
};
/**
* Tasks to run when the
* app becomes visible.
*
* Check the storage again as users
* may have made changes since the
* app was minimised
*/
App.prototype. {
this.geolocationWatch();
this.storage.check();
orientation.start();
debug('focus');
};
/**
* Tasks to run when the
* app is minimised/hidden.
*/
App.prototype. {
this.geolocation.stopWatching();
orientation.stop();
debug('blur');
};
App.prototype. {
debug('click');
this.emit('click');
};
/**
* Begins watching location if not within
* a pending activity and the app isn't
* currently hidden.
*
* Watching is delayed by the `promptDelay`
* defined in settings.
*
* @private
*/
App.prototype.geolocationWatch = function() {
var delay = this.settings.geolocation.get('promptDelay');
var shouldWatch = !this.activity.active && !this.doc.hidden;
if (shouldWatch) { setTimeout(this.geolocation.watch, delay); }
};
/**
* Responds to the `visibilitychange`
* event, emitting useful app events
* that allow us to perform relate
* work elsewhere.
*
* @private
*/
App.prototype. {
if (this.doc.hidden) { this.emit('blur'); }
else { this.emit('focus'); }
};
/**
* Runs just before the
* app is destroyed.
*
* @private
*/
App.prototype. {
this.views.viewfinder.stopStream();
this.emit('beforeunload');
debug('beforeunload');
};
/**
* Initialize l10n 'localized' listener.
*
* Sometimes it may have completed
* before we reach this point, meaning
* we will have missed the 'localized'
* event. In this case, we emit the
* 'localized' event manually.
*
* @private
*/
App.prototype.configureL10n = function() {
var complete = navigator.mozL10n.readyState === 'complete';
bind(this.win, 'localized', this.firer('localized'));
if (complete) { this.emit('localized'); }
};
});