From 48f4580991bda3b2f9756d768a436151bc5c2cb2 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 14 Feb 2021 12:32:50 +0100 Subject: [PATCH 1/2] A couple of small `BaseViewer` tweaks - Mark `BaseViewer.initializeScriptingEvents` as an `async` method, since that's actually how it's being used in the default viewer (see `PDFViewerApplication-_initializeJavaScript`). - Change `BaseViewer._pageWidthScaleFactor` to access the *internal* scroll/spread-modes directly, rather than using the getters, since that's consistent with the rest of the code (and not just for these properties). --- web/base_viewer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index 3c6f169f5..4ffd54e4c 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -740,8 +740,8 @@ class BaseViewer { */ get _pageWidthScaleFactor() { if ( - this.spreadMode !== SpreadMode.NONE && - this.scrollMode !== ScrollMode.HORIZONTAL && + this._spreadMode !== SpreadMode.NONE && + this._scrollMode !== ScrollMode.HORIZONTAL && !this.isInPresentationMode ) { return 2; @@ -1642,7 +1642,7 @@ class BaseViewer { return true; } - initializeScriptingEvents() { + async initializeScriptingEvents() { if (!this.enableScripting || this._pageOpenPendingSet) { return; } From 209fe604725d81bfbacb760eb005c1ca19c245d2 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 14 Feb 2021 12:37:37 +0100 Subject: [PATCH 2/2] Use a more compact format for the fallback EventBus-listeners in `PDFViewerApplication_initializeJavaScript` Given that these event listeners should essentially never be needed, but are included simply to avoid breakage in edge-cases, it can't hurt to make this code slightly less verbose. --- web/app.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/web/app.js b/web/app.js index dc080e7ca..2af3a511e 100644 --- a/web/app.js +++ b/web/app.js @@ -1479,13 +1479,7 @@ const PDFViewerApplication = { // It should be *extremely* rare for metadata to not have been resolved // when this code runs, but ensure that we handle that case here. await new Promise(resolve => { - this.eventBus._on( - "metadataloaded", - evt => { - resolve(); - }, - { once: true } - ); + this.eventBus._on("metadataloaded", resolve, { once: true }); }); if (pdfDocument !== this.pdfDocument) { return; // The document was closed while the metadata resolved. @@ -1498,13 +1492,7 @@ const PDFViewerApplication = { // Hence we'll simply have to trust that the `contentLength` (as provided // by the server), when it exists, is accurate enough here. await new Promise(resolve => { - this.eventBus._on( - "documentloaded", - evt => { - resolve(); - }, - { once: true } - ); + this.eventBus._on("documentloaded", resolve, { once: true }); }); if (pdfDocument !== this.pdfDocument) { return; // The document was closed while the downloadInfo resolved.