Wraps mozL10n to async calls; splits firefox and generic l10n libs.

This commit is contained in:
Yury Delendik 2017-05-03 20:05:53 -05:00
parent 09d46e94c6
commit 5438ce9b98
28 changed files with 463 additions and 260 deletions

View file

@ -14,7 +14,7 @@
*/
import { FindStates } from './pdf_find_controller';
import { mozL10n } from './ui_utils';
import { NullL10n } from './ui_utils';
/**
* Creates a "search bar" given a set of DOM elements that act as controls
@ -23,7 +23,7 @@ import { mozL10n } from './ui_utils';
* is done by PDFFindController.
*/
class PDFFindBar {
constructor(options) {
constructor(options, l10n = NullL10n) {
this.opened = false;
this.bar = options.bar || null;
@ -38,6 +38,7 @@ class PDFFindBar {
this.findNextButton = options.findNextButton || null;
this.findController = options.findController || null;
this.eventBus = options.eventBus;
this.l10n = l10n;
if (this.findController === null) {
throw new Error('PDFFindBar cannot be used without a ' +
@ -115,16 +116,16 @@ class PDFFindBar {
break;
case FindStates.FIND_NOTFOUND:
findMsg = mozL10n.get('find_not_found', null, 'Phrase not found');
findMsg = this.l10n.get('find_not_found', null, 'Phrase not found');
notFound = true;
break;
case FindStates.FIND_WRAPPED:
if (previous) {
findMsg = mozL10n.get('find_reached_top', null,
findMsg = this.l10n.get('find_reached_top', null,
'Reached top of document, continued from bottom');
} else {
findMsg = mozL10n.get('find_reached_bottom', null,
findMsg = this.l10n.get('find_reached_bottom', null,
'Reached end of document, continued from top');
}
break;
@ -137,7 +138,9 @@ class PDFFindBar {
}
this.findField.setAttribute('data-status', status);
this.findMsg.textContent = findMsg;
Promise.resolve(findMsg).then((msg) => {
this.findMsg.textContent = msg;
});
this.updateResultsCount(matchCount);
this._adjustWidth();