mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-02 14:49:16 +02:00
Updated scrolled display to work on vertical and horizontal axis
This commit is contained in:
parent
e9b074fde3
commit
4a2e9e97a9
6 changed files with 90 additions and 38 deletions
|
@ -37,16 +37,19 @@
|
||||||
<div id="viewer"></div>
|
<div id="viewer"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var currentSectionIndex = 8;
|
var params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
|
||||||
|
var url = params && params.get("url") && decodeURIComponent(params.get("url"));
|
||||||
|
var currentSectionIndex = (params && params.get("loc")) ? params.get("loc") : undefined;
|
||||||
|
|
||||||
// Load the opf
|
// Load the opf
|
||||||
var book = ePub("https://s3.amazonaws.com/epubjs/books/moby-dick/OPS/package.opf");
|
var book = ePub(url || "https://s3.amazonaws.com/epubjs/books/moby-dick/OPS/package.opf");
|
||||||
var rendition = book.renderTo("viewer", {
|
var rendition = book.renderTo("viewer", {
|
||||||
manager: "continuous",
|
manager: "continuous",
|
||||||
flow: "scrolled",
|
flow: "scrolled",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%"
|
height: "100%"
|
||||||
});
|
});
|
||||||
var displayed = rendition.display("epubcfi(/6/14[xchapter_001]!4/2/24/2[c001p0011]/1:799)");
|
var displayed = rendition.display(currentSectionIndex);
|
||||||
|
|
||||||
|
|
||||||
displayed.then(function(renderer){
|
displayed.then(function(renderer){
|
||||||
|
|
|
@ -248,6 +248,7 @@ body {
|
||||||
-webkit-transform: translate(-400px, 0);
|
-webkit-transform: translate(-400px, 0);
|
||||||
-moz-transform: translate(-400px, 0);
|
-moz-transform: translate(-400px, 0);
|
||||||
-ms-transform: translate(-400px, 0);
|
-ms-transform: translate(-400px, 0);
|
||||||
|
transform: translate(-400px, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
|
|
@ -16,15 +16,18 @@
|
||||||
<a id="next" href="#next" class="navlink">...</a>
|
<a id="next" href="#next" class="navlink">...</a>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var currentSectionIndex = 8;
|
|
||||||
// Load the opf
|
// Load the opf
|
||||||
var book = ePub("https://s3.amazonaws.com/epubjs/books/alice/OPS/package.opf");
|
var params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
|
||||||
|
var url = params && params.get("url") && decodeURIComponent(params.get("url"));
|
||||||
|
var currentSectionIndex = (params && params.get("loc")) ? params.get("loc") : undefined;
|
||||||
|
|
||||||
|
var book = ePub(url || "https://s3.amazonaws.com/epubjs/books/alice/OPS/package.opf");
|
||||||
var rendition = book.renderTo("viewer", {
|
var rendition = book.renderTo("viewer", {
|
||||||
flow: "scrolled-doc",
|
flow: "scrolled-doc",
|
||||||
width: "100%"
|
width: "100%"
|
||||||
});
|
});
|
||||||
|
|
||||||
rendition.display("chapter_008.xhtml");
|
rendition.display(currentSectionIndex);
|
||||||
|
|
||||||
|
|
||||||
var next = document.getElementById("next");
|
var next = document.getElementById("next");
|
||||||
|
|
|
@ -189,15 +189,17 @@ class Layout {
|
||||||
* @param {Contents} contents
|
* @param {Contents} contents
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
format(contents, section){
|
format(contents, section, axis){
|
||||||
var formating;
|
var formating;
|
||||||
|
|
||||||
if (this.name === "pre-paginated") {
|
if (this.name === "pre-paginated") {
|
||||||
formating = contents.fit(this.columnWidth, this.height, section);
|
formating = contents.fit(this.columnWidth, this.height, section);
|
||||||
} else if (this._flow === "paginated") {
|
} else if (this._flow === "paginated") {
|
||||||
formating = contents.columns(this.width, this.height, this.columnWidth, this.gap, this.settings.direction);
|
formating = contents.columns(this.width, this.height, this.columnWidth, this.gap, this.settings.direction);
|
||||||
} else { // scrolled
|
} else if (axis && axis === "horizontal") {
|
||||||
formating = contents.size(this.width, null);
|
formating = contents.size(null, this.height);
|
||||||
|
} else {
|
||||||
|
formating = contents.size(this.width, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formating; // might be a promise in some View Managers
|
return formating; // might be a promise in some View Managers
|
||||||
|
|
|
@ -486,6 +486,15 @@ class DefaultViewManager {
|
||||||
return err;
|
return err;
|
||||||
})
|
})
|
||||||
.then(function(){
|
.then(function(){
|
||||||
|
|
||||||
|
// Reset position to start for scrolled-doc vertical-rl in default mode
|
||||||
|
if (!this.isPaginated &&
|
||||||
|
this.settings.axis === "horizontal" &&
|
||||||
|
this.settings.direction === "rtl" &&
|
||||||
|
this.settings.rtlScrollType === "default") {
|
||||||
|
|
||||||
|
this.scrollTo(this.container.scrollWidth, 0, true);
|
||||||
|
}
|
||||||
this.views.show();
|
this.views.show();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
@ -612,11 +621,10 @@ class DefaultViewManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
currentLocation(){
|
currentLocation(){
|
||||||
|
if (this.isPaginated && this.settings.axis === "horizontal") {
|
||||||
if (this.settings.axis === "vertical") {
|
|
||||||
this.location = this.scrolledLocation();
|
|
||||||
} else {
|
|
||||||
this.location = this.paginatedLocation();
|
this.location = this.paginatedLocation();
|
||||||
|
} else {
|
||||||
|
this.location = this.scrolledLocation();
|
||||||
}
|
}
|
||||||
return this.location;
|
return this.location;
|
||||||
}
|
}
|
||||||
|
@ -625,31 +633,55 @@ class DefaultViewManager {
|
||||||
let visible = this.visible();
|
let visible = this.visible();
|
||||||
let container = this.container.getBoundingClientRect();
|
let container = this.container.getBoundingClientRect();
|
||||||
let pageHeight = (container.height < window.innerHeight) ? container.height : window.innerHeight;
|
let pageHeight = (container.height < window.innerHeight) ? container.height : window.innerHeight;
|
||||||
|
let pageWidth = (container.width < window.innerWidth) ? container.width : window.innerWidth;
|
||||||
|
let vertical = (this.settings.axis === "vertical");
|
||||||
|
let rtl = (this.settings.direction === "rtl");
|
||||||
|
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
let used = 0;
|
let used = 0;
|
||||||
|
|
||||||
if(this.settings.fullsize) {
|
if(this.settings.fullsize) {
|
||||||
offset = window.scrollY;
|
offset = vertical ? window.scrollY : window.scrollX;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sections = visible.map((view) => {
|
let sections = visible.map((view) => {
|
||||||
let {index, href} = view.section;
|
let {index, href} = view.section;
|
||||||
let position = view.position();
|
let position = view.position();
|
||||||
|
let width = view.width();
|
||||||
let height = view.height();
|
let height = view.height();
|
||||||
|
|
||||||
let startPos = offset + container.top - position.top + used;
|
let startPos;
|
||||||
let endPos = startPos + pageHeight - used;
|
let endPos;
|
||||||
if (endPos > height) {
|
let stopPos;
|
||||||
endPos = height;
|
let totalPages;
|
||||||
used = (endPos - startPos);
|
|
||||||
|
if (vertical) {
|
||||||
|
startPos = offset + container.top - position.top + used;
|
||||||
|
endPos = startPos + pageHeight - used;
|
||||||
|
totalPages = this.layout.count(height, pageHeight).pages;
|
||||||
|
stopPos = pageHeight;
|
||||||
|
// TODO: what was this doing? Seem to break things.
|
||||||
|
// if (endPos > stopPos) {
|
||||||
|
// endPos = stopPos;
|
||||||
|
// used = (endPos - startPos);
|
||||||
|
// }
|
||||||
|
} else {
|
||||||
|
startPos = offset + container.left - position.left + used;
|
||||||
|
endPos = startPos + pageWidth - used;
|
||||||
|
totalPages = this.layout.count(width, pageWidth).pages;
|
||||||
|
stopPos = pageWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
let totalPages = this.layout.count(height, pageHeight).pages;
|
let currPage = Math.ceil(startPos / stopPos);
|
||||||
|
|
||||||
let currPage = Math.ceil(startPos / pageHeight);
|
|
||||||
let pages = [];
|
let pages = [];
|
||||||
let endPage = Math.ceil(endPos / pageHeight);
|
let endPage = Math.ceil(endPos / stopPos);
|
||||||
|
|
||||||
|
// Reverse page counts for horizontal rtl
|
||||||
|
if (this.settings.direction === "rtl" && !vertical) {
|
||||||
|
let tempStartPage = currPage;
|
||||||
|
currPage = totalPages - endPage;
|
||||||
|
endPage = totalPages - tempStartPage;
|
||||||
|
}
|
||||||
|
|
||||||
pages = [];
|
pages = [];
|
||||||
for (var i = currPage; i <= endPage; i++) {
|
for (var i = currPage; i <= endPage; i++) {
|
||||||
|
@ -691,6 +723,14 @@ class DefaultViewManager {
|
||||||
// Find mapping
|
// Find mapping
|
||||||
let start = left + container.left - position + offset + used;
|
let start = left + container.left - position + offset + used;
|
||||||
let end = start + this.layout.width - used;
|
let end = start + this.layout.width - used;
|
||||||
|
if (this.settings.direction === "rtl") {
|
||||||
|
start = width - left - container.width + container.left - position + offset + used;
|
||||||
|
end = start + this.layout.width - used;
|
||||||
|
} else {
|
||||||
|
start = left + container.left - position + offset + used;
|
||||||
|
end = start + this.layout.width - used;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let mapping = this.mapping.page(view.contents, view.section.cfiBase, start, end);
|
let mapping = this.mapping.page(view.contents, view.section.cfiBase, start, end);
|
||||||
|
|
||||||
|
@ -698,7 +738,7 @@ class DefaultViewManager {
|
||||||
let startPage = Math.floor(start / this.layout.pageWidth);
|
let startPage = Math.floor(start / this.layout.pageWidth);
|
||||||
let pages = [];
|
let pages = [];
|
||||||
let endPage = Math.floor(end / this.layout.pageWidth);
|
let endPage = Math.floor(end / this.layout.pageWidth);
|
||||||
|
|
||||||
// start page should not be negative
|
// start page should not be negative
|
||||||
if (startPage < 0) {
|
if (startPage < 0) {
|
||||||
startPage = 0;
|
startPage = 0;
|
||||||
|
@ -908,7 +948,7 @@ class DefaultViewManager {
|
||||||
updateAxis(axis, forceUpdate){
|
updateAxis(axis, forceUpdate){
|
||||||
|
|
||||||
if (!this.isPaginated) {
|
if (!this.isPaginated) {
|
||||||
axis = "vertical";
|
// axis = "vertical";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!forceUpdate && axis === this.settings.axis) {
|
if (!forceUpdate && axis === this.settings.axis) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ class IframeView {
|
||||||
constructor(section, options) {
|
constructor(section, options) {
|
||||||
this.settings = extend({
|
this.settings = extend({
|
||||||
ignoreClass : "",
|
ignoreClass : "",
|
||||||
axis: options.layout && options.layout.props.flow === "scrolled" ? "vertical" : "horizontal",
|
axis: undefined, //options.layout && options.layout.props.flow === "scrolled" ? "vertical" : "horizontal",
|
||||||
direction: undefined,
|
direction: undefined,
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
|
@ -148,24 +148,32 @@ class IframeView {
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
.then(function(){
|
.then(function(){
|
||||||
|
|
||||||
// apply the layout function to the contents
|
|
||||||
this.layout.format(this.contents, this.section);
|
|
||||||
|
|
||||||
// find and report the writingMode axis
|
// find and report the writingMode axis
|
||||||
let writingMode = this.contents.writingMode();
|
let writingMode = this.contents.writingMode();
|
||||||
let axis = (writingMode.indexOf("vertical") === 0) ? "vertical" : "horizontal";
|
|
||||||
|
|
||||||
|
// Set the axis based on the flow and writing mode
|
||||||
|
let axis;
|
||||||
|
if (this.settings.flow === "scrolled") {
|
||||||
|
axis = (writingMode.indexOf("vertical") === 0) ? "horizontal" : "vertical";
|
||||||
|
} else {
|
||||||
|
axis = (writingMode.indexOf("vertical") === 0) ? "vertical" : "horizontal";
|
||||||
|
}
|
||||||
|
|
||||||
|
// this.element.style.writingMode = writingMode;
|
||||||
this.setAxis(axis);
|
this.setAxis(axis);
|
||||||
this.emit(EVENTS.VIEWS.AXIS, axis);
|
this.emit(EVENTS.VIEWS.AXIS, axis);
|
||||||
|
|
||||||
|
|
||||||
|
// apply the layout function to the contents
|
||||||
|
this.layout.format(this.contents, this.section, this.axis);
|
||||||
|
|
||||||
// Listen for events that require an expansion of the iframe
|
// Listen for events that require an expansion of the iframe
|
||||||
this.addListeners();
|
this.addListeners();
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Expand the iframe to the full size of the content
|
// Expand the iframe to the full size of the content
|
||||||
this.expand();
|
this.expand();
|
||||||
//
|
|
||||||
if (this.settings.forceRight) {
|
if (this.settings.forceRight) {
|
||||||
this.element.style.marginLeft = this.width() + "px";
|
this.element.style.marginLeft = this.width() + "px";
|
||||||
}
|
}
|
||||||
|
@ -207,7 +215,7 @@ class IframeView {
|
||||||
this.lock("both", width, height);
|
this.lock("both", width, height);
|
||||||
} else if(this.settings.axis === "horizontal") {
|
} else if(this.settings.axis === "horizontal") {
|
||||||
this.lock("height", width, height);
|
this.lock("height", width, height);
|
||||||
} else {
|
} else {
|
||||||
this.lock("width", width, height);
|
this.lock("width", width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,11 +461,6 @@ class IframeView {
|
||||||
|
|
||||||
setAxis(axis) {
|
setAxis(axis) {
|
||||||
|
|
||||||
// Force vertical for scrolled
|
|
||||||
if (this.layout.props.flow === "scrolled") {
|
|
||||||
axis = "vertical";
|
|
||||||
}
|
|
||||||
|
|
||||||
this.settings.axis = axis;
|
this.settings.axis = axis;
|
||||||
|
|
||||||
if(axis == "horizontal"){
|
if(axis == "horizontal"){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue