1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #12464 from baloone/Fix_getVisibleElements_in_rtl_direction

Fix getVisibleElements helper in RTL-locales
This commit is contained in:
Tim van der Meij 2020-10-24 17:03:57 +02:00 committed by GitHub
commit 0d1a874358
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 11 deletions

View file

@ -1006,6 +1006,10 @@ class BaseViewer {
: this._scrollMode === ScrollMode.HORIZONTAL;
}
get _isContainerRtl() {
return getComputedStyle(this.container).direction === "rtl";
}
get isInPresentationMode() {
return this.presentationModeState === PresentationModeState.FULLSCREEN;
}
@ -1055,7 +1059,8 @@ class BaseViewer {
this.container,
this._pages,
true,
this._isScrollModeHorizontal
this._isScrollModeHorizontal,
this._isScrollModeHorizontal && this._isContainerRtl
);
}

View file

@ -442,7 +442,8 @@ function getVisibleElements(
scrollEl,
views,
sortByVisibility = false,
horizontal = false
horizontal = false,
rtl = false
) {
const top = scrollEl.scrollTop,
bottom = top + scrollEl.clientHeight;
@ -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 = [],
@ -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