-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
186 lines (161 loc) · 5.51 KB
/
index.js
File metadata and controls
186 lines (161 loc) · 5.51 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
(function () {
var QuickAccess = {
_elements: {},
supportItems: ['gallary', 'dial', 'sms', 'mail', 'addContact'],
workingItems: [],
initialize: function initialize() {
this._elements = {
quickSettingsContainer: document.querySelector('#quick-settings > ul'),
lastButton: document.querySelector('#quick-settings-full-app').parentNode
};
this.workingItems = this.supportItems;
var KEY = 'quick.settings.addon';
var settings = window.navigator.mozSettings;
var req = settings.createLock().get(KEY);
req.onsccess = () => {
var result = req.result[KEY];
if (typeof result === 'undefined') {
console.log('initial to default');
this.workingItems = this.supportItems;
} else {
this.workingItems = result
}
};
req.onerror = () => {
console.log('Error fail to get settings');
this.workingItems = this.supportItems;
};
this.renderItems();
},
renderItems: function renderItems() {
this._elements.quickSettingsContainer.style.flexWrap = 'wrap';
// Remove previously appended buttons if any
while (this._elements.lastButton.nextSibling) {
this._elements.quickSettingsContainer.removeChild(
this._elements.lastButton.nextSibling);
}
var availableItems = {
'gallary': this.initGalleryButton,
//'record': this.initRecordButton,
'dial' : this.initDialButton,
'sms': this.initSmsButton,
'mail': this.initMailButton,
'addContact': this.initAddContactButton
};
// if (this.workingItems.indexOf('config') < 0) {
// this.workingItems.push('config');
// }
var btn = null;
this.workingItems.forEach((item) => {
btn = this.createButton(item);
availableItems[item].call(this, btn.firstChild);
this._elements.quickSettingsContainer.appendChild(btn);
});
// Add additional li as placeholders to layout buttons correctly
var fillLi = 5 - this.workingItems.length % 5;
for (i=0; i < fillLi; i++) {
this._elements.quickSettingsContainer.appendChild(
document.createElement('li'));
}
var allSettings = document.querySelectorAll('#quick-settings > ul > li');
for (var i=0; i < allSettings.length; i++) {
allSettings[i].style.flex = '1 1 20%';
}
},
// Template:
// <li><a href="#" id="quick-settings-wifi" class="icon bb-button" data-icon="wifi-4" data-enabled="false" role="button" data-l10n-id="quick-settings-wifiButton-off"></a></li>
createButton: function createButton(name) {
var li = document.createElement('li');
var a = document.createElement('a');
a.href = '#';
a.id = 'quick-settings-' + name;
a.classList.add('icon');
a.classList.add('bb-button');
a.setAttribute('role', 'button');
li.appendChild(a);
return li;
},
//open gallary
initGalleryButton: function initGalleryButton(button) {
function onClick() {
new MozActivity({
name: 'browse'
});
}
button.dataset.icon = 'camera';
button.dataset.enabled = false;
button.dataset.l10nId = 'quick-settings-galleryButton-off';
button.addEventListener('click', onClick);
},
//Dial number
initDialButton: function initDailButton(button) {
function onClick() {
new MozActivity({
name: 'dial',
data: {
type: "webtelephony/number"
}
});
}
button.dataset.icon = 'call';
button.dataset.enabled = false;
button.dataset.l10nId = 'quick-settings-dialButton-off';
button.addEventListener('click', onClick);
},
//compose sms
initSmsButton: function initSmsButton(button) {
function onClick() {
new MozActivity({
name: "new",
data: {
type: "websms/sms"
}
});
}
button.dataset.icon = 'messages';
button.dataset.enabled = false;
button.dataset.l10nId = 'quick-settings-smsButton-off';
button.addEventListener('click', onClick);
},
//compose mail
initMailButton: function initMailButton(button) {
function onClick() {
new MozActivity({
name: "new",
data: {
type : "mail"
}
});
}
button.dataset.icon = 'compose';
button.dataset.enabled = false;
button.dataset.l10nId = 'quick-settings-mailButton-off';
button.addEventListener('click', onClick);
},
//add contact
initAddContactButton: function initAddContactButton(button) {
function onClick() {
new MozActivity({
name: 'new',
data: {
type: "webcontacts/contact"
}
});
}
button.dataset.icon = 'add';
button.dataset.enabled = false;
button.dataset.l10nId = 'quick-settings-addContactButton-off';
button.addEventListener('click', onClick);
}
};
// If injecting into an app that was already running at the time
// the app was enabled, simply initialize it.
if (document.documentElement) {
QuickAccess.initialize();
} else {
// Otherwise, we need to wait for the DOM to be ready before
// starting initialization since add-ons are usually (always?)
// injected *before* `document.documentElement` is defined.
window.addEventListener('DOMContentLoaded', QuickAccess.initialize);
}
}());