diff --git a/src/lib/viewers/doc/PresentationViewer.js b/src/lib/viewers/doc/PresentationViewer.js index f7189257f..e9578dfd4 100644 --- a/src/lib/viewers/doc/PresentationViewer.js +++ b/src/lib/viewers/doc/PresentationViewer.js @@ -276,8 +276,20 @@ class PresentationViewer extends DocBaseViewer { */ overwritePdfViewerBehavior() { // Overwrite scrollPageIntoView for presentations since we have custom pagination behavior - this.pdfViewer.scrollPageIntoView = () => {}; + // This override is needed to allow PDF.js to change pages when clicking on links in a presentation that + // navigate to other pages + this.pdfViewer.scrollPageIntoView = (pageObj) => { + if (!this.loaded) { + return; + } + let pageNum = pageObj; + if (typeof pageNum !== 'number') { + pageNum = pageObj.pageNumber || 1; + } + + this.setPage(pageNum); + }; // Overwrite _getVisiblePages for presentations to always calculate instead of fetching visible // elements since we lay out presentations differently this.pdfViewer._getVisiblePages = () => { diff --git a/src/lib/viewers/doc/__tests__/PresentationViewer-test.js b/src/lib/viewers/doc/__tests__/PresentationViewer-test.js index 5bd7b6cfa..d09d56396 100644 --- a/src/lib/viewers/doc/__tests__/PresentationViewer-test.js +++ b/src/lib/viewers/doc/__tests__/PresentationViewer-test.js @@ -443,16 +443,32 @@ describe('lib/viewers/doc/PresentationViewer', () => { }); describe('overwritePdfViewerBehavior()', () => { - it('should overwrite the scrollPageIntoView method', () => { - const setPageStub = sandbox.stub(presentation, 'setPage'); - const page = { - pageNumber: 3 - }; - - presentation.overwritePdfViewerBehavior(); - presentation.pdfViewer.scrollPageIntoView(page); - - expect(setPageStub).to.not.be.called; + describe('should overwrite the scrollPageIntoView method', () => { + it('should do nothing if the viewer is not loaded', () => { + const setPageStub = sandbox.stub(presentation, 'setPage'); + const page = { + pageNumber: 3 + }; + + presentation.loaded = false; + presentation.overwritePdfViewerBehavior(); + presentation.pdfViewer.scrollPageIntoView(page); + + expect(setPageStub).to.not.be.called; + }); + + it('should change the page if the viewer is loaded', () => { + const setPageStub = sandbox.stub(presentation, 'setPage'); + const page = { + pageNumber: 3 + }; + + presentation.loaded = true; + presentation.overwritePdfViewerBehavior(); + presentation.pdfViewer.scrollPageIntoView(page); + + expect(setPageStub).to.be.calledWith(3); + }); }); it('should overwrite the _getVisiblePages method', () => { diff --git a/src/lib/viewers/doc/_docBase.scss b/src/lib/viewers/doc/_docBase.scss index 8fefec099..388266272 100644 --- a/src/lib/viewers/doc/_docBase.scss +++ b/src/lib/viewers/doc/_docBase.scss @@ -34,8 +34,8 @@ $thumbnail-border-radius: 4px; border-radius: $thumbnail-border-radius; cursor: pointer; flex: 1 0 auto; - padding: 0; overflow: hidden; + padding: 0; width: 134px; }