mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Fix rendering compensation events
This commit is contained in:
parent
b486232685
commit
4c5a8c7f12
6 changed files with 1621 additions and 2118 deletions
|
@ -9,8 +9,8 @@ EPUBJS.View = function(section) {
|
|||
this.element.classList.add("epub-view");
|
||||
this.element.style.display = "inline-block";
|
||||
// this.element.style.minHeight = "100px";
|
||||
this.element.style.height = 0;
|
||||
this.element.style.width = 0;
|
||||
this.element.style.height = "0px";
|
||||
this.element.style.width = "0px";
|
||||
this.element.style.overflow = "hidden";
|
||||
|
||||
|
||||
|
@ -18,6 +18,10 @@ EPUBJS.View = function(section) {
|
|||
this.rendered = false;
|
||||
|
||||
this.observe = false;
|
||||
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.View.prototype.create = function(width, height) {
|
||||
|
@ -35,28 +39,36 @@ EPUBJS.View.prototype.create = function(width, height) {
|
|||
|
||||
this.resizing = true;
|
||||
|
||||
if(width || height){
|
||||
this.resize(width, height);
|
||||
}
|
||||
|
||||
|
||||
// this.iframe.style.display = "none";
|
||||
// this.iframe.style.visibility = "hidden";
|
||||
this.iframe.style.visibility = "hidden";
|
||||
|
||||
this.element.appendChild(this.iframe);
|
||||
this.rendered = true;
|
||||
|
||||
|
||||
if(width || height){
|
||||
this.resize(width, height);
|
||||
}
|
||||
|
||||
if(this.width && this.height){
|
||||
this.resize(this.width, this.height);
|
||||
}
|
||||
|
||||
return this.iframe;
|
||||
};
|
||||
|
||||
// TODO: minimize resizes
|
||||
EPUBJS.View.prototype.resize = function(width, height) {
|
||||
|
||||
var borders = this.borders();
|
||||
|
||||
if(width){
|
||||
|
||||
if(this.iframe) {
|
||||
this.iframe.style.width = width + "px";
|
||||
}
|
||||
if(this.shown) {
|
||||
this.element.style.width = height + "px";
|
||||
this.element.style.width = width + borders.width + "px";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +77,7 @@ EPUBJS.View.prototype.resize = function(width, height) {
|
|||
this.iframe.style.height = height + "px";
|
||||
}
|
||||
if(this.shown) {
|
||||
this.element.style.height = height + "px";
|
||||
this.element.style.height = height + borders.height + "px";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,8 +103,6 @@ EPUBJS.View.prototype.resized = function(e) {
|
|||
};
|
||||
|
||||
EPUBJS.View.prototype.display = function(_request) {
|
||||
this.shown = true;
|
||||
|
||||
return this.section.render(_request)
|
||||
.then(function(contents){
|
||||
return this.load(contents);
|
||||
|
@ -185,13 +195,18 @@ EPUBJS.View.prototype.expand = function(_defer, _count, _func) {
|
|||
|
||||
return expanded;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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)) {
|
||||
// this.iframe.style.height = height + "px";
|
||||
// this.iframe.style.width = width + "px";
|
||||
this.resize(width, height);
|
||||
|
||||
setTimeout(function(){
|
||||
count += 1;
|
||||
if(_func){
|
||||
|
@ -207,10 +222,7 @@ EPUBJS.View.prototype.expand = function(_defer, _count, _func) {
|
|||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
// this.iframe.style.height = height + "px";
|
||||
// this.iframe.style.width = width + "px";
|
||||
this.resize(width, height);
|
||||
|
||||
// expanding.resolve();
|
||||
return expanded;
|
||||
};
|
||||
|
||||
|
@ -247,25 +259,18 @@ 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;
|
||||
var borders = this.borders();
|
||||
|
||||
this.element.style.width = this.width + "px";
|
||||
this.element.style.height = this.height + "px";
|
||||
|
||||
|
||||
this.element.style.width = this.width + borders.width + "px";
|
||||
this.element.style.height = this.height + borders.height + "px";
|
||||
// this.iframe.style.display = "inline-block";
|
||||
// this.iframe.style.visibility = "visible";
|
||||
this.iframe.style.visibility = "visible";
|
||||
|
||||
this.shown = true;
|
||||
|
||||
this.onShown(this);
|
||||
this.trigger("shown", this);
|
||||
|
||||
this.shown = true;
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.View.prototype.hide = function() {
|
||||
|
@ -282,6 +287,37 @@ EPUBJS.View.prototype.onShown = function(view) {
|
|||
// Stub, override with a custom functions
|
||||
};
|
||||
|
||||
EPUBJS.View.prototype.borders = function() {
|
||||
|
||||
if(this.iframe && !this.iframeStyle) {
|
||||
this.iframeStyle = window.getComputedStyle(this.iframe);
|
||||
|
||||
this.paddingTopBottom = parseInt(this.iframeStyle.paddingTop) + parseInt(this.iframeStyle.paddingBottom) || 0;
|
||||
this.paddingLeftRight = parseInt(this.iframeStyle.paddingLeft) + parseInt(this.iframeStyle.paddingRight) || 0;
|
||||
this.marginTopBottom = parseInt(this.iframeStyle.marginTop) + parseInt(this.iframeStyle.marginBottom) || 0;
|
||||
this.marginLeftRight = parseInt(this.iframeStyle.marginLeft) + parseInt(this.iframeStyle.marginRight) || 0;
|
||||
this.borderTopBottom = parseInt(this.iframeStyle.borderTop) + parseInt(this.iframeStyle.borderBottom) || 0;
|
||||
this.borderLeftRight = parseInt(this.iframeStyle.borderLeft) + parseInt(this.iframeStyle.borderRight) || 0;
|
||||
}
|
||||
|
||||
if(this.element && !this.elementStyle) {
|
||||
|
||||
this.elementStyle = window.getComputedStyle(this.element);
|
||||
|
||||
this.elpaddingTopBottom = parseInt(this.elementStyle.paddingTop) + parseInt(this.elementStyle.paddingBottom) || 0;
|
||||
this.elpaddingLeftRight = parseInt(this.elementStyle.paddingLeft) + parseInt(this.elementStyle.paddingRight) || 0;
|
||||
this.elmarginTopBottom = parseInt(this.elementStyle.marginTop) + parseInt(this.elementStyle.marginBottom) || 0;
|
||||
this.elmarginLeftRight = parseInt(this.elementStyle.marginLeft) + parseInt(this.elementStyle.marginRight) || 0;
|
||||
this.elborderTopBottom = parseInt(this.elementStyle.borderTop) + parseInt(this.elementStyle.borderBottom) || 0;
|
||||
this.elborderLeftRight = parseInt(this.elementStyle.borderLeft) + parseInt(this.elementStyle.borderRight) || 0;
|
||||
}
|
||||
|
||||
return {
|
||||
height: this.paddingTopBottom + this.marginTopBottom + this.borderTopBottom,
|
||||
width: this.paddingLeftRight + this.marginLeftRight + this.borderLeftRight
|
||||
}
|
||||
};
|
||||
|
||||
EPUBJS.View.prototype.bounds = function() {
|
||||
// var bounds = this.element.getBoundingClientRect();
|
||||
// var bounds = {
|
||||
|
@ -289,8 +325,8 @@ EPUBJS.View.prototype.bounds = function() {
|
|||
// height: this.element.offsetHeight
|
||||
// };
|
||||
return {
|
||||
height: this.height + this.paddingTopBottom + this.marginTopBottom + this.borderTopBottom,
|
||||
width: this.width + this.paddingLeftRight + this.marginLeftRight + this.borderLeftRight
|
||||
height: this.height + this.paddingTopBottom + this.marginTopBottom + this.borderTopBottom + this.elpaddingTopBottom + this.elmarginTopBottom + this.elborderTopBottom,
|
||||
width: this.width + this.paddingLeftRight + this.marginLeftRight + this.borderLeftRight + this.elpaddingLeftRight + this.elmarginLeftRight + this.elborderLeftRight
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -303,8 +339,9 @@ EPUBJS.View.prototype.destroy = function() {
|
|||
this.shown = false;
|
||||
this.iframe = null;
|
||||
}
|
||||
// this.element.style.height = 0;
|
||||
// this.element.style.width = 0;
|
||||
|
||||
// this.element.style.height = "0px";
|
||||
// this.element.style.width = "0px";
|
||||
};
|
||||
|
||||
RSVP.EventTarget.mixin(EPUBJS.View.prototype);
|
Loading…
Add table
Add a link
Reference in a new issue