... |
... |
@@ -182,21 +182,6 @@ const SurveyArea = { |
182
|
182
|
*/
|
183
|
183
|
_version: 1,
|
184
|
184
|
|
185
|
|
- /**
|
186
|
|
- * The latest version of the survey the user has dismissed.
|
187
|
|
- * If higher or equal than _version, the survey will not be displayed.
|
188
|
|
- *
|
189
|
|
- * @type {integer}
|
190
|
|
- */
|
191
|
|
- _dismissVersion: 0,
|
192
|
|
-
|
193
|
|
- /**
|
194
|
|
- * The surveys will be shown only in the stable channel of Tor Browser.
|
195
|
|
- *
|
196
|
|
- * @type {boolean}
|
197
|
|
- */
|
198
|
|
- _isStable: false,
|
199
|
|
-
|
200
|
185
|
/**
|
201
|
186
|
* The date to start showing the survey.
|
202
|
187
|
*
|
... |
... |
@@ -308,13 +293,6 @@ const SurveyArea = { |
308
|
293
|
},
|
309
|
294
|
],
|
310
|
295
|
|
311
|
|
- /**
|
312
|
|
- * The observer to update the localized content whenever the language changes.
|
313
|
|
- *
|
314
|
|
- * @type {MutationObserver}
|
315
|
|
- */
|
316
|
|
- _langObserver: null,
|
317
|
|
-
|
318
|
296
|
/**
|
319
|
297
|
* Initialize the survey area.
|
320
|
298
|
*/
|
... |
... |
@@ -333,17 +311,6 @@ const SurveyArea = { |
333
|
311
|
document.getElementById("survey-dismiss").addEventListener("click", () => {
|
334
|
312
|
this._hide();
|
335
|
313
|
});
|
336
|
|
- this._langObserver = new MutationObserver(mutationList => {
|
337
|
|
- for (const mutation of mutationList) {
|
338
|
|
- if (
|
339
|
|
- mutation.type === "attributes" &&
|
340
|
|
- mutation.attributeName === "lang"
|
341
|
|
- ) {
|
342
|
|
- this.potentiallyShow();
|
343
|
|
- }
|
344
|
|
- }
|
345
|
|
- });
|
346
|
|
- this._langObserver.observe(document.documentElement, { attributes: true });
|
347
|
314
|
},
|
348
|
315
|
|
349
|
316
|
/**
|
... |
... |
@@ -366,49 +333,42 @@ const SurveyArea = { |
366
|
333
|
},
|
367
|
334
|
|
368
|
335
|
/**
|
369
|
|
- * Set the data for the survey.
|
|
336
|
+ * Decide whether to show the survey.
|
370
|
337
|
*
|
371
|
338
|
* @param {integer} dismissVersion - The latest version of survey that the
|
372
|
339
|
* user has already dismissed.
|
373
|
340
|
* @param {boolean} isStable - Whether this is the stable release of Tor
|
374
|
341
|
* Browser.
|
|
342
|
+ * @param {string} appLocale - The app locale currently in use.
|
375
|
343
|
*/
|
376
|
|
- setData(dismissVersion, isStable) {
|
377
|
|
- this._isStable = isStable;
|
378
|
|
- this._dismissVersion = dismissVersion;
|
379
|
|
- this.potentiallyShow();
|
380
|
|
- },
|
381
|
|
-
|
382
|
|
- /**
|
383
|
|
- * Decide whether to show or update the survey.
|
384
|
|
- */
|
385
|
|
- potentiallyShow() {
|
|
344
|
+ potentiallyShow(dismissVersion, isStable, appLocale) {
|
386
|
345
|
const now = Date.now();
|
387
|
346
|
if (
|
388
|
347
|
now < this._startDate ||
|
389
|
348
|
now >= this._endDate ||
|
390
|
349
|
// The user has already dismissed this version of the survey before:
|
391
|
|
- this._dismissVersion >= this._version ||
|
392
|
|
- !this._isStable
|
|
350
|
+ dismissVersion >= this._version ||
|
|
351
|
+ !isStable
|
393
|
352
|
) {
|
394
|
353
|
// Don't show the survey.
|
395
|
|
- document.body.classList.remove("show-survey");
|
396
|
354
|
return;
|
397
|
355
|
}
|
398
|
356
|
|
399
|
|
- // Determine the survey locale based on the about:tor locale.
|
|
357
|
+ // Determine the survey locale based on the app locale.
|
400
|
358
|
// NOTE: We do not user document.l10n to translate the survey banner.
|
401
|
359
|
// Instead we only translate the banner into a limited set of locales that
|
402
|
360
|
// match the languages that the survey itself supports. This should match
|
403
|
361
|
// the language of the survey when it is opened by the user.
|
404
|
|
- this._localeData = this._localeDataSet[0];
|
405
|
|
- const pageLocale = document.documentElement.getAttribute("lang");
|
406
|
362
|
for (const localeData of this._localeDataSet) {
|
407
|
|
- if (localeData.browserLocales.includes(pageLocale)) {
|
|
363
|
+ if (localeData.browserLocales.includes(appLocale)) {
|
408
|
364
|
this._localeData = localeData;
|
409
|
365
|
break;
|
410
|
366
|
}
|
411
|
367
|
}
|
|
368
|
+ if (!this._localeData) {
|
|
369
|
+ // Show the default en-US banner.
|
|
370
|
+ this._localeData = this._localeDataSet[0];
|
|
371
|
+ }
|
412
|
372
|
|
413
|
373
|
// Make sure the survey's lang and dir attributes match the chosen locale.
|
414
|
374
|
const surveyEl = document.getElementById("survey");
|
... |
... |
@@ -440,8 +400,9 @@ window.addEventListener("InitialData", event => { |
440
|
400
|
searchOnionize,
|
441
|
401
|
messageData,
|
442
|
402
|
surveyDismissVersion,
|
|
403
|
+ appLocale,
|
443
|
404
|
} = event.detail;
|
444
|
405
|
SearchWidget.setOnionizeState(!!searchOnionize);
|
445
|
406
|
MessageArea.setMessageData(messageData, !!isStable, !!torConnectEnabled);
|
446
|
|
- SurveyArea.setData(surveyDismissVersion, isStable);
|
|
407
|
+ SurveyArea.potentiallyShow(surveyDismissVersion, isStable, appLocale);
|
447
|
408
|
}); |