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

small fixes

This commit is contained in:
Fred Chasen 2014-10-06 17:44:04 -04:00
parent cf603fcca8
commit 105a3a36d6
7 changed files with 150 additions and 64 deletions

View file

@ -211,12 +211,13 @@ EPUBJS.Renderer.prototype.display = function(what){
var displayed = displaying.promise;
// TODO: check for fragments
var split = what.split("#");
var href = split[0];
// Check for fragments
if(typeof what === 'string') {
what = what.split("#")[0];
}
this.book.opened.then(function(){
var section = this.book.spine.get(href);
var section = this.book.spine.get(what);
var rendered;
this.displaying = true;
@ -318,7 +319,7 @@ EPUBJS.Renderer.prototype.forwards = function(){
rendered.reject(new Error("Reject Forwards"));
return rendered.promise;
}
// console.log("going forwards")
console.log("going forwards")
this.rendering = true;
@ -327,23 +328,31 @@ EPUBJS.Renderer.prototype.forwards = function(){
rendered.then(function(){
var first = this.first();
var bounds = first.bounds();
var firstBounds = first.bounds();
var lastBounds = this.last().bounds();
var prevTop = this.container.scrollTop;
var prevLeft = this.container.scrollLeft;
if(this.views.length > this.settings.viewsLimit) {
// Remove the item
this.remove(first);
if(this.settings.infinite) {
// Reset Position
if(this.settings.axis === "vertical") {
this.infinite.scroll(0, prevTop - bounds.height, true)
} else {
this.infinite.scroll(prevLeft - bounds.width, true);
// Temp fix for loop
if(this.container.scrollTop - firstBounds.height > 100) {
// Remove the item
this.remove(first);
if(this.settings.infinite) {
// Reset Position
if(this.settings.axis === "vertical") {
this.infinite.scroll(0, prevTop - firstBounds.height, true);
} else {
this.infinite.scroll(prevLeft - firstBounds.width, true);
}
}
}
}
}
this.rendering = false;
@ -366,7 +375,7 @@ EPUBJS.Renderer.prototype.backwards = function(view){
rendered.reject(new Error("Reject Backwards"));
return rendered.promise;
}
// console.log("going backwards")
console.log("going backwards")
this.rendering = true;
@ -389,10 +398,14 @@ EPUBJS.Renderer.prototype.backwards = function(view){
if(this.views.length > this.settings.viewsLimit) {
last = this.last();
this.remove(last);
if(this.container.scrollTop - this.first().bounds().height > 100) {
// Remove the item
this.remove(last);
}
}
this.rendering = false;
@ -513,6 +526,7 @@ EPUBJS.Renderer.prototype.replacements = function(view, renderer) {
var href = link.getAttribute("href");
var uri = new EPUBJS.core.uri(href);
if(uri.protocol){
link.setAttribute("target", "_blank");
@ -526,12 +540,17 @@ EPUBJS.Renderer.prototype.replacements = function(view, renderer) {
// return false;
// };
// } else {
//}
if(href.indexOf("#") === 0) {
// do nothing with fragment yet
} else {
link.onclick = function(){
renderer.display(href);
return false;
};
//}
}
}
};
@ -562,17 +581,24 @@ EPUBJS.Renderer.prototype.paginate = function(options) {
EPUBJS.Renderer.prototype.checkCurrent = function(position) {
var view, top;
var container = this.container.getBoundingClientRect();
var length = this.views.length - 1;
if(this.rendering) {
return;
}
if(this.settings.axis === "horizontal") {
// TODO: Check for current horizontal
} else {
for (var i = this.views.length - 1; i >= 0; i--) {
for (var i = length; i >= 0; i--) {
view = this.views[i];
top = view.bounds().top;
if(top < container.bottom && top > 0) {
if(top < container.bottom) {
if(this.current == view.section) break;
if(this.current == view.section) {
break;
}
this.current = view.section;
this.trigger("current", this.current)
@ -583,5 +609,9 @@ EPUBJS.Renderer.prototype.checkCurrent = function(position) {
}
};
EPUBJS.Renderer.prototype.bounds = function() {
return this.container.getBoundingClientRect();
};
//-- Enable binding events to Renderer
RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);