diff --git a/web/base_viewer.js b/web/base_viewer.js index 4149dd3a21456..6a9bacc42a3a9 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -183,6 +183,12 @@ class BaseViewer { this.spreadMode = options.spreadMode; } } + + // Defer the dispatching of this event, to give other viewer components + // time to initialize *and* register 'baseviewerinit' event listeners. + Promise.resolve().then(() => { + this.eventBus.dispatch('baseviewerinit', { source: this, }); + }); } get pagesCount() { diff --git a/web/pdf_cursor_tools.js b/web/pdf_cursor_tools.js index 8d230a5981c1d..2529639448198 100644 --- a/web/pdf_cursor_tools.js +++ b/web/pdf_cursor_tools.js @@ -47,6 +47,8 @@ class PDFCursorTools { this._addEventListeners(); + // Defer the initial `switchTool` call, to give other viewer components + // time to initialize *and* register 'cursortoolchanged' event listeners. Promise.resolve().then(() => { this.switchTool(cursorToolOnLoad); }); diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js index ac46becdeb9dd..bb41f2068cb2f 100644 --- a/web/secondary_toolbar.js +++ b/web/secondary_toolbar.js @@ -15,6 +15,7 @@ import { ScrollMode, SpreadMode } from './base_viewer'; import { CursorTool } from './pdf_cursor_tools'; +import { PDFSinglePageViewer } from './pdf_single_page_viewer'; import { SCROLLBAR_PADDING } from './ui_utils'; /** @@ -117,6 +118,18 @@ class SecondaryToolbar { // Bind the event listener for adjusting the 'max-height' of the toolbar. this.eventBus.on('resize', this._setMaxHeight.bind(this)); + + // Hide the Scroll/Spread mode buttons, when they're not applicable to the + // current `BaseViewer` instance (in particular `PDFSinglePageViewer`). + this.eventBus.on('baseviewerinit', (evt) => { + if (evt.source instanceof PDFSinglePageViewer) { + this.toolbarButtonContainer.classList.add('hiddenScrollModeButtons'); + this.toolbarButtonContainer.classList.add('hiddenSpreadModeButtons'); + } else { + this.toolbarButtonContainer.classList.remove('hiddenScrollModeButtons'); + this.toolbarButtonContainer.classList.remove('hiddenSpreadModeButtons'); + } + }); } /** @@ -142,8 +155,7 @@ class SecondaryToolbar { this._updateUIState(); // Reset the Scroll/Spread buttons too, since they're document specific. - this.eventBus.dispatch('resetscrollmode', { source: this, }); - this.eventBus.dispatch('resetspreadmode', { source: this, }); + this.eventBus.dispatch('secondarytoolbarreset', { source: this, }); } _updateUIState() { @@ -209,10 +221,17 @@ class SecondaryToolbar { buttons.scrollWrappedButton.classList.add('toggled'); break; } + + // Temporarily *disable* the Spread buttons when horizontal scrolling is + // enabled, since the non-default Spread modes doesn't affect the layout. + const isScrollModeHorizontal = (evt.mode === ScrollMode.HORIZONTAL); + buttons.spreadNoneButton.disabled = isScrollModeHorizontal; + buttons.spreadOddButton.disabled = isScrollModeHorizontal; + buttons.spreadEvenButton.disabled = isScrollModeHorizontal; } this.eventBus.on('scrollmodechanged', scrollModeChanged); - this.eventBus.on('resetscrollmode', (evt) => { + this.eventBus.on('secondarytoolbarreset', (evt) => { if (evt.source === this) { scrollModeChanged({ mode: ScrollMode.VERTICAL, }); } @@ -239,7 +258,7 @@ class SecondaryToolbar { } this.eventBus.on('spreadmodechanged', spreadModeChanged); - this.eventBus.on('resetspreadmode', (evt) => { + this.eventBus.on('secondarytoolbarreset', (evt) => { if (evt.source === this) { spreadModeChanged({ mode: SpreadMode.NONE, }); } diff --git a/web/viewer.css b/web/viewer.css index 2a87b025c938b..72230783dd3e3 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -394,6 +394,11 @@ html[dir='rtl'] .secondaryToolbar { margin-bottom: -4px; } +#secondaryToolbarButtonContainer.hiddenScrollModeButtons > .scrollModeButtons, +#secondaryToolbarButtonContainer.hiddenSpreadModeButtons > .spreadModeButtons { + display: none !important; +} + .doorHanger, .doorHangerRight { border: 1px solid hsla(0,0%,0%,.5); diff --git a/web/viewer.html b/web/viewer.html index ba0ac8e492eb6..5d64c1ed1b834 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -168,29 +168,29 @@
-