mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Single render handles spreads
This commit is contained in:
parent
0889e63a29
commit
89387f1ef2
9 changed files with 231 additions and 45 deletions
111
dist/epub.js
vendored
111
dist/epub.js
vendored
|
@ -6366,6 +6366,7 @@ Contents.prototype.columns = function(width, height, columnWidth, gap){
|
|||
var COLUMN_GAP = core.prefixed('columnGap');
|
||||
var COLUMN_WIDTH = core.prefixed('columnWidth');
|
||||
var COLUMN_FILL = core.prefixed('columnFill');
|
||||
var textWidth;
|
||||
|
||||
this.width(width);
|
||||
this.height(height);
|
||||
|
@ -7991,6 +7992,7 @@ function Layout(settings){
|
|||
this._flow = (settings.flow === "paginated") ? "paginated" : "scrolled";
|
||||
this._spread = (settings.spread === "none") ? false : true;
|
||||
this._minSpreadWidth = settings.spread || 800;
|
||||
this._evenSpreads = settings.evenSpreads || false;
|
||||
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
|
@ -9086,11 +9088,17 @@ SingleViewManager.prototype.destroy = function(){
|
|||
};
|
||||
|
||||
SingleViewManager.prototype.onResized = function(e) {
|
||||
clearTimeout(this.resizeTimeout);
|
||||
this.resizeTimeout = setTimeout(function(){
|
||||
this.resize();
|
||||
}.bind(this), 150);
|
||||
};
|
||||
|
||||
SingleViewManager.prototype.resize = function(width, height){
|
||||
|
||||
// Clear the queue
|
||||
this.q.clear();
|
||||
|
||||
this._stageSize = this.stage.size(width, height);
|
||||
this._bounds = this.bounds();
|
||||
|
||||
|
@ -9103,9 +9111,11 @@ SingleViewManager.prototype.resize = function(width, height){
|
|||
view.size(this._stageSize.width, this._stageSize.height);
|
||||
}.bind(this));
|
||||
|
||||
this.updateLayout();
|
||||
|
||||
this.trigger("resized", {
|
||||
width: this._stageSize.width,
|
||||
height: this._stageSize.height
|
||||
width: this.stage.width,
|
||||
height: this.stage.height
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -9169,8 +9179,25 @@ SingleViewManager.prototype.afterResized = function(view){
|
|||
this.trigger("resize", view.section);
|
||||
};
|
||||
|
||||
// SingleViewManager.prototype.moveTo = function(offset){
|
||||
// this.scrollTo(offset.left, offset.top);
|
||||
// };
|
||||
|
||||
SingleViewManager.prototype.moveTo = function(offset){
|
||||
this.scrollTo(offset.left, offset.top);
|
||||
var distX = 0,
|
||||
distY = 0;
|
||||
|
||||
if(this.settings.axis === "vertical") {
|
||||
distY = offset.top;
|
||||
} else {
|
||||
distX = Math.floor(offset.left / this.layout.delta) * this.layout.delta;
|
||||
|
||||
if (distX + this.layout.delta > this.container.scrollWidth) {
|
||||
distX = this.container.scrollWidth - this.layout.delta;
|
||||
}
|
||||
}
|
||||
|
||||
this.scrollTo(distX, distY);
|
||||
};
|
||||
|
||||
SingleViewManager.prototype.add = function(view){
|
||||
|
@ -9198,10 +9225,30 @@ SingleViewManager.prototype.add = function(view){
|
|||
SingleViewManager.prototype.next = function(){
|
||||
var next;
|
||||
var view;
|
||||
var left;
|
||||
|
||||
if(!this.views.length) return;
|
||||
|
||||
if(this.settings.axis === "horizontal") {
|
||||
|
||||
this.scrollLeft = this.container.scrollLeft;
|
||||
|
||||
left = this.container.scrollLeft + this.container.offsetWidth + this.layout.delta;
|
||||
|
||||
if(left < this.container.scrollWidth) {
|
||||
this.scrollBy(this.layout.delta, 0);
|
||||
} else if (left - this.layout.columnWidth === this.container.scrollWidth) {
|
||||
this.scrollTo(this.container.scrollWidth - this.layout.delta, 0);
|
||||
} else {
|
||||
next = this.views.last().section.next();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
next = this.views.last().section.next();
|
||||
|
||||
}
|
||||
|
||||
if(next) {
|
||||
this.views.clear();
|
||||
|
@ -9212,21 +9259,45 @@ SingleViewManager.prototype.next = function(){
|
|||
this.views.show();
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
SingleViewManager.prototype.prev = function(){
|
||||
var prev;
|
||||
var view;
|
||||
var left;
|
||||
|
||||
if(!this.views.length) return;
|
||||
|
||||
if(this.settings.axis === "horizontal") {
|
||||
|
||||
this.scrollLeft = this.container.scrollLeft;
|
||||
|
||||
left = this.container.scrollLeft;
|
||||
|
||||
if(left > 0) {
|
||||
this.scrollBy(-this.layout.delta, 0);
|
||||
} else {
|
||||
prev = this.views.first().section.prev();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
prev = this.views.first().section.prev();
|
||||
|
||||
}
|
||||
|
||||
if(prev) {
|
||||
this.views.clear();
|
||||
|
||||
view = this.createView(prev);
|
||||
return this.add(view)
|
||||
.then(function(){
|
||||
if(this.settings.axis === "horizontal") {
|
||||
this.scrollTo(this.container.scrollWidth - this.layout.delta, 0);
|
||||
}
|
||||
this.views.show();
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -9250,7 +9321,7 @@ SingleViewManager.prototype.currentLocation = function(){
|
|||
start = container.left - view.position().left;
|
||||
end = start + this.layout.spread;
|
||||
|
||||
return this.mapping.page(view);
|
||||
return this.mapping.page(view, view.section.cfiBase);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -9359,15 +9430,27 @@ SingleViewManager.prototype.applyLayout = function(layout) {
|
|||
};
|
||||
|
||||
SingleViewManager.prototype.updateLayout = function() {
|
||||
var bounds;
|
||||
|
||||
if (!this.stage) {
|
||||
return;
|
||||
}
|
||||
|
||||
bounds = this.stage.size();
|
||||
this._stageSize = this.stage.size();
|
||||
|
||||
this.layout.calculate(bounds.width, bounds.height);
|
||||
if(this.settings.axis === "vertical") {
|
||||
this.layout.calculate(this._stageSize.width, this._stageSize.height);
|
||||
} else {
|
||||
this.layout.calculate(
|
||||
this._stageSize.width,
|
||||
this._stageSize.height,
|
||||
this.settings.gap
|
||||
);
|
||||
|
||||
// Set the look ahead offset for what is visible
|
||||
this.settings.offset = this.layout.delta;
|
||||
|
||||
this.stage.addStyleRules("iframe", [{"margin-right" : this.layout.gap + "px"}]);
|
||||
|
||||
}
|
||||
|
||||
this.setLayout(this.layout);
|
||||
|
||||
|
@ -10516,7 +10599,7 @@ function Rendition(book, options) {
|
|||
width: null,
|
||||
height: null,
|
||||
ignoreClass: '',
|
||||
manager: "continuous",
|
||||
manager: "single",
|
||||
view: "iframe",
|
||||
flow: null,
|
||||
layout: null,
|
||||
|
@ -12456,6 +12539,7 @@ IframeView.prototype.lock = function(what, width, height) {
|
|||
IframeView.prototype.expand = function(force) {
|
||||
var width = this.lockedWidth;
|
||||
var height = this.lockedHeight;
|
||||
var columns;
|
||||
|
||||
var textWidth, textHeight;
|
||||
|
||||
|
@ -12473,6 +12557,15 @@ IframeView.prototype.expand = function(force) {
|
|||
// Get the contentWidth by resizing the iframe
|
||||
// Check with a min reset of the textWidth
|
||||
width = this.contentWidth(textWidth);
|
||||
|
||||
columns = Math.ceil(width / (this.settings.layout.columnWidth + this.settings.layout.gap));
|
||||
|
||||
if ( this.settings.layout.divisor > 1 &&
|
||||
(columns % 2 > 0)) {
|
||||
// add a blank page
|
||||
width += this.settings.layout.gap + this.settings.layout.columnWidth;
|
||||
}
|
||||
|
||||
// Save the textWdith
|
||||
this._textWidth = textWidth;
|
||||
// Save the contentWidth
|
||||
|
|
2
dist/epub.js.map
vendored
2
dist/epub.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -63,7 +63,6 @@
|
|||
// Load the opf
|
||||
var book = ePub("https://s3.amazonaws.com/epubjs/books/alice/OPS/package.opf");
|
||||
var rendition = book.renderTo("viewer", {
|
||||
manager: "single",
|
||||
flow: "scrolled-doc",
|
||||
});
|
||||
|
||||
|
|
|
@ -92,7 +92,8 @@
|
|||
// var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf");
|
||||
var book = ePub("../books/moby-dick/OPS/package.opf");
|
||||
var rendition = book.renderTo("viewer", {
|
||||
method: "paginate",
|
||||
manager: "continuous",
|
||||
flow: "paginated",
|
||||
width: "100%",
|
||||
height: "100%"
|
||||
});
|
||||
|
|
|
@ -588,6 +588,7 @@ Contents.prototype.columns = function(width, height, columnWidth, gap){
|
|||
var COLUMN_GAP = core.prefixed('columnGap');
|
||||
var COLUMN_WIDTH = core.prefixed('columnWidth');
|
||||
var COLUMN_FILL = core.prefixed('columnFill');
|
||||
var textWidth;
|
||||
|
||||
this.width(width);
|
||||
this.height(height);
|
||||
|
|
|
@ -6,6 +6,7 @@ function Layout(settings){
|
|||
this._flow = (settings.flow === "paginated") ? "paginated" : "scrolled";
|
||||
this._spread = (settings.spread === "none") ? false : true;
|
||||
this._minSpreadWidth = settings.spread || 800;
|
||||
this._evenSpreads = settings.evenSpreads || false;
|
||||
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
|
|
|
@ -91,11 +91,17 @@ SingleViewManager.prototype.destroy = function(){
|
|||
};
|
||||
|
||||
SingleViewManager.prototype.onResized = function(e) {
|
||||
clearTimeout(this.resizeTimeout);
|
||||
this.resizeTimeout = setTimeout(function(){
|
||||
this.resize();
|
||||
}.bind(this), 150);
|
||||
};
|
||||
|
||||
SingleViewManager.prototype.resize = function(width, height){
|
||||
|
||||
// Clear the queue
|
||||
this.q.clear();
|
||||
|
||||
this._stageSize = this.stage.size(width, height);
|
||||
this._bounds = this.bounds();
|
||||
|
||||
|
@ -108,9 +114,11 @@ SingleViewManager.prototype.resize = function(width, height){
|
|||
view.size(this._stageSize.width, this._stageSize.height);
|
||||
}.bind(this));
|
||||
|
||||
this.updateLayout();
|
||||
|
||||
this.trigger("resized", {
|
||||
width: this._stageSize.width,
|
||||
height: this._stageSize.height
|
||||
width: this.stage.width,
|
||||
height: this.stage.height
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -174,8 +182,25 @@ SingleViewManager.prototype.afterResized = function(view){
|
|||
this.trigger("resize", view.section);
|
||||
};
|
||||
|
||||
// SingleViewManager.prototype.moveTo = function(offset){
|
||||
// this.scrollTo(offset.left, offset.top);
|
||||
// };
|
||||
|
||||
SingleViewManager.prototype.moveTo = function(offset){
|
||||
this.scrollTo(offset.left, offset.top);
|
||||
var distX = 0,
|
||||
distY = 0;
|
||||
|
||||
if(this.settings.axis === "vertical") {
|
||||
distY = offset.top;
|
||||
} else {
|
||||
distX = Math.floor(offset.left / this.layout.delta) * this.layout.delta;
|
||||
|
||||
if (distX + this.layout.delta > this.container.scrollWidth) {
|
||||
distX = this.container.scrollWidth - this.layout.delta;
|
||||
}
|
||||
}
|
||||
|
||||
this.scrollTo(distX, distY);
|
||||
};
|
||||
|
||||
SingleViewManager.prototype.add = function(view){
|
||||
|
@ -203,10 +228,30 @@ SingleViewManager.prototype.add = function(view){
|
|||
SingleViewManager.prototype.next = function(){
|
||||
var next;
|
||||
var view;
|
||||
var left;
|
||||
|
||||
if(!this.views.length) return;
|
||||
|
||||
if(this.settings.axis === "horizontal") {
|
||||
|
||||
this.scrollLeft = this.container.scrollLeft;
|
||||
|
||||
left = this.container.scrollLeft + this.container.offsetWidth + this.layout.delta;
|
||||
|
||||
if(left < this.container.scrollWidth) {
|
||||
this.scrollBy(this.layout.delta, 0);
|
||||
} else if (left - this.layout.columnWidth === this.container.scrollWidth) {
|
||||
this.scrollTo(this.container.scrollWidth - this.layout.delta, 0);
|
||||
} else {
|
||||
next = this.views.last().section.next();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
next = this.views.last().section.next();
|
||||
|
||||
}
|
||||
|
||||
if(next) {
|
||||
this.views.clear();
|
||||
|
@ -217,21 +262,45 @@ SingleViewManager.prototype.next = function(){
|
|||
this.views.show();
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
SingleViewManager.prototype.prev = function(){
|
||||
var prev;
|
||||
var view;
|
||||
var left;
|
||||
|
||||
if(!this.views.length) return;
|
||||
|
||||
if(this.settings.axis === "horizontal") {
|
||||
|
||||
this.scrollLeft = this.container.scrollLeft;
|
||||
|
||||
left = this.container.scrollLeft;
|
||||
|
||||
if(left > 0) {
|
||||
this.scrollBy(-this.layout.delta, 0);
|
||||
} else {
|
||||
prev = this.views.first().section.prev();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
prev = this.views.first().section.prev();
|
||||
|
||||
}
|
||||
|
||||
if(prev) {
|
||||
this.views.clear();
|
||||
|
||||
view = this.createView(prev);
|
||||
return this.add(view)
|
||||
.then(function(){
|
||||
if(this.settings.axis === "horizontal") {
|
||||
this.scrollTo(this.container.scrollWidth - this.layout.delta, 0);
|
||||
}
|
||||
this.views.show();
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -255,7 +324,7 @@ SingleViewManager.prototype.currentLocation = function(){
|
|||
start = container.left - view.position().left;
|
||||
end = start + this.layout.spread;
|
||||
|
||||
return this.mapping.page(view);
|
||||
return this.mapping.page(view, view.section.cfiBase);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -364,15 +433,27 @@ SingleViewManager.prototype.applyLayout = function(layout) {
|
|||
};
|
||||
|
||||
SingleViewManager.prototype.updateLayout = function() {
|
||||
var bounds;
|
||||
|
||||
if (!this.stage) {
|
||||
return;
|
||||
}
|
||||
|
||||
bounds = this.stage.size();
|
||||
this._stageSize = this.stage.size();
|
||||
|
||||
this.layout.calculate(bounds.width, bounds.height);
|
||||
if(this.settings.axis === "vertical") {
|
||||
this.layout.calculate(this._stageSize.width, this._stageSize.height);
|
||||
} else {
|
||||
this.layout.calculate(
|
||||
this._stageSize.width,
|
||||
this._stageSize.height,
|
||||
this.settings.gap
|
||||
);
|
||||
|
||||
// Set the look ahead offset for what is visible
|
||||
this.settings.offset = this.layout.delta;
|
||||
|
||||
this.stage.addStyleRules("iframe", [{"margin-right" : this.layout.gap + "px"}]);
|
||||
|
||||
}
|
||||
|
||||
this.setLayout(this.layout);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ function Rendition(book, options) {
|
|||
width: null,
|
||||
height: null,
|
||||
ignoreClass: '',
|
||||
manager: "continuous",
|
||||
manager: "single",
|
||||
view: "iframe",
|
||||
flow: null,
|
||||
layout: null,
|
||||
|
|
|
@ -230,6 +230,7 @@ IframeView.prototype.lock = function(what, width, height) {
|
|||
IframeView.prototype.expand = function(force) {
|
||||
var width = this.lockedWidth;
|
||||
var height = this.lockedHeight;
|
||||
var columns;
|
||||
|
||||
var textWidth, textHeight;
|
||||
|
||||
|
@ -247,6 +248,15 @@ IframeView.prototype.expand = function(force) {
|
|||
// Get the contentWidth by resizing the iframe
|
||||
// Check with a min reset of the textWidth
|
||||
width = this.contentWidth(textWidth);
|
||||
|
||||
columns = Math.ceil(width / (this.settings.layout.columnWidth + this.settings.layout.gap));
|
||||
|
||||
if ( this.settings.layout.divisor > 1 &&
|
||||
(columns % 2 > 0)) {
|
||||
// add a blank page
|
||||
width += this.settings.layout.gap + this.settings.layout.columnWidth;
|
||||
}
|
||||
|
||||
// Save the textWdith
|
||||
this._textWidth = textWidth;
|
||||
// Save the contentWidth
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue