Skip to content

Commit

Permalink
Fix: Fix internal presentation links (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Feb 28, 2019
1 parent e06b60a commit e575a89
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
14 changes: 13 additions & 1 deletion src/lib/viewers/doc/PresentationViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
36 changes: 26 additions & 10 deletions src/lib/viewers/doc/__tests__/PresentationViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/doc/_docBase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit e575a89

Please sign in to comment.