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

Pass axis to Mapping

This commit is contained in:
Fred Chasen 2017-10-31 11:46:54 -07:00
parent 101cd47513
commit 922f9c9ba4
3 changed files with 28 additions and 25 deletions

View file

@ -421,12 +421,10 @@ class DefaultViewManager {
this.scrollTop = this.container.scrollTop; this.scrollTop = this.container.scrollTop;
let top = this.container.scrollTop + this.container.offsetHeight + this.layout.delta; let top = this.container.scrollTop + this.container.offsetHeight;
if(top <= this.container.scrollHeight) { if(top < this.container.scrollHeight) {
this.scrollBy(0, this.layout.height + this.layout.gap / 2, true); this.scrollBy(0, this.layout.height + this.layout.gap / 2, true);
} else if ((left - this.layout.pageWidth) === this.container.scrollWidth) {
this.scrollTo(this.container.scrollWidth - this.layout.delta, 0, true);
} else { } else {
next = this.views.last().section.next(); next = this.views.last().section.next();
} }
@ -521,7 +519,7 @@ class DefaultViewManager {
} }
}.bind(this)) }.bind(this))
.then(function(){ .then(function(){
if(this.isPaginated) { if(this.isPaginated && this.settings.axis === "horizontal") {
if (this.settings.direction === "rtl") { if (this.settings.direction === "rtl") {
this.scrollTo(0, 0, true); this.scrollTo(0, 0, true);
} else { } else {
@ -555,7 +553,7 @@ class DefaultViewManager {
currentLocation(){ currentLocation(){
if (!this.isPaginated) { if (this.settings.axis === "vertical") {
this.location = this.scrolledLocation(); this.location = this.scrolledLocation();
} else { } else {
this.location = this.paginatedLocation(); this.location = this.paginatedLocation();
@ -587,14 +585,15 @@ class DefaultViewManager {
used = (endPos - startPos); used = (endPos - startPos);
} }
let totalPages = this.layout.count(view._height, pageHeight).pages; let totalPages = this.layout.count(height, pageHeight).pages;
let currPage = Math.ceil(startPos / pageHeight); let currPage = Math.ceil(startPos / pageHeight);
let pages = []; let pages = [];
let endPage = Math.ceil(endPos / pageHeight); let endPage = Math.ceil(endPos / pageHeight);
pages = [currPage]; pages = [];
for (var i = currPage; i <= endPage; i++) { for (var i = currPage; i <= endPage; i++) {
let pg = i; let pg = i + 1;
pages.push(pg); pages.push(pg);
} }
@ -799,13 +798,11 @@ class DefaultViewManager {
this.layout = layout; this.layout = layout;
this.updateLayout(); this.updateLayout();
this.mapping = new Mapping(this.layout.props, this.settings.direction);
// this.manager.layout(this.layout.format); // this.manager.layout(this.layout.format);
} }
updateLayout() { updateLayout() {
if (!this.stage) { if (!this.stage) {
return; return;
} }
@ -839,6 +836,8 @@ class DefaultViewManager {
this.viewSettings.layout = layout; this.viewSettings.layout = layout;
this.mapping = new Mapping(layout.props, this.settings.direction, this.settings.axis);
if(this.views) { if(this.views) {
this.views.forEach(function(view){ this.views.forEach(function(view){
@ -851,28 +850,33 @@ class DefaultViewManager {
} }
updateAxis(axis){ updateAxis(axis, preventUpdate){
this.settings.axis = axis; this.settings.axis = axis;
this.stage && this.stage.axis(axis); this.stage && this.stage.axis(axis);
this.viewSettings.axis = axis; this.viewSettings.axis = axis;
if (axis === "vertical") {
this.layout.spread("none");
}
if (!preventUpdate) {
this.updateLayout();
}
} }
updateFlow(flow){ updateFlow(flow){
// var axis = (flow === "paginated") ? "horizontal" : "vertical";
let isPaginated = (flow === "paginated" || flow === "auto"); let isPaginated = (flow === "paginated" || flow === "auto");
this.isPaginated = isPaginated; this.isPaginated = isPaginated;
if (isPaginated) { if (flow === "scrolled-doc" ||
// this.updateAxis("horizontal"); flow === "scrolled-continuous" ||
} else { flow === "scrolled") {
// this.updateAxis("vertical"); this.updateAxis("vertical", true);
} }
// this.stage && this.stage.axis(flow);
this.viewSettings.flow = flow; this.viewSettings.flow = flow;
if (!this.settings.overflow) { if (!this.settings.overflow) {

View file

@ -1,9 +1,9 @@
import EpubCFI from "./epubcfi"; import EpubCFI from "./epubcfi";
class Mapping { class Mapping {
constructor(layout, direction, dev) { constructor(layout, direction, axis, dev) {
this.layout = layout; this.layout = layout;
this.horizontal = (this.layout.flow === "paginated") ? true : false; this.horizontal = (axis === "horizontal") ? true : false;
this.direction = direction || "ltr"; this.direction = direction || "ltr";
this._dev = dev; this._dev = dev;
} }

View file

@ -526,9 +526,8 @@ class Rendition {
} }
/** /**
* Adjust the flow of the rendition to paginated or scrolled * Adjust the direction of the rendition
* (scrolled-continuous vs scrolled-doc are handled by different view managers) * @param {string} dir
* @param {string} flow
*/ */
direction(dir){ direction(dir){