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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { QuickSuggest } = ChromeUtils.importESModule(
"resource:///modules/QuickSuggest.sys.mjs"
);
const { ONBOARDING_CHOICE } = QuickSuggest;
const VARIATION_MAP = {
a: {
l10nUpdates: {
onboardingNext: "firefox-suggest-onboarding-introduction-next-button-1",
"introduction-title": "firefox-suggest-onboarding-introduction-title-1",
"main-title": "firefox-suggest-onboarding-main-title-1",
"main-description": "firefox-suggest-onboarding-main-description-1",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-1",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-1",
},
},
b: {
l10nUpdates: {
onboardingNext: "firefox-suggest-onboarding-introduction-next-button-1",
"introduction-title": "firefox-suggest-onboarding-introduction-title-2",
"main-title": "firefox-suggest-onboarding-main-title-2",
"main-description": "firefox-suggest-onboarding-main-description-2",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-1",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-1",
},
},
c: {
logoType: "firefox",
l10nUpdates: {
onboardingNext: "firefox-suggest-onboarding-introduction-next-button-1",
"introduction-title": "firefox-suggest-onboarding-introduction-title-3",
"main-title": "firefox-suggest-onboarding-main-title-3",
"main-description": "firefox-suggest-onboarding-main-description-3",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-1",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-1",
},
},
d: {
l10nUpdates: {
onboardingNext: "firefox-suggest-onboarding-introduction-next-button-1",
"introduction-title": "firefox-suggest-onboarding-introduction-title-4",
"main-title": "firefox-suggest-onboarding-main-title-4",
"main-description": "firefox-suggest-onboarding-main-description-4",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-2",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-2",
},
},
e: {
logoType: "firefox",
l10nUpdates: {
onboardingNext: "firefox-suggest-onboarding-introduction-next-button-1",
"introduction-title": "firefox-suggest-onboarding-introduction-title-5",
"main-title": "firefox-suggest-onboarding-main-title-5",
"main-description": "firefox-suggest-onboarding-main-description-5",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-2",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-2",
},
},
f: {
l10nUpdates: {
onboardingNext: "firefox-suggest-onboarding-introduction-next-button-2",
"introduction-title": "firefox-suggest-onboarding-introduction-title-6",
"main-title": "firefox-suggest-onboarding-main-title-6",
"main-description": "firefox-suggest-onboarding-main-description-6",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-2",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-2",
},
},
g: {
mainPrivacyFirst: true,
l10nUpdates: {
onboardingNext: "firefox-suggest-onboarding-introduction-next-button-1",
"introduction-title": "firefox-suggest-onboarding-introduction-title-7",
"main-title": "firefox-suggest-onboarding-main-title-7",
"main-description": "firefox-suggest-onboarding-main-description-7",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-2",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-2",
},
},
h: {
logoType: "firefox",
l10nUpdates: {
onboardingNext: "firefox-suggest-onboarding-introduction-next-button-1",
"introduction-title": "firefox-suggest-onboarding-introduction-title-2",
"main-title": "firefox-suggest-onboarding-main-title-8",
"main-description": "firefox-suggest-onboarding-main-description-8",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-1",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-1",
},
},
"100-a": {
introductionLayout: "layout-100",
mainPrivacyFirst: true,
logoType: "firefox",
l10nUpdates: {
onboardingNext: "firefox-suggest-onboarding-introduction-next-button-3",
"introduction-title": "firefox-suggest-onboarding-main-title-9",
"main-title": "firefox-suggest-onboarding-main-title-9",
"main-description": "firefox-suggest-onboarding-main-description-9",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label-2",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-3",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label-2",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-3",
},
},
"100-b": {
mainPrivacyFirst: true,
logoType: "firefox",
l10nUpdates: {
"main-title": "firefox-suggest-onboarding-main-title-9",
"main-description": "firefox-suggest-onboarding-main-description-9",
"main-accept-option-label":
"firefox-suggest-onboarding-main-accept-option-label-2",
"main-accept-option-description":
"firefox-suggest-onboarding-main-accept-option-description-3",
"main-reject-option-label":
"firefox-suggest-onboarding-main-reject-option-label-2",
"main-reject-option-description":
"firefox-suggest-onboarding-main-reject-option-description-3",
},
skipIntroduction: true,
},
};
// If the window height is smaller than this value when the dialog opens, then
// the dialog will open in compact mode. The dialog will not change modes while
// it's open even if the window height changes.
const COMPACT_MODE_HEIGHT =
650 + // section min-height (non-compact mode)
2 * 32 + // 2 * --section-vertical-padding (non-compact mode)
44; // approximate height of the browser window's tab bar
// Used for test only. If links or buttons may be clicked or typed Key_Enter
// while translating l10n, cannot capture the events since not register listeners
// yet. To avoid the issue, add this flag to know the listeners are ready.
let resolveOnboardingReady;
window._quicksuggestOnboardingReady = new Promise(r => {
resolveOnboardingReady = r;
});
document.addEventListener("DOMContentLoaded", async () => {
await document.l10n.ready;
const variation =
VARIATION_MAP[window.arguments[0].variationType] || VARIATION_MAP.a;
document.l10n.pauseObserving();
try {
await applyVariation(variation);
} finally {
document.l10n.resumeObserving();
}
addSubmitListener(document.getElementById("onboardingClose"), () => {
window.arguments[0].choice = ONBOARDING_CHOICE.CLOSE_1;
window.close();
});
addSubmitListener(document.getElementById("onboardingNext"), () => {
gotoMain(variation);
});
addSubmitListener(document.getElementById("onboardingLearnMore"), () => {
window.arguments[0].choice = ONBOARDING_CHOICE.LEARN_MORE_2;
window.close();
});
addSubmitListener(
document.getElementById("onboardingLearnMoreOnIntroduction"),
() => {
window.arguments[0].choice = ONBOARDING_CHOICE.LEARN_MORE_1;
window.close();
}
);
addSubmitListener(document.getElementById("onboardingSkipLink"), () => {
window.arguments[0].choice = ONBOARDING_CHOICE.NOT_NOW_2;
window.close();
});
const onboardingSubmit = document.getElementById("onboardingSubmit");
const onboardingAccept = document.getElementById("onboardingAccept");
const onboardingReject = document.getElementById("onboardingReject");
function optionChangeListener() {
onboardingSubmit.removeAttribute("disabled");
onboardingAccept
.closest(".option")
.classList.toggle("selected", onboardingAccept.checked);
onboardingReject
.closest(".option")
.classList.toggle("selected", !onboardingAccept.checked);
}
onboardingAccept.addEventListener("change", optionChangeListener);
onboardingReject.addEventListener("change", optionChangeListener);
function submitListener() {
if (!onboardingAccept.checked && !onboardingReject.checked) {
return;
}
window.arguments[0].choice = onboardingAccept.checked
? ONBOARDING_CHOICE.ACCEPT_2
: ONBOARDING_CHOICE.REJECT_2;
window.close();
}
addSubmitListener(onboardingSubmit, submitListener);
onboardingAccept.addEventListener("keydown", e => {
if (e.keyCode == e.DOM_VK_RETURN) {
submitListener();
}
});
onboardingReject.addEventListener("keydown", e => {
if (e.keyCode == e.DOM_VK_RETURN) {
submitListener();
}
});
if (window.outerHeight < COMPACT_MODE_HEIGHT) {
document.body.classList.add("compact");
}
resolveOnboardingReady();
});
function gotoMain(variation) {
window.arguments[0].visitedMain = true;
document.getElementById("introduction-section").classList.add("inactive");
document.getElementById("main-section").classList.add("active");
document.body.setAttribute("aria-labelledby", "main-title");
let ariaDescribedBy = "main-description";
if (variation.mainPrivacyFirst) {
ariaDescribedBy += " main-privacy-first";
}
document.body.setAttribute("aria-describedby", ariaDescribedBy);
}
async function applyVariation(variation) {
if (variation.logoType) {
for (const logo of document.querySelectorAll(".logo")) {
logo.classList.add(variation.logoType);
}
}
if (variation.mainPrivacyFirst) {
const label = document.querySelector("#main-section .privacy-first");
label.classList.add("active");
}
if (variation.l10nUpdates) {
const translatedElements = [];
for (const [id, newL10N] of Object.entries(variation.l10nUpdates)) {
const element = document.getElementById(id);
document.l10n.setAttributes(element, newL10N);
translatedElements.push(element);
}
await document.l10n.translateElements(translatedElements);
}
if (variation.skipIntroduction) {
document.body.classList.add("skip-introduction");
gotoMain(variation);
}
if (variation.introductionLayout) {
document
.getElementById("introduction-section")
.classList.add(variation.introductionLayout);
}
}
function addSubmitListener(element, listener) {
if (!element) {
console.warn("Element is null on addSubmitListener");
return;
}
element.addEventListener("click", listener);
element.addEventListener("keydown", e => {
if (e.keyCode == e.DOM_VK_RETURN) {
listener();
}
});
}
|