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

updated expansion rendering

This commit is contained in:
Fred Chasen 2015-02-18 13:52:08 -05:00
parent c965cb5408
commit b486232685
6 changed files with 145 additions and 78 deletions

View file

@ -12,7 +12,8 @@ EPUBJS.View = function(section) {
this.element.style.height = 0;
this.element.style.width = 0;
this.element.style.overflow = "hidden";
this.shown = false;
this.rendered = false;
@ -38,8 +39,8 @@ EPUBJS.View.prototype.create = function(width, height) {
this.resize(width, height);
}
this.iframe.style.display = "none";
this.iframe.style.visibility = "hidden";
// this.iframe.style.display = "none";
// this.iframe.style.visibility = "hidden";
this.element.appendChild(this.iframe);
this.rendered = true;
@ -47,18 +48,23 @@ EPUBJS.View.prototype.create = function(width, height) {
return this.iframe;
};
// TODO: minimize resizes
EPUBJS.View.prototype.resize = function(width, height) {
if(width){
if(this.iframe) {
this.iframe.style.width = width + "px";
this.element.style.width = width + "px";
}
if(this.shown) {
this.element.style.width = height + "px";
}
}
if(height){
if(this.iframe) {
this.iframe.style.height = height + "px";
}
if(this.shown) {
this.element.style.height = height + "px";
}
}
@ -144,7 +150,7 @@ EPUBJS.View.prototype.afterLoad = function() {
// Wait for fonts to load to finish
if(this.document.fonts.status === "loading") {
this.document.fonts.onloading = function(){
// this.expand();
this.expand();
}.bind(this);
}
@ -154,7 +160,7 @@ EPUBJS.View.prototype.afterLoad = function() {
};
EPUBJS.View.prototype.expand = function(_defer, _count) {
EPUBJS.View.prototype.expand = function(_defer, _count, _func) {
var bounds;
var width, height;
var expanding = _defer || new RSVP.defer();
@ -165,8 +171,6 @@ EPUBJS.View.prototype.expand = function(_defer, _count) {
var count = _count || 1;
var TIMEOUT = 10 * _count;
// console.log("expand", count, this.index)
// Flag Changes
this.resizing = true;
@ -185,11 +189,15 @@ EPUBJS.View.prototype.expand = function(_defer, _count) {
height = bounds.height; //this.document.documentElement.scrollHeight; //window.getComputedStyle?
width = this.document.documentElement.scrollWidth;
console.log("expand", count, this.index, height, width)
if(count <= MAX && (this.width != width || this.height != height)) {
setTimeout(function(){
count += 1;
this.expand(expanding, count);
if(_func){
_func(this);
}
this.expand(expanding, count, _func);
}.bind(this), TIMEOUT);
} else {
@ -238,12 +246,22 @@ EPUBJS.View.prototype.observe = function(target) {
EPUBJS.View.prototype.show = function() {
// this.iframe.style.display = "block";
this.style = window.getComputedStyle(this.element);
this.paddingTopBottom = parseInt(this.style.paddingTop) + parseInt(this.style.paddingBottom) || 0;
this.paddingLeftRight = parseInt(this.style.paddingLeft) + parseInt(this.style.paddingRight) || 0;
this.marginTopBottom = parseInt(this.style.marginTop) + parseInt(this.style.marginBottom) || 0;
this.marginLeftRight = parseInt(this.style.marginLeft) + parseInt(this.style.marginRight) || 0;
this.borderTopBottom = parseInt(this.style.borderTop) + parseInt(this.style.borderBottom) || 0;
this.borderLeftRight = parseInt(this.style.borderLeft) + parseInt(this.style.borderRight) || 0;
this.element.style.width = this.width + "px";
this.element.style.height = this.height + "px";
this.iframe.style.display = "inline-block";
this.iframe.style.visibility = "visible";
// this.iframe.style.display = "inline-block";
// this.iframe.style.visibility = "visible";
this.onShown(this);
this.trigger("shown", this);
this.shown = true;
@ -251,8 +269,8 @@ EPUBJS.View.prototype.show = function() {
};
EPUBJS.View.prototype.hide = function() {
this.iframe.style.display = "none";
this.iframe.style.visibility = "hidden";
// this.iframe.style.display = "none";
// this.iframe.style.visibility = "hidden";
this.trigger("hidden");
};
@ -260,17 +278,19 @@ EPUBJS.View.prototype.position = function() {
return this.element.getBoundingClientRect();
};
EPUBJS.View.prototype.bounds = function() {
var bounds = this.element.getBoundingClientRect();
var style = window.getComputedStyle(this.element);
var marginTopBottom = parseInt(style.marginTop) + parseInt(style.marginBottom) || 0;
var marginLeftRight = parseInt(style.marginLeft) + parseInt(style.marginLeft) || 0;
var borderTopBottom = parseInt(style.borderTop) + parseInt(style.borderBottom) || 0;
var borderLeftRight = parseInt(style.borderLeft) + parseInt(style.borderRight) || 0;
EPUBJS.View.prototype.onShown = function(view) {
// Stub, override with a custom functions
};
EPUBJS.View.prototype.bounds = function() {
// var bounds = this.element.getBoundingClientRect();
// var bounds = {
// width: this.element.offsetWidth,
// height: this.element.offsetHeight
// };
return {
height: bounds.height + marginTopBottom + borderTopBottom,
width: bounds.width + marginLeftRight + borderLeftRight
height: this.height + this.paddingTopBottom + this.marginTopBottom + this.borderTopBottom,
width: this.width + this.paddingLeftRight + this.marginLeftRight + this.borderLeftRight
}
};