1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-05 15:32:55 +02:00

Updated rendering states

This commit is contained in:
Fred Chasen 2014-09-15 14:03:33 -04:00
parent 951d6ff3e2
commit 251ac3cdc4
5 changed files with 198 additions and 2052 deletions

2126
dist/epub.js vendored

File diff suppressed because it is too large Load diff

5
dist/epub.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -10,6 +10,7 @@ EPUBJS.Infinite = function(container, axis){
this.axis = axis;
// this.renderer = renderer;
this.prevScrollTop = 0;
};
EPUBJS.Infinite.prototype.start = function() {
@ -38,7 +39,6 @@ EPUBJS.Infinite.prototype.start = function() {
EPUBJS.Infinite.prototype.forwards = function() {
this.trigger("forwards");
};
EPUBJS.Infinite.prototype.backwards = function() {
@ -56,6 +56,11 @@ EPUBJS.Infinite.prototype.check = function(){
this.checkLeft();
}
this.trigger("scroll", {
top: this.container.scrollTop,
left: this.container.scrollLeft
});
this.scrolled = false;
} else {
this.displaying = false;
@ -63,6 +68,7 @@ EPUBJS.Infinite.prototype.check = function(){
}
this.tick.call(window, this.check.bind(this));
// setTimeout(this.check.bind(this), 100);
}
EPUBJS.Infinite.prototype.checkTop = function(){

View file

@ -7,6 +7,8 @@ EPUBJS.Renderer = function(book, _options) {
viewsLimit: options.viewsLimit || 5,
width: typeof(options.width) === "undefined" ? false : options.width,
height: typeof(options.height) === "undefined" ? false : options.height,
overflow: typeof(options.overflow) === "undefined" ? "auto" : options.overflow,
padding: options.padding || ""
};
this.book = book;
@ -27,6 +29,9 @@ EPUBJS.Renderer = function(book, _options) {
});
this.rendering = false;
this.filling = false;
this.displaying = false;
this.views = [];
this.positions = [];
@ -64,6 +69,7 @@ EPUBJS.Renderer.prototype.initialize = function(_options){
if(this.settings.infinite) {
this.infinite = new EPUBJS.Infinite(this.container, this.settings.axis);
this.infinite.on("scroll", this.checkCurrent.bind(this));
}
if(this.settings.axis === "horizontal") {
@ -74,7 +80,7 @@ EPUBJS.Renderer.prototype.initialize = function(_options){
this.container.style.width = width;
this.container.style.height = height;
this.container.style.overflow = "scroll";
this.container.style.overflow = this.settings.overflow;
if(options.hidden) {
this.wrapper = document.createElement("div");
@ -147,7 +153,8 @@ EPUBJS.Renderer.prototype.attachTo = function(_element){
this.infinite.on("forwards", function(){
var next = this.last().section.index + 1;
if(!this.rendering && next < this.book.spine.length){
if(!this.rendering && !this.filling && !this.displaying
&& next < this.book.spine.length){
this.forwards();
}
@ -156,7 +163,8 @@ EPUBJS.Renderer.prototype.attachTo = function(_element){
this.infinite.on("backwards", function(){
var prev = this.first().section.index - 1;
if(!this.rendering && prev > 0){
if(!this.rendering && !this.filling && !this.displaying
&& prev > 0){
this.backwards();
}
@ -166,6 +174,7 @@ EPUBJS.Renderer.prototype.attachTo = function(_element){
window.addEventListener("resize", this.onResized.bind(this), false);
this.hooks.replacements.register(this.replacements.bind(this));
this.hooks.display.register(this.afterDisplay.bind(this));
};
@ -181,23 +190,31 @@ EPUBJS.Renderer.prototype.display = function(what){
var displaying = new RSVP.defer();
var displayed = displaying.promise;
// TODO: check for fragments
// Clear views
this.clear();
// TODO: check for fragments
this.book.opened.then(function(){
var section = this.book.spine.get(what);
var rendered;
this.displaying = true;
if(section){
// Clear views
this.clear();
rendered = this.render(section);
if(this.settings.infinite) {
rendered.then(this.fill.bind(this))
rendered.then(function(){
return this.fill.call(this);
}.bind(this));
}
rendered.then(function(){
this.trigger("displayed", section);
this.displaying = false;
displaying.resolve(this);
}.bind(this));
@ -213,6 +230,7 @@ EPUBJS.Renderer.prototype.display = function(what){
EPUBJS.Renderer.prototype.render = function(section){
var rendered;
var view;
var bounds = this.container.getBoundingClientRect();
if(!section) {
rendered = new RSVP.defer();
@ -221,7 +239,14 @@ EPUBJS.Renderer.prototype.render = function(section){
};
view = new EPUBJS.View(section);
if(this.settings.axis === "vertical") {
view.create(bounds.width, 0);
} else {
view.create(0, bounds.height);
}
// Place view in correct position
this.insert(view, section.index);
@ -238,8 +263,9 @@ EPUBJS.Renderer.prototype.render = function(section){
return view.expand();
}.bind(this))
.then(function(){
this.rendering = false;
// this.rendering = false;
view.show();
this.trigger("rendered", view.section);
return view;
}.bind(this))
.catch(function(e){
@ -288,6 +314,8 @@ EPUBJS.Renderer.prototype.forwards = function(){
}
}
this.rendering = false;
}.bind(this));
@ -299,7 +327,6 @@ EPUBJS.Renderer.prototype.backwards = function(view){
var rendered;
var section;
prev = this.first().section.index - 1;
if(this.rendering || prev < 0){
@ -307,7 +334,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;
@ -335,6 +362,9 @@ EPUBJS.Renderer.prototype.backwards = function(view){
last = this.last();
this.remove(last);
}
this.rendering = false;
}.bind(this));
return rendered;
@ -349,6 +379,8 @@ EPUBJS.Renderer.prototype.fill = function() {
var prev = this.first().section.index - 1;
var filling = this.forwards();
this.filling = true;
if(this.settings.axis === "vertical") {
filling.then(this.fillVertical.bind(this));
} else {
@ -362,7 +394,7 @@ EPUBJS.Renderer.prototype.fill = function() {
return filling
.then(function(){
this.rendering = false;
this.filling = false;
}.bind(this));
@ -376,7 +408,7 @@ EPUBJS.Renderer.prototype.fillVertical = function() {
if (height && bottom && (bottom < height)) { //&& (this.last().section.index + 1 < this.book.spine.length)) {
return this.forwards().then(this.fillVertical.bind(this));
} else {
this.rendering = false;
// this.rendering = false;
defer.resolve();
return defer.promise;
}
@ -390,7 +422,7 @@ EPUBJS.Renderer.prototype.fillHorizontal = function() {
if (width && right && (right <= width)) { //&& (this.last().section.index + 1 < this.book.spine.length)) {
return this.forwards().then(this.fillHorizontal.bind(this));
} else {
this.rendering = false;
// this.rendering = false;
defer.resolve();
return defer.promise;
}
@ -480,6 +512,13 @@ EPUBJS.Renderer.prototype.replacements = function(view, renderer) {
return task.promise;
};
EPUBJS.Renderer.prototype.afterDisplay = function(view, renderer) {
var task = new RSVP.defer();
view.document.documentElement.style.padding = this.settings.padding;
task.resolve();
return task.promise;
};
EPUBJS.Renderer.prototype.paginate = function(options) {
this.pagination = new EPUBJS.Paginate(this, {
width: this.settings.width,
@ -488,5 +527,29 @@ EPUBJS.Renderer.prototype.paginate = function(options) {
return this.pagination;
};
EPUBJS.Renderer.prototype.checkCurrent = function(position) {
var view, top;
var container = this.container.getBoundingClientRect();
if(this.settings.axis === "horizontal") {
} else {
for (var i = this.views.length - 1; i >= 0; i--) {
view = this.views[i];
top = view.bounds().top;
if(top < container.bottom && top > 0) {
if(this.current == view.section) break;
this.current = view.section;
this.trigger("current", this.current)
break;
}
};
}
};
//-- Enable binding events to Renderer
RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);

View file

@ -2,11 +2,11 @@ EPUBJS.View = function(section) {
this.id = "epubjs-view:" + EPUBJS.core.uuid();
this.rendering = new RSVP.defer();
this.rendered = this.rendering.promise;
this.iframe = this.create();
// this.iframe = this.create();
this.section = section;
};
EPUBJS.View.prototype.create = function() {
EPUBJS.View.prototype.create = function(width, height) {
this.iframe = document.createElement('iframe');
this.iframe.id = this.id;
this.iframe.scrolling = "no";
@ -15,8 +15,14 @@ EPUBJS.View.prototype.create = function() {
this.iframe.style.border = "none";
this.resizing = true;
// this.iframe.style.width = "100%";
// this.iframe.style.height = "100%";
if(width){
this.iframe.style.width = width + "px";
}
if(height){
this.iframe.style.height = height + "px";
}
this.iframe.style.display = "none";
this.iframe.style.visibility = "hidden";
@ -50,6 +56,11 @@ EPUBJS.View.prototype.load = function(contents) {
this.document = this.iframe.contentDocument;
if(!this.document) {
loading.reject(new Error("No Document Available"));
return loaded;
}
this.iframe.addEventListener("load", function(event) {
this.window = this.iframe.contentWindow;
@ -121,9 +132,6 @@ EPUBJS.View.prototype.expand = function() {
width = this.document.documentElement.scrollWidth;
this.iframe.style.width = width + "px";
// this.width = width;
// this.height = height;