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

Add map for sections and pages, update queue to handle function without promise

This commit is contained in:
Fred Chasen 2015-05-26 19:59:06 -04:00
parent f998e5be0a
commit 5c33f9c52b
14 changed files with 1044 additions and 93 deletions

View file

@ -88,6 +88,7 @@ EPUBJS.Paginate.prototype.start = function(){
// this.layoutMethod = this.determineLayout(this.layoutSettings);
// this.layout = new EPUBJS.Layout[this.layoutMethod]();
//this.hooks.display.register(this.registerLayoutMethod.bind(this));
this.hooks.display.register(this.reportLocation);
this.currentPage = 0;
@ -113,7 +114,9 @@ EPUBJS.Paginate.prototype.layoutMethod = function() {
);
// Set the look ahead offset for what is visible
this.settings.offset = this.layout.spread;
this.settings.offset = this.layout.delta;
this.map = new EPUBJS.Map(this.layout);
// this.hooks.layout.register(this.layout.format.bind(this));
@ -132,9 +135,10 @@ EPUBJS.Paginate.prototype.page = function(pg){
EPUBJS.Paginate.prototype.next = function(){
this.q.enqueue(function(){
this.scrollBy(this.layout.spread, 0);
return this.check();
return this.q.enqueue(function(){
this.scrollBy(this.layout.delta, 0);
this.reportLocation();
this.check();
});
// return this.page(this.currentPage + 1);
@ -142,13 +146,55 @@ EPUBJS.Paginate.prototype.next = function(){
EPUBJS.Paginate.prototype.prev = function(){
this.q.enqueue(function(){
this.scrollBy(-this.layout.spread, 0);
return this.check();
return this.q.enqueue(function(){
this.scrollBy(-this.layout.delta, 0);
this.reportLocation();
this.check();
});
// return this.page(this.currentPage - 1);
};
EPUBJS.Paginate.prototype.reportLocation = function(){
return this.q.enqueue(function(){
var location = this.currentLocation();
this.trigger("locationChanged", location);
}.bind(this));
};
EPUBJS.Paginate.prototype.currentLocation = function(){
var visible = this.visible();
var startA, startB, endA, endB;
container = this.container.getBoundingClientRect()
if(visible.length === 1) {
startA = container.left - visible[0].position().left;
endA = startA + this.layout.spread;
return this.map.page(visible[0], startA, endA);
}
if(visible.length > 1) {
// Left Col
startA = container.left - visible[0].position().left;
endA = startA + this.layout.column;
// Right Col
startB = container.left + this.layout.spread - visible[visible.length-1].position().left;
endB = startB + this.layout.column;
pageLeft = this.map.page(visible[0], startA, endA);
pageRight = this.map.page(visible[visible.length-1], startB, endB);
return {
start: pageLeft.start,
end: pageRight.end
}
}
};
// EPUBJS.Paginate.prototype.display = function(what){
// return this.display(what);
// };