Convert the only remaining consumer (in hand_tool.js) of the 'localized' event to use the localized Promise instead, and only re-dispatch the 'localized' event on the eventBus for GENERIC builds

Ideally we'd remove the 'localized' event from the `eventBus`, but for backwards compatibility we keep it in `GENERIC` builds.
Note that while we want to ensure that the direction attribute of the HTML is updated as soon as the `localized` Promise is resolved, we purposely wait until the viewer has been initialized to ensure that the 'localized' event will always be dispatched.
This commit is contained in:
Jonas Jenwald 2016-12-08 14:44:12 +01:00
parent 648024f5d0
commit a96b0f80dd
2 changed files with 21 additions and 15 deletions

View file

@ -215,6 +215,14 @@ var PDFViewerApplication = {
self.bindEvents();
self.bindWindowEvents();
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
// For backwards compatibility, we dispatch the 'localized' event on
// the `eventBus` once the viewer has been initialized.
localized.then(function () {
self.eventBus.dispatch('localized');
});
}
if (self.isViewerEmbedded && !PDFJS.isExternalLinkTargetSet()) {
// Prevent external links from "replacing" the viewer,
// when it's embedded in e.g. an iframe or an object.
@ -1788,11 +1796,6 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
};
}
function webViewerLocalized() {
document.getElementsByTagName('html')[0].dir = mozL10n.getDirection();
PDFViewerApplication.eventBus.dispatch('localized');
}
function webViewerPresentationMode() {
PDFViewerApplication.requestPresentationMode();
}
@ -2241,7 +2244,9 @@ function webViewerKeyDown(evt) {
}
}
localized.then(webViewerLocalized);
localized.then(function webViewerLocalized() {
document.getElementsByTagName('html')[0].dir = mozL10n.getDirection();
});
/* Abstract factory for the print service. */
var PDFPrintServiceFactory = {