mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Preserve aspect ratio when expanding
This commit is contained in:
parent
27fec5a305
commit
4a7e08c49a
4 changed files with 18 additions and 14 deletions
12
dist/epub.js
vendored
12
dist/epub.js
vendored
|
@ -3964,9 +3964,9 @@ EPUBJS.View.prototype.expand = function(force) {
|
||||||
var height = this.lockedHeight;
|
var height = this.lockedHeight;
|
||||||
|
|
||||||
var textWidth, textHeight;
|
var textWidth, textHeight;
|
||||||
|
// console.log("expanding a")
|
||||||
if(!this.iframe || this._expanding) return;
|
if(!this.iframe || this._expanding) return;
|
||||||
|
|
||||||
this._expanding = true;
|
this._expanding = true;
|
||||||
|
|
||||||
// Expand Horizontally
|
// Expand Horizontally
|
||||||
|
@ -4016,7 +4016,8 @@ EPUBJS.View.prototype.contentWidth = function(min) {
|
||||||
// Save previous width
|
// Save previous width
|
||||||
prev = this.iframe.style.width;
|
prev = this.iframe.style.width;
|
||||||
// Set the iframe size to min, width will only ever be greater
|
// Set the iframe size to min, width will only ever be greater
|
||||||
this.iframe.style.width = 0 + "px";
|
// Will preserve the aspect ratio
|
||||||
|
this.iframe.style.width = (min || 0) + "px";
|
||||||
// Get the scroll overflow width
|
// Get the scroll overflow width
|
||||||
width = this.document.body.scrollWidth;
|
width = this.document.body.scrollWidth;
|
||||||
// Reset iframe size back
|
// Reset iframe size back
|
||||||
|
@ -4229,7 +4230,7 @@ EPUBJS.View.prototype.listeners = function() {
|
||||||
EPUBJS.View.prototype.resizeListenters = function() {
|
EPUBJS.View.prototype.resizeListenters = function() {
|
||||||
// Test size again
|
// Test size again
|
||||||
clearTimeout(this.expanding);
|
clearTimeout(this.expanding);
|
||||||
this.expanding = setTimeout(this.expand.bind(this), 350);
|
// this.expanding = setTimeout(this.expand.bind(this), 350);
|
||||||
};
|
};
|
||||||
|
|
||||||
//https://github.com/tylergaw/media-query-events/blob/master/js/mq-events.js
|
//https://github.com/tylergaw/media-query-events/blob/master/js/mq-events.js
|
||||||
|
@ -4237,7 +4238,8 @@ EPUBJS.View.prototype.mediaQueryListeners = function() {
|
||||||
var sheets = this.document.styleSheets;
|
var sheets = this.document.styleSheets;
|
||||||
var mediaChangeHandler = function(m){
|
var mediaChangeHandler = function(m){
|
||||||
if(m.matches && !this._expanding) {
|
if(m.matches && !this._expanding) {
|
||||||
this.expand();
|
setTimeout(this.expand.bind(this), 1);
|
||||||
|
// this.expand();
|
||||||
}
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|
4
dist/epub.min.js
vendored
4
dist/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -97,8 +97,8 @@
|
||||||
height: "100%"
|
height: "100%"
|
||||||
});
|
});
|
||||||
|
|
||||||
// var displayed = rendition.display("chapter_001.xhtml");
|
var displayed = rendition.display("chapter_001.xhtml");
|
||||||
var displayed = rendition.display();
|
// var displayed = rendition.display();
|
||||||
|
|
||||||
displayed.then(function(renderer){
|
displayed.then(function(renderer){
|
||||||
// -- do stuff
|
// -- do stuff
|
||||||
|
|
12
src/view.js
12
src/view.js
|
@ -132,9 +132,9 @@ EPUBJS.View.prototype.expand = function(force) {
|
||||||
var height = this.lockedHeight;
|
var height = this.lockedHeight;
|
||||||
|
|
||||||
var textWidth, textHeight;
|
var textWidth, textHeight;
|
||||||
|
// console.log("expanding a")
|
||||||
if(!this.iframe || this._expanding) return;
|
if(!this.iframe || this._expanding) return;
|
||||||
|
|
||||||
this._expanding = true;
|
this._expanding = true;
|
||||||
|
|
||||||
// Expand Horizontally
|
// Expand Horizontally
|
||||||
|
@ -184,7 +184,8 @@ EPUBJS.View.prototype.contentWidth = function(min) {
|
||||||
// Save previous width
|
// Save previous width
|
||||||
prev = this.iframe.style.width;
|
prev = this.iframe.style.width;
|
||||||
// Set the iframe size to min, width will only ever be greater
|
// Set the iframe size to min, width will only ever be greater
|
||||||
this.iframe.style.width = 0 + "px";
|
// Will preserve the aspect ratio
|
||||||
|
this.iframe.style.width = (min || 0) + "px";
|
||||||
// Get the scroll overflow width
|
// Get the scroll overflow width
|
||||||
width = this.document.body.scrollWidth;
|
width = this.document.body.scrollWidth;
|
||||||
// Reset iframe size back
|
// Reset iframe size back
|
||||||
|
@ -397,7 +398,7 @@ EPUBJS.View.prototype.listeners = function() {
|
||||||
EPUBJS.View.prototype.resizeListenters = function() {
|
EPUBJS.View.prototype.resizeListenters = function() {
|
||||||
// Test size again
|
// Test size again
|
||||||
clearTimeout(this.expanding);
|
clearTimeout(this.expanding);
|
||||||
this.expanding = setTimeout(this.expand.bind(this), 350);
|
// this.expanding = setTimeout(this.expand.bind(this), 350);
|
||||||
};
|
};
|
||||||
|
|
||||||
//https://github.com/tylergaw/media-query-events/blob/master/js/mq-events.js
|
//https://github.com/tylergaw/media-query-events/blob/master/js/mq-events.js
|
||||||
|
@ -405,7 +406,8 @@ EPUBJS.View.prototype.mediaQueryListeners = function() {
|
||||||
var sheets = this.document.styleSheets;
|
var sheets = this.document.styleSheets;
|
||||||
var mediaChangeHandler = function(m){
|
var mediaChangeHandler = function(m){
|
||||||
if(m.matches && !this._expanding) {
|
if(m.matches && !this._expanding) {
|
||||||
this.expand();
|
setTimeout(this.expand.bind(this), 1);
|
||||||
|
// this.expand();
|
||||||
}
|
}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue