Skip to content

Commit

Permalink
Fix getVisibleElements helper in RTL-locales
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed committed Oct 9, 2020
1 parent 88f72d6 commit 8e43606
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
7 changes: 6 additions & 1 deletion web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,10 @@ class BaseViewer {
: this._scrollMode === ScrollMode.HORIZONTAL;
}

get _isDirRtl() {
return this.container.ownerDocument.dir === "rtl";
}

get isInPresentationMode() {
return this.presentationModeState === PresentationModeState.FULLSCREEN;
}
Expand Down Expand Up @@ -1055,7 +1059,8 @@ class BaseViewer {
this.container,
this._pages,
true,
this._isScrollModeHorizontal
this._isScrollModeHorizontal,
this._isDirRtl
);
}

Expand Down
15 changes: 9 additions & 6 deletions web/ui_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ function getVisibleElements(
scrollEl,
views,
sortByVisibility = false,
horizontal = false
horizontal = false,
rtl = false
) {
const top = scrollEl.scrollTop,
bottom = top + scrollEl.clientHeight;
Expand All @@ -465,11 +466,11 @@ function getVisibleElements(
element.offsetTop + element.clientTop + element.clientHeight;
return elementBottom > top;
}
function isElementRightAfterViewLeft(view) {
function isElementNextAfterViewHorizontally(view) {
const element = view.div;
const elementRight =
element.offsetLeft + element.clientLeft + element.clientWidth;
return elementRight > left;
const elementLeft = element.offsetLeft + element.clientLeft;
const elementRight = elementLeft + element.clientWidth;
return rtl ? elementLeft < right : elementRight > left;
}

const visible = [],
Expand All @@ -479,7 +480,9 @@ function getVisibleElements(
? 0
: binarySearchFirstItem(
views,
horizontal ? isElementRightAfterViewLeft : isElementBottomAfterViewTop
horizontal
? isElementNextAfterViewHorizontally
: isElementBottomAfterViewTop
);

// Please note the return value of the `binarySearchFirstItem` function when
Expand Down

0 comments on commit 8e43606

Please sign in to comment.