1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-02 14:49:16 +02:00

add RTL support for moveTo function

fixes links in RTL books
This commit is contained in:
Ali Kazemkhanloo 2020-12-12 19:04:57 +03:30 committed by GitHub
parent a1e77b745b
commit 1e5c12c9bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -277,7 +277,8 @@ class DefaultViewManager {
if(target) {
let offset = visible.locationOf(target);
this.moveTo(offset);
let width = visible.width();
this.moveTo(offset, width);
}
displaying.resolve();
@ -298,7 +299,8 @@ class DefaultViewManager {
// Move to correct place within the section, if needed
if(target) {
let offset = view.locationOf(target);
this.moveTo(offset);
let width = view.width();
this.moveTo(offset, width);
}
}.bind(this), (err) => {
@ -331,7 +333,7 @@ class DefaultViewManager {
this.emit(EVENTS.MANAGERS.RESIZE, view.section);
}
moveTo(offset){
moveTo(offset, width){
var distX = 0,
distY = 0;
@ -344,6 +346,15 @@ class DefaultViewManager {
distX = this.container.scrollWidth - this.layout.delta;
}
}
if(this.settings.direction === 'rtl'){
/***
the `floor` function above (L343) is on positive values, so we should add one `layout.delta`
to distX or use `Math.ceil` function, or multiply offset.left by -1
before `Math.floor`
*/
distX = distX + this.layout.delta
distX = distX - width
}
this.scrollTo(distX, distY, true);
}