mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Major RTL fixes
This commit is contained in:
parent
be24ab8b39
commit
e2c77d6f3a
5 changed files with 122 additions and 33 deletions
|
@ -995,7 +995,7 @@ class Contents {
|
||||||
* @param {number} columnWidth
|
* @param {number} columnWidth
|
||||||
* @param {number} gap
|
* @param {number} gap
|
||||||
*/
|
*/
|
||||||
columns(width, height, columnWidth, gap){
|
columns(width, height, columnWidth, gap, dir){
|
||||||
let COLUMN_AXIS = prefixed("column-axis");
|
let COLUMN_AXIS = prefixed("column-axis");
|
||||||
let COLUMN_GAP = prefixed("column-gap");
|
let COLUMN_GAP = prefixed("column-gap");
|
||||||
let COLUMN_WIDTH = prefixed("column-width");
|
let COLUMN_WIDTH = prefixed("column-width");
|
||||||
|
@ -1006,9 +1006,8 @@ class Contents {
|
||||||
|
|
||||||
this.layoutStyle("paginated");
|
this.layoutStyle("paginated");
|
||||||
|
|
||||||
// Fix body width issues if rtl is only set on body element
|
if (dir === "rtl") {
|
||||||
if (this.content.dir === "rtl") {
|
this.direction(dir);
|
||||||
this.direction("rtl");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.width(width);
|
this.width(width);
|
||||||
|
|
|
@ -195,7 +195,7 @@ class Layout {
|
||||||
if (this.name === "pre-paginated") {
|
if (this.name === "pre-paginated") {
|
||||||
formating = contents.fit(this.columnWidth, this.height);
|
formating = contents.fit(this.columnWidth, this.height);
|
||||||
} else if (this._flow === "paginated") {
|
} else if (this._flow === "paginated") {
|
||||||
formating = contents.columns(this.width, this.height, this.columnWidth, this.gap);
|
formating = contents.columns(this.width, this.height, this.columnWidth, this.gap, this.settings.direction);
|
||||||
} else { // scrolled
|
} else { // scrolled
|
||||||
formating = contents.size(this.width, null);
|
formating = contents.size(this.width, null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,20 +265,34 @@ class ContinuousViewManager extends DefaultViewManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
//Horizontal negative scrooling
|
||||||
|
if (horizontal && rtl && this.settings.rtlScrollType === "negative") {
|
||||||
|
|
||||||
if (offset + visibleLength + delta >= contentLength) {
|
if (offset - delta <= (-1 * contentLength)) {
|
||||||
if (horizontal && rtl) {
|
append();
|
||||||
prepend();
|
|
||||||
} else {
|
|
||||||
append();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (offset - delta < 0 ) {
|
if (offset + delta > 0) {
|
||||||
if (horizontal && rtl) {
|
prepend();
|
||||||
append();
|
}
|
||||||
} else {
|
|
||||||
prepend();
|
}
|
||||||
|
//default scrooling
|
||||||
|
else {
|
||||||
|
if (offset + visibleLength + delta >= contentLength) {
|
||||||
|
if (horizontal && rtl) {
|
||||||
|
prepend();
|
||||||
|
} else {
|
||||||
|
append();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offset - delta < 0) {
|
||||||
|
if (horizontal && rtl) {
|
||||||
|
append();
|
||||||
|
} else {
|
||||||
|
prepend();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +369,17 @@ class ContinuousViewManager extends DefaultViewManager {
|
||||||
if(this.settings.axis === "vertical") {
|
if(this.settings.axis === "vertical") {
|
||||||
this.scrollTo(0, prevTop - bounds.height, true);
|
this.scrollTo(0, prevTop - bounds.height, true);
|
||||||
} else {
|
} else {
|
||||||
this.scrollTo(prevLeft - Math.floor(bounds.width), 0, true);
|
if(this.settings.direction === 'rtl') {
|
||||||
|
if (this.settings.rtlScrollType === "default") {
|
||||||
|
this.scrollTo(prevLeft, 0, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.scrollTo(prevLeft + Math.floor(bounds.width), 0, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.scrollTo(prevLeft - Math.floor(bounds.width), 0, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,29 @@ class DefaultViewManager {
|
||||||
|
|
||||||
this.settings.size = size;
|
this.settings.size = size;
|
||||||
|
|
||||||
|
//Detect RTL scroll type
|
||||||
|
var definer = document.createElement('div');
|
||||||
|
definer.style.position = "absolute";
|
||||||
|
definer.style.width = "1px";
|
||||||
|
definer.style.height = "1px";
|
||||||
|
definer.style.overflow = "scroll";
|
||||||
|
definer.dir="rtl";
|
||||||
|
definer.appendChild(document.createTextNode('A'));
|
||||||
|
|
||||||
|
document.body.appendChild(definer);
|
||||||
|
var type = 'reverse';
|
||||||
|
|
||||||
|
if (definer.scrollLeft > 0) {
|
||||||
|
type = 'default';
|
||||||
|
} else {
|
||||||
|
definer.scrollLeft = 1;
|
||||||
|
if (definer.scrollLeft === 0) {
|
||||||
|
type = 'negative';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.body.removeChild(definer);
|
||||||
|
this.settings.rtlScrollType = type;
|
||||||
|
|
||||||
// Save the stage
|
// Save the stage
|
||||||
this.stage = new Stage({
|
this.stage = new Stage({
|
||||||
width: size.width,
|
width: size.width,
|
||||||
|
@ -423,13 +446,25 @@ class DefaultViewManager {
|
||||||
|
|
||||||
this.scrollLeft = this.container.scrollLeft;
|
this.scrollLeft = this.container.scrollLeft;
|
||||||
|
|
||||||
left = this.container.scrollLeft;
|
if (this.settings.rtlScrollType === "default"){
|
||||||
|
left = this.container.scrollLeft;
|
||||||
|
|
||||||
if(left > 0) {
|
if (left > 0) {
|
||||||
this.scrollBy(this.layout.delta, 0, true);
|
this.scrollBy(this.layout.delta, 0, true);
|
||||||
} else {
|
} else {
|
||||||
next = this.views.last().section.next();
|
next = this.views.last().section.next();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
left = this.container.scrollLeft + ( this.layout.delta * -1 );
|
||||||
|
if (left > this.container.scrollWidth * -1){
|
||||||
|
this.scrollBy(this.layout.delta, 0, true);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
next = this.views.last().section.next();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (this.isPaginated && this.settings.axis === "vertical") {
|
} else if (this.isPaginated && this.settings.axis === "vertical") {
|
||||||
|
|
||||||
|
@ -493,13 +528,25 @@ class DefaultViewManager {
|
||||||
|
|
||||||
this.scrollLeft = this.container.scrollLeft;
|
this.scrollLeft = this.container.scrollLeft;
|
||||||
|
|
||||||
left = this.container.scrollLeft + this.container.offsetWidth + this.layout.delta;
|
if (this.settings.rtlScrollType === "default"){
|
||||||
|
left = this.container.scrollLeft + this.container.offsetWidth + this.layout.delta;
|
||||||
|
|
||||||
if(left <= this.container.scrollWidth) {
|
if (left <= this.container.scrollWidth) {
|
||||||
this.scrollBy(-this.layout.delta, 0, true);
|
this.scrollBy(-this.layout.delta, 0, true);
|
||||||
} else {
|
} else {
|
||||||
prev = this.views.first().section.prev();
|
prev = this.views.first().section.prev();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
left = this.container.scrollLeft;
|
||||||
|
|
||||||
|
if (left < 0) {
|
||||||
|
this.scrollBy(-this.layout.delta, 0, true);
|
||||||
|
} else {
|
||||||
|
prev = this.views.first().section.prev();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else if (this.isPaginated && this.settings.axis === "vertical") {
|
} else if (this.isPaginated && this.settings.axis === "vertical") {
|
||||||
|
|
||||||
|
@ -537,7 +584,12 @@ class DefaultViewManager {
|
||||||
.then(function(){
|
.then(function(){
|
||||||
if(this.isPaginated && this.settings.axis === "horizontal") {
|
if(this.isPaginated && this.settings.axis === "horizontal") {
|
||||||
if (this.settings.direction === "rtl") {
|
if (this.settings.direction === "rtl") {
|
||||||
this.scrollTo(0, 0, true);
|
if (this.settings.rtlScrollType === "default"){
|
||||||
|
this.scrollTo(0, 0, true);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.scrollTo((this.container.scrollWidth * -1) + this.layout.delta, 0, true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.scrollTo(this.container.scrollWidth - this.layout.delta, 0, true);
|
this.scrollTo(this.container.scrollWidth - this.layout.delta, 0, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,21 @@ class Packaging {
|
||||||
this.uniqueIdentifier = this.findUniqueIdentifier(packageDocument);
|
this.uniqueIdentifier = this.findUniqueIdentifier(packageDocument);
|
||||||
this.metadata = this.parseMetadata(metadataNode);
|
this.metadata = this.parseMetadata(metadataNode);
|
||||||
|
|
||||||
this.metadata.direction = spineNode.getAttribute("page-progression-direction");
|
// Detect book direction - default ltr
|
||||||
|
//RTL detection
|
||||||
|
//1. spineNode attributes page-progression-direction
|
||||||
|
//2. Language metadata field check against rtl languages
|
||||||
|
this.metadata.direction = ( function() {
|
||||||
|
var defaultDirection = "ltr";
|
||||||
|
var rtlLanguages =
|
||||||
|
["ar", "arc", "dv", "fa", "ha", "he", "khw", "ku", "ps", "ur", "yi"];
|
||||||
|
|
||||||
|
var isRTLLanguage = rtlLanguages.indexOf(this.metadata.language.toLowerCase()) > -1;
|
||||||
|
|
||||||
|
return spineNode.getAttribute("page-progression-direction") ||
|
||||||
|
isRTLLanguage ? "rtl" : "" ||
|
||||||
|
defaultDirection;
|
||||||
|
}.bind(this))();
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue