mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Fixed resizing
This commit is contained in:
parent
5c33f9c52b
commit
4670be6f4d
8 changed files with 203 additions and 215 deletions
|
@ -63,11 +63,16 @@ EPUBJS.View.prototype.create = function() {
|
|||
// this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||
// }
|
||||
|
||||
// Firefox has trouble with baseURI and srcdoc
|
||||
// Disabled for now
|
||||
/*
|
||||
if(!!("srcdoc" in this.iframe)) {
|
||||
this.supportsSrcdoc = true;
|
||||
} else {
|
||||
this.supportsSrcdoc = false;
|
||||
}
|
||||
*/
|
||||
this.supportsSrcdoc = false;
|
||||
|
||||
return this.iframe;
|
||||
};
|
||||
|
@ -77,6 +82,7 @@ EPUBJS.View.prototype.lock = function(width, height) {
|
|||
|
||||
var elBorders = EPUBJS.core.borders(this.element);
|
||||
var iframeBorders;
|
||||
|
||||
if(this.iframe) {
|
||||
iframeBorders = EPUBJS.core.borders(this.iframe);
|
||||
} else {
|
||||
|
@ -86,21 +92,19 @@ EPUBJS.View.prototype.lock = function(width, height) {
|
|||
|
||||
if(EPUBJS.core.isNumber(width)){
|
||||
this.lockedWidth = width - elBorders.width - iframeBorders.width;
|
||||
this.resize(this.lockedWidth, 0);
|
||||
this.resize(this.lockedWidth, width); // width keeps ratio correct
|
||||
}
|
||||
|
||||
if(EPUBJS.core.isNumber(height)){
|
||||
this.lockedHeight = height - elBorders.height - iframeBorders.height;
|
||||
this.resize(0, this.lockedHeight);
|
||||
this.resize(null, this.lockedHeight);
|
||||
}
|
||||
|
||||
|
||||
if(this.shown && this.iframe) {
|
||||
|
||||
if(this.shown) {
|
||||
|
||||
if (this.iframe && !this.resizing) {
|
||||
this.layout();
|
||||
this.expand();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -121,12 +125,13 @@ EPUBJS.View.prototype.resize = function(width, height) {
|
|||
}
|
||||
|
||||
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||
|
||||
this.reframe(this.iframeBounds.width, this.iframeBounds.height);
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.View.prototype.reframe = function(width, height) {
|
||||
var prevBounds;
|
||||
//var prevBounds;
|
||||
|
||||
if(!this.shown) return;
|
||||
|
||||
|
@ -138,15 +143,15 @@ EPUBJS.View.prototype.reframe = function(width, height) {
|
|||
this.element.style.height = height + "px";
|
||||
}
|
||||
|
||||
prevBounds = this.elementBounds;
|
||||
this.prevBounds = this.elementBounds;
|
||||
|
||||
this.elementBounds = EPUBJS.core.bounds(this.element);
|
||||
|
||||
this.trigger("resized", {
|
||||
width: this.elementBounds.width,
|
||||
height: this.elementBounds.height,
|
||||
widthDelta: this.elementBounds.width - prevBounds.width,
|
||||
heightDelta: this.elementBounds.height - prevBounds.height,
|
||||
widthDelta: this.elementBounds.width - this.prevBounds.width,
|
||||
heightDelta: this.elementBounds.height - this.prevBounds.height,
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -253,84 +258,27 @@ EPUBJS.View.prototype.listeners = function() {
|
|||
this.mediaQueryListeners();
|
||||
|
||||
};
|
||||
/*
|
||||
EPUBJS.View.prototype.expand = function(_defer, _count, _func) {
|
||||
var bounds;
|
||||
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 count = _count || 1;
|
||||
var TIMEOUT = 10 * _count;
|
||||
|
||||
// Flag Changes
|
||||
this.resizing = true;
|
||||
|
||||
// Check bounds
|
||||
bounds = this.document.body.getBoundingClientRect();
|
||||
if(!bounds || (bounds.height === 0 && bounds.width === 0)) {
|
||||
console.error("View not shown", this);
|
||||
|
||||
// setTimeout(function(){
|
||||
// this.expand(expanding, count);
|
||||
// }.bind(this), TIMEOUT);
|
||||
|
||||
expanding.resolve();
|
||||
|
||||
return expanded;
|
||||
}
|
||||
|
||||
height = this.lockedHeight || bounds.height; //this.document.documentElement.scrollHeight; //window.getComputedStyle?
|
||||
|
||||
width = this.lockedWidth || this.document.documentElement.scrollWidth;
|
||||
|
||||
|
||||
if(count <= MAX && (this.width != width || this.height != height) && !this.stopExpanding) {
|
||||
|
||||
this.reframe(width, height);
|
||||
|
||||
this.expandTimeout = setTimeout(function(){
|
||||
count += 1;
|
||||
if(_func){
|
||||
_func(this);
|
||||
}
|
||||
this.expand(expanding, count, _func);
|
||||
}.bind(this), TIMEOUT);
|
||||
|
||||
} else {
|
||||
this.resizing = false;
|
||||
if(this.stopExpanding){
|
||||
this.stopExpanding = null;
|
||||
}
|
||||
expanding.resolve();
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
return expanded;
|
||||
};
|
||||
*/
|
||||
EPUBJS.View.prototype.expand = function() {
|
||||
var width = this.lockedWidth;
|
||||
var height = this.lockedHeight;
|
||||
|
||||
// Resize to the locked width;
|
||||
//this.resize(width, height);
|
||||
|
||||
// Expand Vertically
|
||||
if(width && !height) {
|
||||
height = this.document.documentElement.scrollHeight;
|
||||
this.resize(null, height);
|
||||
}
|
||||
|
||||
// Expand Horizontally
|
||||
if(height && !width) {
|
||||
width = this.document.body.scrollWidth;
|
||||
this.resize(width, null);
|
||||
};
|
||||
|
||||
this.resize(width, height);
|
||||
|
||||
//this.width = width;
|
||||
//this.height = height;
|
||||
//this.reframe(width, height);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue