Skip to content

Commit

Permalink
Merge pull request #483 from JRegimbal/active-page-fix
Browse files Browse the repository at this point in the history
Active page fix
  • Loading branch information
vigliensoni authored Aug 21, 2019
2 parents 7e3643f + d0096a8 commit 4eeb1f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions source/js/document-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ function getCentermostPage (renderedPages, layout, viewport)
const centerPage = maxBy(renderedPages, pageIndex =>
{
const dims = layout.getPageDimensions(pageIndex);
const imageOffset = layout.getPageOffset(pageIndex, {includePadding: false});
const imageOffset = layout.getPageOffset(pageIndex, {includePadding: true});

const midX = imageOffset.left + (dims.height / 2);
const midY = imageOffset.top + (dims.width / 2);
const midX = imageOffset.left + (dims.width / 2);
const midY = imageOffset.top + (dims.height / 2);

const dx = Math.max(Math.abs(centerX - midX) - (dims.width / 2), 0);
const dy = Math.max(Math.abs(centerY - midY) - (dims.height / 2), 0);
Expand Down
13 changes: 11 additions & 2 deletions source/js/viewer-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1366,19 +1366,28 @@ export default class ViewerCore
if (!arraysEqual(this.viewerState.currentPageIndices, visiblePages))
{
this.viewerState.currentPageIndices = visiblePages;
this.viewerState.activePageIndex = activePage;
if (this.viewerState.activePageIndex !== activePage)
{
this.viewerState.activePageIndex = activePage;
this.publish("ActivePageDidChange", activePage);
}
this.publish("VisiblePageDidChange", visiblePages);

// Publish an event if the page we're switching to has other images.
if (this.viewerState.manifest.pages[activePage].otherImages.length > 0)
this.publish('VisiblePageHasAlternateViews', activePage);
}
else if (this.viewerState.activePageIndex !== activePage)
{
this.viewerState.activePageIndex = activePage;
this.publish("ActivePageDidChange", activePage);
}

function arraysEqual (a, b)
{
if (a.length !== b.length)
return false;

for (let i = 0, len = a.length; i < len; i++)
{
if (a[i] !== b[i])
Expand Down

0 comments on commit 4eeb1f5

Please sign in to comment.