mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Updated expanding, and resize
This commit is contained in:
parent
a574c68975
commit
1f7a4a2ccf
9 changed files with 362 additions and 256 deletions
|
@ -56,20 +56,21 @@ EPUBJS.Rendition.prototype.initialize = function(_options){
|
|||
|
||||
// Style Element
|
||||
container.style.fontSize = "0";
|
||||
container.style.wordSpacing = "0";
|
||||
container.style.lineHeight = "0";
|
||||
container.style.verticalAlign = "top";
|
||||
|
||||
if(this.settings.axis === "horizontal") {
|
||||
// this.container.style.display = "flex";
|
||||
// this.container.style.flexWrap = "nowrap";
|
||||
container.style.whiteSpace = "nowrap";
|
||||
}
|
||||
|
||||
if(options.width){
|
||||
//if(options.width){
|
||||
container.style.width = width;
|
||||
}
|
||||
//}
|
||||
|
||||
if(options.height){
|
||||
//if(options.height){
|
||||
container.style.height = height;
|
||||
}
|
||||
//}
|
||||
|
||||
container.style.overflow = this.settings.overflow;
|
||||
|
||||
|
@ -108,17 +109,6 @@ EPUBJS.Rendition.prototype.attachTo = function(_element){
|
|||
console.error("Not an Element");
|
||||
return;
|
||||
}
|
||||
|
||||
// If width or height are set to "100%", inherit them from containing element
|
||||
// if(this.settings.height === "100%") {
|
||||
// bounds = this.element.getBoundingClientRect();
|
||||
// this.container.style.height = bounds.height + "px";
|
||||
// }
|
||||
|
||||
// if(this.settings.width === "100%") {
|
||||
// bounds = bounds || this.element.getBoundingClientRect();
|
||||
// this.container.style.width = bounds.width + "px";
|
||||
// }
|
||||
|
||||
this.element.appendChild(this.container);
|
||||
|
||||
|
@ -154,7 +144,8 @@ EPUBJS.Rendition.prototype.attachTo = function(_element){
|
|||
EPUBJS.Rendition.prototype.attachListeners = function(){
|
||||
|
||||
// Listen to window for resize event if width or height is set to 100%
|
||||
if(this.settings.width === "100%" || this.settings.height === "100%") {
|
||||
if(!EPUBJS.core.isNumber(this.settings.width) ||
|
||||
!EPUBJS.core.isNumber(this.settings.height) ) {
|
||||
window.addEventListener("resize", this.onResized.bind(this), false);
|
||||
}
|
||||
|
||||
|
@ -206,8 +197,8 @@ EPUBJS.Rendition.prototype.render = function(view) {
|
|||
view.create();
|
||||
|
||||
// Fit to size of the container, apply padding
|
||||
// this.resizeView(view);
|
||||
|
||||
this.resizeView(view);
|
||||
|
||||
// Render Chain
|
||||
return view.display(this.book.request)
|
||||
.then(function(){
|
||||
|
@ -272,48 +263,54 @@ EPUBJS.Rendition.prototype.remove = function(view) {
|
|||
};
|
||||
|
||||
|
||||
// EPUBJS.Rendition.prototype.resizeView = function(view) {
|
||||
// // var bounds = this.container.getBoundingClientRect();
|
||||
// // var styles = window.getComputedStyle(this.container);
|
||||
// // var padding = {
|
||||
// // left: parseFloat(styles["padding-left"]) || 0,
|
||||
// // right: parseFloat(styles["padding-right"]) || 0,
|
||||
// // top: parseFloat(styles["padding-top"]) || 0,
|
||||
// // bottom: parseFloat(styles["padding-bottom"]) || 0
|
||||
// // };
|
||||
// // var width = bounds.width - padding.left - padding.right;
|
||||
// // var height = bounds.height - padding.top - padding.bottom;
|
||||
EPUBJS.Rendition.prototype.resizeView = function(view) {
|
||||
|
||||
// if(this.settings.axis === "vertical") {
|
||||
// view.resize(this.stage.width, 0);
|
||||
// } else {
|
||||
// view.resize(0, this.stage.height);
|
||||
// }
|
||||
// console.log("resize view")
|
||||
if(this.settings.axis === "horizontal") {
|
||||
view.lock(null, this.stage.height);
|
||||
} else {
|
||||
view.lock(this.stage.width, null);
|
||||
}
|
||||
|
||||
// };
|
||||
};
|
||||
|
||||
EPUBJS.Rendition.prototype.stageSize = function(_width, _height){
|
||||
var bounds;
|
||||
var width = _width || this.settings.width;
|
||||
var height = _height || this.settings.height;
|
||||
|
||||
if(width === "100%") {
|
||||
// If width or height are set to "100%", inherit them from containing element
|
||||
if(width === false) {
|
||||
bounds = this.element.getBoundingClientRect();
|
||||
width = bounds.width;
|
||||
height = bounds.height;
|
||||
|
||||
this.container.style.height = bounds.height + "px";
|
||||
if(bounds.width) {
|
||||
width = bounds.width;
|
||||
this.container.style.width = bounds.width + "px";
|
||||
}
|
||||
}
|
||||
|
||||
if(height === false) {
|
||||
bounds = bounds || this.element.getBoundingClientRect();
|
||||
|
||||
if(bounds.height) {
|
||||
height = bounds.height;
|
||||
this.container.style.height = bounds.height + "px";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(width && !EPUBJS.core.isNumber(width)) {
|
||||
bounds = this.container.getBoundingClientRect();
|
||||
width = bounds.width;
|
||||
//height = bounds.height;
|
||||
}
|
||||
|
||||
if(height === "100%") {
|
||||
bounds = bounds || this.element.getBoundingClientRect();
|
||||
width = bounds.width;
|
||||
if(height && !EPUBJS.core.isNumber(height)) {
|
||||
bounds = bounds || this.container.getBoundingClientRect();
|
||||
//width = bounds.width;
|
||||
height = bounds.height;
|
||||
|
||||
this.container.style.width = bounds.width + "px";
|
||||
}
|
||||
|
||||
|
||||
this.containerStyles = window.getComputedStyle(this.container);
|
||||
this.containerPadding = {
|
||||
left: parseFloat(this.containerStyles["padding-left"]) || 0,
|
||||
|
@ -341,9 +338,9 @@ EPUBJS.Rendition.prototype.resize = function(width, height){
|
|||
|
||||
this.views.forEach(function(view){
|
||||
if(this.settings.axis === "vertical") {
|
||||
view.resize(this.stage.width, 0);
|
||||
view.lock(this.stage.width, null);
|
||||
} else {
|
||||
view.resize(0, this.stage.height);
|
||||
view.lock(null, this.stage.height);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue