From aad4c6538f1ac8425d60dc1531d0f34193ce10d1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 3 May 2022 13:14:17 +0200 Subject: [PATCH] Re-factor the PresentationMode handling in `BaseViewer.#ensurePageViewVisible` Given that we're (ab)using spread-modes in order to ensure that pages are centered *vertically* in PresentationMode, this re-factoring simplifies the code slightly. Furthermore, in the event that we *possibly* want to try and support spread-modes in PresentationMode[1] this re-factoring will also prevent future duplication. --- [1] Note that I'm not particularly keen on doing that, since documents with varying page sizes will be annoying to handle. --- web/base_viewer.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index 7db0d193f..284deb331 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -885,23 +885,10 @@ class BaseViewer { // ... and clear out the active ones. state.pages.length = 0; - if (this._spreadMode === SpreadMode.NONE) { + if (this._spreadMode === SpreadMode.NONE && !this.isInPresentationMode) { // Finally, append the new page to the viewer. const pageView = this._pages[pageNumber - 1]; - - if (this.isInPresentationMode) { - const spread = document.createElement("div"); - spread.className = "spread"; - const dummyPage = document.createElement("div"); - dummyPage.className = "dummyPage"; - dummyPage.style.height = `${this.container.clientHeight}px`; - - spread.appendChild(dummyPage); - spread.appendChild(pageView.div); - viewer.appendChild(spread); - } else { - viewer.appendChild(pageView.div); - } + viewer.appendChild(pageView.div); state.pages.push(pageView); } else { @@ -909,7 +896,10 @@ class BaseViewer { parity = this._spreadMode - 1; // Determine the pageIndices in the new spread. - if (pageNumber % 2 !== parity) { + if (parity === -1) { + // PresentationMode is active, with `SpreadMode.NONE` set. + pageIndexSet.add(pageNumber - 1); + } else if (pageNumber % 2 !== parity) { // Left-hand side page. pageIndexSet.add(pageNumber - 1); pageIndexSet.add(pageNumber); @@ -923,6 +913,13 @@ class BaseViewer { const spread = document.createElement("div"); spread.className = "spread"; + if (this.isInPresentationMode) { + const dummyPage = document.createElement("div"); + dummyPage.className = "dummyPage"; + dummyPage.style.height = `${this.container.clientHeight}px`; + spread.appendChild(dummyPage); + } + for (const i of pageIndexSet) { const pageView = this._pages[i]; if (!pageView) {