Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fix internal presentation links #946

Merged
merged 2 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
jstoffan marked this conversation as resolved.
Show resolved Hide resolved
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