1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

New continuos render

This commit is contained in:
fchasen 2014-11-10 09:16:32 -05:00
parent 0013cf417d
commit 03aef89037
13 changed files with 2027 additions and 120 deletions

View file

@ -1,12 +1,20 @@
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.displaying = new RSVP.defer();
this.displayed = this.displaying.promise;
this.section = section;
this.index = section.index;
this.element = document.createElement('div');
this.element.classList.add("epub-view");
this.element.style.display = "inline-block";
this.element.minHeight = "100px";
this.shown = false;
};
EPUBJS.View.prototype.create = function(width, height) {
this.iframe = document.createElement('iframe');
this.iframe.id = this.id;
this.iframe.scrolling = "no";
@ -16,32 +24,38 @@ EPUBJS.View.prototype.create = function(width, height) {
this.resizing = true;
if(width){
this.iframe.style.width = width + "px";
}
if(height){
this.iframe.style.height = height + "px";
if(width || height){
this.resize(width, height);
}
this.iframe.style.display = "none";
this.iframe.style.visibility = "hidden";
this.element.appendChild(this.iframe);
return this.iframe;
};
EPUBJS.View.prototype.resize = function(width, height) {
if(width){
this.iframe.style.width = width + "px";
if(this.iframe) {
this.iframe.style.width = width + "px";
}
this.element.style.minWidth = width + "px";
}
if(height){
this.iframe.style.height = height + "px";
if(this.iframe) {
this.iframe.style.height = height + "px";
}
this.element.style.minHeight = height + "px";
}
if (!this.resizing) {
this.resizing = true;
this.expand();
if(this.iframe) {
this.expand();
}
}
};
@ -49,7 +63,6 @@ EPUBJS.View.prototype.resize = function(width, height) {
EPUBJS.View.prototype.resized = function(e) {
if (!this.resizing) {
console.log("resize");
this.expand();
} else {
this.resizing = false;
@ -57,15 +70,18 @@ EPUBJS.View.prototype.resized = function(e) {
};
EPUBJS.View.prototype.render = function(_request) {
EPUBJS.View.prototype.display = function(_request) {
this.shown = true;
return this.section.render(_request)
.then(function(contents){
return this.load(contents);
}.bind(this))
.then(this.display.bind(this))
.then(this.afterLoad.bind(this))
.then(this.displaying.resolve.call())
.then(function(){
this.rendering.resolve(this);
}.bind(this));
this.onDisplayed(this);
}.bind(this)); // TEMP... TODO: proper callback
};
EPUBJS.View.prototype.load = function(contents) {
@ -97,10 +113,9 @@ EPUBJS.View.prototype.load = function(contents) {
return loaded;
};
EPUBJS.View.prototype.display = function(contents) {
var displaying = new RSVP.defer();
var displayed = displaying.promise;
EPUBJS.View.prototype.afterLoad = function() {
// this.iframe.style.display = "block";
this.iframe.style.display = "inline-block";
@ -109,27 +124,22 @@ EPUBJS.View.prototype.display = function(contents) {
this.document.body.style.margin = "0";
this.document.body.style.display = "inline-block";
this.document.documentElement.style.width = "auto";
setTimeout(function(){
this.window.addEventListener("resize", this.resized.bind(this), false);
}.bind(this), 10); // Wait to listen for resize events
// Wait for fonts to load to finish
if(this.document.fonts.status === "loading") {
this.document.fonts.onloading = function(){
this.expand();
}.bind(this);
}
// if(!this.document.fonts || this.document.fonts.status !== "loading") {
// this.expand();
// displaying.resolve(this);
// } else {
// this.document.fonts.onloading = function(){
// this.expand();
// displaying.resolve(this);
// }.bind(this);
// }
displaying.resolve(this);
// this.observer = this.observe(this.document.body);
return displayed;
if(this.observe) {
this.observer = this.observe(this.document.body);
}
};
@ -138,9 +148,11 @@ EPUBJS.View.prototype.expand = function(_defer, _count) {
var width, height;
var expanding = _defer || new RSVP.defer();
var expanded = expanding.promise;
var fontsLoading = false;
// Stop checking for equal height after 10 tries
var MAX = 10;
var TIMEOUT = 10;
var count = _count || 0;
// Flag Changes
@ -160,7 +172,7 @@ EPUBJS.View.prototype.expand = function(_defer, _count) {
setTimeout(function(){
this.expand(expanding, count);
}.bind(this), 10);
}.bind(this), TIMEOUT);
} else {
expanding.resolve();
@ -169,9 +181,10 @@ EPUBJS.View.prototype.expand = function(_defer, _count) {
this.width = width;
this.height = height;
this.iframe.style.height = height + "px";
this.iframe.style.width = width + "px";
// this.iframe.style.height = height + "px";
// this.iframe.style.width = width + "px";
this.resize(width, height);
return expanded;
};
@ -195,15 +208,15 @@ EPUBJS.View.prototype.observe = function(target) {
return observer;
};
EPUBJS.View.prototype.appendTo = function(element) {
this.element = element;
this.element.appendChild(this.iframe);
};
EPUBJS.View.prototype.prependTo = function(element) {
this.element = element;
element.insertBefore(this.iframe, element.firstChild);
};
// EPUBJS.View.prototype.appendTo = function(element) {
// this.element = element;
// this.element.appendChild(this.iframe);
// };
//
// EPUBJS.View.prototype.prependTo = function(element) {
// this.element = element;
// element.insertBefore(this.iframe, element.firstChild);
// };
EPUBJS.View.prototype.show = function() {
// this.iframe.style.display = "block";
@ -217,13 +230,16 @@ EPUBJS.View.prototype.hide = function() {
};
EPUBJS.View.prototype.bounds = function() {
return this.iframe.getBoundingClientRect();
return this.element.getBoundingClientRect();
};
EPUBJS.View.prototype.destroy = function() {
// Stop observing
// this.observer.disconnect();
this.element.removeChild(this.iframe);
if(this.iframe){
this.element.removeChild(this.iframe);
this.shown = false;
this.iframe = null;
}
};