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
|
'use strict';
var CallHandler = {
_call: null,
_telephony: window.navigator.mozTelephony,
call: function ch_call(number) {
var sanitizedNumber = number.replace(/-/g, '');
var telephony = this._telephony;
if (telephony) {
this._call = telephony.dialEmergency(sanitizedNumber);
var call = this._call;
if (call) {
var cb = function clearPhoneView() {
KeypadManager.updatePhoneNumber('');
};
call.onconnected = cb;
call.ondisconnected = function callEnded() {
cb();
CallScreen.hide();
};
CallScreen.number = call.number;
CallScreen.show();
}
}
},
end: function ch_end() {
if (!this._call) {
CallScreen.hide();
return;
}
this._call.hangUp();
this._call = null;
},
toggleSpeaker: function ch_toggleSpeaker() {
this._telephony.speakerEnabled = !this._telephony.speakerEnabled;
}
};
var CallScreen = {
screen: document.getElementById('call-screen'),
numberView: document.getElementById('emergency-number'),
hangUpButton: document.getElementById('callbar-hang-up'),
speakerButton: document.getElementById('speaker'),
set number(value) {
this.numberView.textContent = value;
},
init: function cs_init() {
this.hangUpButton.addEventListener('mouseup',
CallHandler.end.bind(CallHandler));
this.speakerButton.addEventListener('click', this.toggleSpeaker.bind(this));
},
show: function cs_show() {
this.screen.classList.add('displayed');
},
hide: function cs_hide() {
this.screen.classList.remove('displayed');
},
toggleSpeaker: function cs_toggleSpeaker() {
this.speakerButton.classList.toggle('speak');
CallHandler.toggleSpeaker();
}
};
window.addEventListener('load', function onload() {
window.removeEventListener('load', onload);
KeypadManager.init();
CallScreen.init();
});
|