forked from mozilla-b2g/gaia
/
ime_switcher.js
70 lines (57 loc) · 2.22 KB
/
ime_switcher.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
'use strict';
(function(exports) {
/**
* IMESwitcher is responsible for showing a fake notification
* in utility tray, which indicates the activate keyboard
* and may be interacted upon for showing IME selection menu.
*/
var IMESwitcher = function() {
this._utilityTrayContainer = null;
this._notificationContainer = null;
this._notificationTitle = null;
this._notificationTip = null;
this.ontap = undefined;
};
IMESwitcher.prototype.start = function is_start() {
this._utilityTrayContainer =
document.getElementById('keyboard-show-ime-list');
this._notificationContainer =
this._utilityTrayContainer.querySelector('.fake-notification');
this._notificationTitle =
this._notificationContainer.querySelector('.title-container');
this._notificationTip =
this._notificationContainer.querySelector('.detail');
this._notificationContainer.addEventListener('mousedown', this);
};
IMESwitcher.prototype.stop = function is_stop() {
this._notificationContainer.removeEventListener('mousedown', this);
this._utilityTrayContainer = null;
this._notificationContainer = null;
this._notificationTitle = null;
this._notificationTip = null;
this.ontap = undefined;
};
IMESwitcher.prototype.show = function is_show(appName, imeName) {
window.dispatchEvent(new CustomEvent('keyboardimeswitchershow'));
navigator.mozL10n.localize(this._notificationTitle, 'ime-switching-title', {
appName: appName,
name: imeName
});
navigator.mozL10n.localize(this._notificationTip, 'ime-switching-tip');
// Instead of create DOM element dynamically, we can just turn the message
// on/off and add message as we need. This save the time to create and
// append element.
this._notificationContainer.classList.add('activated');
};
IMESwitcher.prototype.hide = function is_hide() {
this._notificationContainer.classList.remove('activated');
window.dispatchEvent(new CustomEvent('keyboardimeswitcherhide'));
};
IMESwitcher.prototype.handleEvent = function is_handleEvent(evt) {
evt.preventDefault();
if (typeof this.ontap === 'function') {
this.ontap();
}
};
exports.IMESwitcher = IMESwitcher;
})(window);