mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Updated expanding, and resize
This commit is contained in:
parent
a574c68975
commit
1f7a4a2ccf
9 changed files with 362 additions and 256 deletions
|
@ -1,4 +1,4 @@
|
|||
EPUBJS.View = function(section) {
|
||||
EPUBJS.View = function(section, horz) {
|
||||
this.id = "epubjs-view:" + EPUBJS.core.uuid();
|
||||
this.displaying = new RSVP.defer();
|
||||
this.displayed = this.displaying.promise;
|
||||
|
@ -8,6 +8,7 @@ EPUBJS.View = function(section) {
|
|||
this.element = document.createElement('div');
|
||||
this.element.classList.add("epub-view");
|
||||
this.element.style.display = "inline-block";
|
||||
|
||||
// this.element.style.minHeight = "100px";
|
||||
this.element.style.height = "0px";
|
||||
this.element.style.width = "0px";
|
||||
|
@ -54,70 +55,99 @@ EPUBJS.View.prototype.create = function(width, height) {
|
|||
|
||||
this.resizing = true;
|
||||
|
||||
|
||||
|
||||
// this.iframe.style.display = "none";
|
||||
this.element.style.visibility = "hidden";
|
||||
this.iframe.style.visibility = "hidden";
|
||||
|
||||
this.element.appendChild(this.iframe);
|
||||
this.rendered = true;
|
||||
|
||||
|
||||
if(width || height){
|
||||
this.resize(width, height);
|
||||
} else if(this.width && this.height){
|
||||
this.resize(this.width, this.height);
|
||||
} else {
|
||||
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||
}
|
||||
// if(width || height){
|
||||
// this.resize(width, height);
|
||||
// } else if(this.width && this.height){
|
||||
// this.resize(this.width, this.height);
|
||||
// } else {
|
||||
// this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||
// }
|
||||
|
||||
if(!!("srcdoc" in this.iframe)) {
|
||||
this.supportsSrcdoc = true;
|
||||
} else {
|
||||
this.supportsSrcdoc = false;
|
||||
}
|
||||
|
||||
return this.iframe;
|
||||
};
|
||||
|
||||
// TODO: minimize resizes
|
||||
EPUBJS.View.prototype.resize = function(width, height) {
|
||||
|
||||
EPUBJS.View.prototype.lock = function(width, height) {
|
||||
|
||||
if(width){
|
||||
|
||||
if(this.iframe) {
|
||||
this.iframe.style.width = width + "px";
|
||||
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||
}
|
||||
if(this.shown) {
|
||||
this.element.style.width = this.iframeBounds.width + "px";
|
||||
this.elementBounds = EPUBJS.core.bounds(this.element);
|
||||
}
|
||||
var borders = EPUBJS.core.borders(this.element);
|
||||
|
||||
if(EPUBJS.core.isNumber(width)){
|
||||
this.lockedWidth = width - borders.width;
|
||||
}
|
||||
|
||||
if(height){
|
||||
if(this.iframe) {
|
||||
this.iframe.style.height = height + "px";
|
||||
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||
}
|
||||
if(this.shown) {
|
||||
this.element.style.height = this.iframeBounds.height + "px";
|
||||
this.elementBounds = EPUBJS.core.bounds(this.element);
|
||||
}
|
||||
if(EPUBJS.core.isNumber(height)){
|
||||
this.lockedHeight = height - borders.height;
|
||||
}
|
||||
|
||||
if (!this.resizing) {
|
||||
this.resizing = true;
|
||||
if(this.iframe) {
|
||||
this.expand();
|
||||
if(this.shown) {
|
||||
this.resize(this.lockedWidth, this.lockedHeight);
|
||||
|
||||
if (this.iframe && !this.resizing) {
|
||||
//this.expand();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.View.prototype.resize = function(width, height) {
|
||||
|
||||
if(!this.shown) return;
|
||||
|
||||
if(EPUBJS.core.isNumber(width)){
|
||||
this.element.style.width = width + "px";
|
||||
}
|
||||
|
||||
if(EPUBJS.core.isNumber(height)){
|
||||
this.element.style.height = height + "px";
|
||||
}
|
||||
|
||||
this.elementBounds = EPUBJS.core.bounds(this.element);
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.View.prototype.reframe = function(width, height) {
|
||||
|
||||
if(!this.iframe) return;
|
||||
|
||||
if(EPUBJS.core.isNumber(width)){
|
||||
this.iframe.style.width = width + "px";
|
||||
}
|
||||
|
||||
if(EPUBJS.core.isNumber(height)){
|
||||
this.iframe.style.height = height + "px";
|
||||
}
|
||||
|
||||
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||
this.resize(this.iframeBounds.width, this.iframeBounds.height);
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.View.prototype.resized = function(e) {
|
||||
|
||||
/*
|
||||
if (!this.resizing) {
|
||||
if(this.iframe) {
|
||||
// this.expand();
|
||||
}
|
||||
} else {
|
||||
this.resizing = false;
|
||||
}
|
||||
}*/
|
||||
|
||||
};
|
||||
|
||||
|
@ -150,11 +180,14 @@ EPUBJS.View.prototype.load = function(contents) {
|
|||
|
||||
}.bind(this));
|
||||
|
||||
|
||||
// this.iframe.srcdoc = contents;
|
||||
this.document.open();
|
||||
this.document.write(contents);
|
||||
this.document.close();
|
||||
if(this.supportsSrcdoc){
|
||||
this.iframe.srcdoc = contents;
|
||||
} else {
|
||||
this.document.open();
|
||||
this.document.write(contents);
|
||||
this.document.close();
|
||||
}
|
||||
|
||||
|
||||
return loaded;
|
||||
};
|
||||
|
@ -215,18 +248,16 @@ EPUBJS.View.prototype.expand = function(_defer, _count, _func) {
|
|||
return expanded;
|
||||
}
|
||||
|
||||
|
||||
height = bounds.height; //this.document.documentElement.scrollHeight; //window.getComputedStyle?
|
||||
height = this.lockedHeight || bounds.height; //this.document.documentElement.scrollHeight; //window.getComputedStyle?
|
||||
|
||||
width = this.document.documentElement.scrollWidth;
|
||||
width = this.lockedWidth || this.document.documentElement.scrollWidth;
|
||||
|
||||
|
||||
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);
|
||||
if(count <= MAX && (this.width != width || this.height != height) && !this.stopExpanding) {
|
||||
|
||||
this.reframe(width, height);
|
||||
|
||||
setTimeout(function(){
|
||||
this.expandTimeout = setTimeout(function(){
|
||||
count += 1;
|
||||
if(_func){
|
||||
_func(this);
|
||||
|
@ -235,13 +266,16 @@ EPUBJS.View.prototype.expand = function(_defer, _count, _func) {
|
|||
}.bind(this), TIMEOUT);
|
||||
|
||||
} else {
|
||||
this.resizing = false;
|
||||
if(this.stopExpanding){
|
||||
this.stopExpanding = null;
|
||||
}
|
||||
expanding.resolve();
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
// expanding.resolve();
|
||||
return expanded;
|
||||
};
|
||||
|
||||
|
@ -276,28 +310,27 @@ EPUBJS.View.prototype.observe = function(target) {
|
|||
// };
|
||||
|
||||
EPUBJS.View.prototype.show = function() {
|
||||
// this.iframe.style.display = "block";
|
||||
|
||||
//var borders = this.borders();
|
||||
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||
|
||||
this.element.style.width = this.iframeBounds.width + "px";
|
||||
this.element.style.height = this.iframeBounds.height + "px";
|
||||
|
||||
this.elementBounds = EPUBJS.core.bounds(this.element);
|
||||
|
||||
// this.iframe.style.display = "inline-block";
|
||||
this.iframe.style.visibility = "visible";
|
||||
|
||||
this.shown = true;
|
||||
|
||||
|
||||
// Reframe, incase the iframe was recreated
|
||||
// Also resizes element.
|
||||
this.reframe(this.width, this.height)
|
||||
|
||||
// this.iframe.style.display = "inline-block";
|
||||
this.element.style.visibility = "visible";
|
||||
this.iframe.style.visibility = "visible";
|
||||
|
||||
this.onShown(this);
|
||||
this.trigger("shown", this);
|
||||
};
|
||||
|
||||
EPUBJS.View.prototype.hide = function() {
|
||||
// this.iframe.style.display = "none";
|
||||
// this.iframe.style.visibility = "hidden";
|
||||
this.element.style.visibility = "hidden";
|
||||
this.iframe.style.visibility = "hidden";
|
||||
|
||||
this.stopExpanding = true;
|
||||
this.trigger("hidden");
|
||||
};
|
||||
|
||||
|
@ -321,6 +354,7 @@ EPUBJS.View.prototype.destroy = function() {
|
|||
// this.observer.disconnect();
|
||||
|
||||
if(this.iframe){
|
||||
this.stopExpanding = true;
|
||||
this.element.removeChild(this.iframe);
|
||||
this.shown = false;
|
||||
this.iframe = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue