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 = {

View File

@ -18,17 +18,19 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define('pdfjs-web/hand_tool', ['exports', 'pdfjs-web/grab_to_pan',
'pdfjs-web/preferences'], factory);
'pdfjs-web/preferences', 'pdfjs-web/ui_utils'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('./grab_to_pan.js'), require('./preferences.js'));
factory(exports, require('./grab_to_pan.js'), require('./preferences.js'),
require('./ui_utils.js'));
} else {
factory((root.pdfjsWebHandTool = {}), root.pdfjsWebGrabToPan,
root.pdfjsWebPreferences);
root.pdfjsWebPreferences, root.pdfjsWebUIUtils);
}
}(this, function (exports, grabToPan, preferences) {
}(this, function (exports, grabToPan, preferences, uiUtils) {
var GrabToPan = grabToPan.GrabToPan;
var Preferences = preferences.Preferences;
var localized = uiUtils.localized;
/**
* @typedef {Object} HandToolOptions
@ -59,13 +61,12 @@ var HandTool = (function HandToolClosure() {
this.eventBus.on('togglehandtool', this.toggle.bind(this));
this.eventBus.on('localized', function (e) {
Preferences.get('enableHandToolOnLoad').then(function resolved(value) {
if (value) {
Promise.all([localized, Preferences.get('enableHandToolOnLoad')]).then(
function resolved(values) {
if (values[1] === true) {
this.handTool.activate();
}
}.bind(this), function rejected(reason) {});
}.bind(this));
}.bind(this)).catch(function rejected(reason) { });
this.eventBus.on('presentationmodechanged', function (e) {
if (e.switchInProgress) {