mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Fixed resizing
This commit is contained in:
parent
5c33f9c52b
commit
4670be6f4d
8 changed files with 203 additions and 215 deletions
190
dist/epub.js
vendored
190
dist/epub.js
vendored
|
@ -3959,6 +3959,7 @@ EPUBJS.Section.prototype.replacements = function(_document){
|
||||||
var task = new RSVP.defer();
|
var task = new RSVP.defer();
|
||||||
var base = _document.createElement("base"); // TODO: check if exists
|
var base = _document.createElement("base"); // TODO: check if exists
|
||||||
var head;
|
var head;
|
||||||
|
|
||||||
base.setAttribute("href", this.url);
|
base.setAttribute("href", this.url);
|
||||||
|
|
||||||
if(_document) {
|
if(_document) {
|
||||||
|
@ -4463,11 +4464,16 @@ EPUBJS.View.prototype.create = function() {
|
||||||
// this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
// this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// Firefox has trouble with baseURI and srcdoc
|
||||||
|
// Disabled for now
|
||||||
|
/*
|
||||||
if(!!("srcdoc" in this.iframe)) {
|
if(!!("srcdoc" in this.iframe)) {
|
||||||
this.supportsSrcdoc = true;
|
this.supportsSrcdoc = true;
|
||||||
} else {
|
} else {
|
||||||
this.supportsSrcdoc = false;
|
this.supportsSrcdoc = false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
this.supportsSrcdoc = false;
|
||||||
|
|
||||||
return this.iframe;
|
return this.iframe;
|
||||||
};
|
};
|
||||||
|
@ -4477,6 +4483,7 @@ EPUBJS.View.prototype.lock = function(width, height) {
|
||||||
|
|
||||||
var elBorders = EPUBJS.core.borders(this.element);
|
var elBorders = EPUBJS.core.borders(this.element);
|
||||||
var iframeBorders;
|
var iframeBorders;
|
||||||
|
|
||||||
if(this.iframe) {
|
if(this.iframe) {
|
||||||
iframeBorders = EPUBJS.core.borders(this.iframe);
|
iframeBorders = EPUBJS.core.borders(this.iframe);
|
||||||
} else {
|
} else {
|
||||||
|
@ -4486,21 +4493,19 @@ EPUBJS.View.prototype.lock = function(width, height) {
|
||||||
|
|
||||||
if(EPUBJS.core.isNumber(width)){
|
if(EPUBJS.core.isNumber(width)){
|
||||||
this.lockedWidth = width - elBorders.width - iframeBorders.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)){
|
if(EPUBJS.core.isNumber(height)){
|
||||||
this.lockedHeight = height - elBorders.height - iframeBorders.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) {
|
this.layout();
|
||||||
|
|
||||||
if (this.iframe && !this.resizing) {
|
|
||||||
this.expand();
|
this.expand();
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4521,12 +4526,13 @@ EPUBJS.View.prototype.resize = function(width, height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||||
|
|
||||||
this.reframe(this.iframeBounds.width, this.iframeBounds.height);
|
this.reframe(this.iframeBounds.width, this.iframeBounds.height);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.View.prototype.reframe = function(width, height) {
|
EPUBJS.View.prototype.reframe = function(width, height) {
|
||||||
var prevBounds;
|
//var prevBounds;
|
||||||
|
|
||||||
if(!this.shown) return;
|
if(!this.shown) return;
|
||||||
|
|
||||||
|
@ -4538,15 +4544,15 @@ EPUBJS.View.prototype.reframe = function(width, height) {
|
||||||
this.element.style.height = height + "px";
|
this.element.style.height = height + "px";
|
||||||
}
|
}
|
||||||
|
|
||||||
prevBounds = this.elementBounds;
|
this.prevBounds = this.elementBounds;
|
||||||
|
|
||||||
this.elementBounds = EPUBJS.core.bounds(this.element);
|
this.elementBounds = EPUBJS.core.bounds(this.element);
|
||||||
|
|
||||||
this.trigger("resized", {
|
this.trigger("resized", {
|
||||||
width: this.elementBounds.width,
|
width: this.elementBounds.width,
|
||||||
height: this.elementBounds.height,
|
height: this.elementBounds.height,
|
||||||
widthDelta: this.elementBounds.width - prevBounds.width,
|
widthDelta: this.elementBounds.width - this.prevBounds.width,
|
||||||
heightDelta: this.elementBounds.height - prevBounds.height,
|
heightDelta: this.elementBounds.height - this.prevBounds.height,
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -4653,84 +4659,27 @@ EPUBJS.View.prototype.listeners = function() {
|
||||||
this.mediaQueryListeners();
|
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() {
|
EPUBJS.View.prototype.expand = function() {
|
||||||
var width = this.lockedWidth;
|
var width = this.lockedWidth;
|
||||||
var height = this.lockedHeight;
|
var height = this.lockedHeight;
|
||||||
|
|
||||||
|
// Resize to the locked width;
|
||||||
|
//this.resize(width, height);
|
||||||
|
|
||||||
// Expand Vertically
|
// Expand Vertically
|
||||||
if(width && !height) {
|
if(width && !height) {
|
||||||
height = this.document.documentElement.scrollHeight;
|
height = this.document.documentElement.scrollHeight;
|
||||||
|
this.resize(null, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand Horizontally
|
// Expand Horizontally
|
||||||
if(height && !width) {
|
if(height && !width) {
|
||||||
width = this.document.body.scrollWidth;
|
width = this.document.body.scrollWidth;
|
||||||
|
this.resize(width, null);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.resize(width, height);
|
//this.reframe(width, height);
|
||||||
|
|
||||||
//this.width = width;
|
|
||||||
//this.height = height;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4871,7 +4820,11 @@ EPUBJS.View.prototype.root = function() {
|
||||||
RSVP.EventTarget.mixin(EPUBJS.View.prototype);
|
RSVP.EventTarget.mixin(EPUBJS.View.prototype);
|
||||||
EPUBJS.Layout = EPUBJS.Layout || {};
|
EPUBJS.Layout = EPUBJS.Layout || {};
|
||||||
|
|
||||||
EPUBJS.Layout.Reflowable = function(_width, _height, _gap, _devisor){
|
EPUBJS.Layout.Reflowable = function(){
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Reflowable.prototype.calculate = function(_width, _height, _gap, _devisor){
|
||||||
|
|
||||||
var divisor = _devisor || 1;
|
var divisor = _devisor || 1;
|
||||||
|
|
||||||
|
@ -4911,11 +4864,8 @@ EPUBJS.Layout.Reflowable = function(_width, _height, _gap, _devisor){
|
||||||
this.column = colWidth;
|
this.column = colWidth;
|
||||||
this.gap = gap;
|
this.gap = gap;
|
||||||
this.divisor = divisor;
|
this.divisor = divisor;
|
||||||
|
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
EPUBJS.Layout.Reflowable.prototype.format = function(view){
|
EPUBJS.Layout.Reflowable.prototype.format = function(view){
|
||||||
|
|
||||||
var $doc = view.document.documentElement;
|
var $doc = view.document.documentElement;
|
||||||
|
@ -4954,6 +4904,10 @@ EPUBJS.Layout.Fixed = function(_width, _height){
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Fixed.prototype.calculate = function(_width, _height){
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
EPUBJS.Layout.Fixed.prototype.format = function(view){
|
EPUBJS.Layout.Fixed.prototype.format = function(view){
|
||||||
var width, height;
|
var width, height;
|
||||||
|
|
||||||
|
@ -4992,7 +4946,11 @@ EPUBJS.Layout.Fixed.prototype.count = function(){
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Layout.Scroll = function(_width, _height){
|
EPUBJS.Layout.Scroll = function(){
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Scroll.prototype.calculate = function(_width, _height){
|
||||||
this.spread = _width;
|
this.spread = _width;
|
||||||
this.column = _width;
|
this.column = _width;
|
||||||
this.gap = 0;
|
this.gap = 0;
|
||||||
|
@ -5020,7 +4978,7 @@ EPUBJS.Rendition = function(book, options) {
|
||||||
infinite: true,
|
infinite: true,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
width: false,
|
width: false,
|
||||||
height: false,
|
height: null,
|
||||||
layoutOveride : null, // Default: { spread: 'reflowable', layout: 'auto', orientation: 'auto'},
|
layoutOveride : null, // Default: { spread: 'reflowable', layout: 'auto', orientation: 'auto'},
|
||||||
axis: "vertical"
|
axis: "vertical"
|
||||||
});
|
});
|
||||||
|
@ -5031,10 +4989,6 @@ EPUBJS.Rendition = function(book, options) {
|
||||||
|
|
||||||
this.book = book;
|
this.book = book;
|
||||||
|
|
||||||
if(this.settings.hidden) {
|
|
||||||
this.wrapper = this.wrap(this.container);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.views = [];
|
this.views = [];
|
||||||
|
|
||||||
//-- Adds Hook methods to the Rendition prototype
|
//-- Adds Hook methods to the Rendition prototype
|
||||||
|
@ -5138,7 +5092,12 @@ EPUBJS.Rendition.prototype.attachTo = function(_element){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.settings.hidden) {
|
||||||
|
this.wrapper = this.wrap(this.container);
|
||||||
|
this.element.appendChild(this.wrapper);
|
||||||
|
} else {
|
||||||
this.element.appendChild(this.container);
|
this.element.appendChild(this.container);
|
||||||
|
}
|
||||||
|
|
||||||
// Attach Listeners
|
// Attach Listeners
|
||||||
this.attachListeners();
|
this.attachListeners();
|
||||||
|
@ -5301,7 +5260,7 @@ EPUBJS.Rendition.prototype.stageSize = function(_width, _height){
|
||||||
var width = _width || this.settings.width;
|
var width = _width || this.settings.width;
|
||||||
var height = _height || this.settings.height;
|
var height = _height || this.settings.height;
|
||||||
|
|
||||||
// If width or height are set to "100%", inherit them from containing element
|
// If width or height are set to false, inherit them from containing element
|
||||||
if(width === false) {
|
if(width === false) {
|
||||||
bounds = this.element.getBoundingClientRect();
|
bounds = this.element.getBoundingClientRect();
|
||||||
|
|
||||||
|
@ -5357,15 +5316,22 @@ EPUBJS.Rendition.prototype.stageSize = function(_width, _height){
|
||||||
|
|
||||||
EPUBJS.Rendition.prototype.layoutMethod = function() {
|
EPUBJS.Rendition.prototype.layoutMethod = function() {
|
||||||
|
|
||||||
this.layout = new EPUBJS.Layout.Scroll(this.stage.width, this.stage.height);
|
this.layout = new EPUBJS.Layout.Scroll();
|
||||||
|
this.layoutUpdate();
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Rendition.prototype.layoutUpdate = function() {
|
||||||
|
|
||||||
|
this.layout.calculate(this.stage.width, this.stage.height);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
EPUBJS.Rendition.prototype.resize = function(width, height){
|
EPUBJS.Rendition.prototype.resize = function(width, height){
|
||||||
|
|
||||||
this.stageSize(width, height);
|
this.stageSize(width, height);
|
||||||
|
|
||||||
this.layoutMethod();
|
this.layoutUpdate();
|
||||||
|
|
||||||
this.views.forEach(this.resizeView.bind(this));
|
this.views.forEach(this.resizeView.bind(this));
|
||||||
|
|
||||||
|
@ -5636,7 +5602,6 @@ EPUBJS.Continuous.prototype.prepend = function(view){
|
||||||
|
|
||||||
//might need to enqueue
|
//might need to enqueue
|
||||||
view.on("resized", this.counter.bind(this));
|
view.on("resized", this.counter.bind(this));
|
||||||
|
|
||||||
return this.check();
|
return this.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5647,6 +5612,7 @@ EPUBJS.Continuous.prototype.counter = function(bounds){
|
||||||
} else {
|
} else {
|
||||||
this.scrollBy(bounds.widthDelta, 0, true);
|
this.scrollBy(bounds.widthDelta, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Continuous.prototype.fill = function(view){
|
EPUBJS.Continuous.prototype.fill = function(view){
|
||||||
|
@ -5881,7 +5847,8 @@ EPUBJS.Continuous.prototype.start = function() {
|
||||||
|
|
||||||
window.addEventListener('unload', function(e){
|
window.addEventListener('unload', function(e){
|
||||||
this.ignore = true;
|
this.ignore = true;
|
||||||
});
|
this.destroy();
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
this.tick.call(window, this.onScroll.bind(this));
|
this.tick.call(window, this.onScroll.bind(this));
|
||||||
|
|
||||||
|
@ -5956,8 +5923,10 @@ EPUBJS.Continuous.prototype.scrollBy = function(x, y, silent){
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.settings.height) {
|
if(this.settings.height) {
|
||||||
this.container.scrollLeft += x;
|
|
||||||
this.container.scrollTop += y;
|
if(x) this.container.scrollLeft += x;
|
||||||
|
if(y) this.container.scrollTop += y;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
window.scrollBy(x,y);
|
window.scrollBy(x,y);
|
||||||
}
|
}
|
||||||
|
@ -5996,6 +5965,15 @@ EPUBJS.Continuous.prototype.scrollTo = function(x, y, silent){
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Continuous.prototype.destroy = function() {
|
||||||
|
|
||||||
|
this.clear();
|
||||||
|
|
||||||
|
this.element.removeChild(this.container);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
EPUBJS.Continuous.prototype.current = function(what){
|
EPUBJS.Continuous.prototype.current = function(what){
|
||||||
var view, top;
|
var view, top;
|
||||||
|
@ -6135,6 +6113,11 @@ EPUBJS.Paginate.prototype.start = function(){
|
||||||
|
|
||||||
this.currentPage = 0;
|
this.currentPage = 0;
|
||||||
|
|
||||||
|
window.addEventListener('unload', function(e){
|
||||||
|
this.ignore = true;
|
||||||
|
this.destroy();
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// EPUBJS.Rendition.prototype.createView = function(section) {
|
// EPUBJS.Rendition.prototype.createView = function(section) {
|
||||||
|
@ -6147,17 +6130,13 @@ EPUBJS.Paginate.prototype.start = function(){
|
||||||
EPUBJS.Paginate.prototype.layoutMethod = function() {
|
EPUBJS.Paginate.prototype.layoutMethod = function() {
|
||||||
//var task = new RSVP.defer();
|
//var task = new RSVP.defer();
|
||||||
|
|
||||||
this.spreads = this.determineSpreads(this.settings.minSpreadWidth);
|
// this.spreads = this.determineSpreads(this.settings.minSpreadWidth);
|
||||||
|
|
||||||
this.layout = new EPUBJS.Layout.Reflowable(
|
this.layout = new EPUBJS.Layout.Reflowable();
|
||||||
this.stage.width,
|
|
||||||
this.stage.height,
|
this.layoutUpdate();
|
||||||
this.settings.gap,
|
|
||||||
this.spreads
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set the look ahead offset for what is visible
|
// Set the look ahead offset for what is visible
|
||||||
this.settings.offset = this.layout.delta;
|
|
||||||
|
|
||||||
this.map = new EPUBJS.Map(this.layout);
|
this.map = new EPUBJS.Map(this.layout);
|
||||||
|
|
||||||
|
@ -6168,6 +6147,21 @@ EPUBJS.Paginate.prototype.layoutMethod = function() {
|
||||||
// return layout;
|
// return layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Paginate.prototype.layoutUpdate = function() {
|
||||||
|
|
||||||
|
this.spreads = this.determineSpreads(this.settings.minSpreadWidth);
|
||||||
|
|
||||||
|
this.layout.calculate(
|
||||||
|
this.stage.width,
|
||||||
|
this.stage.height,
|
||||||
|
this.settings.gap,
|
||||||
|
this.spreads
|
||||||
|
);
|
||||||
|
|
||||||
|
this.settings.offset = this.layout.delta;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
EPUBJS.Paginate.prototype.page = function(pg){
|
EPUBJS.Paginate.prototype.page = function(pg){
|
||||||
|
|
||||||
// this.currentPage = pg;
|
// this.currentPage = pg;
|
||||||
|
|
6
dist/epub.min.js
vendored
6
dist/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -145,7 +145,6 @@ EPUBJS.Continuous.prototype.prepend = function(view){
|
||||||
|
|
||||||
//might need to enqueue
|
//might need to enqueue
|
||||||
view.on("resized", this.counter.bind(this));
|
view.on("resized", this.counter.bind(this));
|
||||||
|
|
||||||
return this.check();
|
return this.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -156,6 +155,7 @@ EPUBJS.Continuous.prototype.counter = function(bounds){
|
||||||
} else {
|
} else {
|
||||||
this.scrollBy(bounds.widthDelta, 0, true);
|
this.scrollBy(bounds.widthDelta, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Continuous.prototype.fill = function(view){
|
EPUBJS.Continuous.prototype.fill = function(view){
|
||||||
|
@ -390,7 +390,8 @@ EPUBJS.Continuous.prototype.start = function() {
|
||||||
|
|
||||||
window.addEventListener('unload', function(e){
|
window.addEventListener('unload', function(e){
|
||||||
this.ignore = true;
|
this.ignore = true;
|
||||||
});
|
this.destroy();
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
this.tick.call(window, this.onScroll.bind(this));
|
this.tick.call(window, this.onScroll.bind(this));
|
||||||
|
|
||||||
|
@ -465,8 +466,10 @@ EPUBJS.Continuous.prototype.scrollBy = function(x, y, silent){
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.settings.height) {
|
if(this.settings.height) {
|
||||||
this.container.scrollLeft += x;
|
|
||||||
this.container.scrollTop += y;
|
if(x) this.container.scrollLeft += x;
|
||||||
|
if(y) this.container.scrollTop += y;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
window.scrollBy(x,y);
|
window.scrollBy(x,y);
|
||||||
}
|
}
|
||||||
|
@ -505,6 +508,15 @@ EPUBJS.Continuous.prototype.scrollTo = function(x, y, silent){
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Continuous.prototype.destroy = function() {
|
||||||
|
|
||||||
|
this.clear();
|
||||||
|
|
||||||
|
this.element.removeChild(this.container);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
EPUBJS.Continuous.prototype.current = function(what){
|
EPUBJS.Continuous.prototype.current = function(what){
|
||||||
var view, top;
|
var view, top;
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
EPUBJS.Layout = EPUBJS.Layout || {};
|
EPUBJS.Layout = EPUBJS.Layout || {};
|
||||||
|
|
||||||
EPUBJS.Layout.Reflowable = function(_width, _height, _gap, _devisor){
|
EPUBJS.Layout.Reflowable = function(){
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Reflowable.prototype.calculate = function(_width, _height, _gap, _devisor){
|
||||||
|
|
||||||
var divisor = _devisor || 1;
|
var divisor = _devisor || 1;
|
||||||
|
|
||||||
|
@ -40,11 +44,8 @@ EPUBJS.Layout.Reflowable = function(_width, _height, _gap, _devisor){
|
||||||
this.column = colWidth;
|
this.column = colWidth;
|
||||||
this.gap = gap;
|
this.gap = gap;
|
||||||
this.divisor = divisor;
|
this.divisor = divisor;
|
||||||
|
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
EPUBJS.Layout.Reflowable.prototype.format = function(view){
|
EPUBJS.Layout.Reflowable.prototype.format = function(view){
|
||||||
|
|
||||||
var $doc = view.document.documentElement;
|
var $doc = view.document.documentElement;
|
||||||
|
@ -83,6 +84,10 @@ EPUBJS.Layout.Fixed = function(_width, _height){
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Fixed.prototype.calculate = function(_width, _height){
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
EPUBJS.Layout.Fixed.prototype.format = function(view){
|
EPUBJS.Layout.Fixed.prototype.format = function(view){
|
||||||
var width, height;
|
var width, height;
|
||||||
|
|
||||||
|
@ -121,7 +126,11 @@ EPUBJS.Layout.Fixed.prototype.count = function(){
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Layout.Scroll = function(_width, _height){
|
EPUBJS.Layout.Scroll = function(){
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Layout.Scroll.prototype.calculate = function(_width, _height){
|
||||||
this.spread = _width;
|
this.spread = _width;
|
||||||
this.column = _width;
|
this.column = _width;
|
||||||
this.gap = 0;
|
this.gap = 0;
|
||||||
|
|
|
@ -92,6 +92,11 @@ EPUBJS.Paginate.prototype.start = function(){
|
||||||
|
|
||||||
this.currentPage = 0;
|
this.currentPage = 0;
|
||||||
|
|
||||||
|
window.addEventListener('unload', function(e){
|
||||||
|
this.ignore = true;
|
||||||
|
this.destroy();
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// EPUBJS.Rendition.prototype.createView = function(section) {
|
// EPUBJS.Rendition.prototype.createView = function(section) {
|
||||||
|
@ -104,17 +109,13 @@ EPUBJS.Paginate.prototype.start = function(){
|
||||||
EPUBJS.Paginate.prototype.layoutMethod = function() {
|
EPUBJS.Paginate.prototype.layoutMethod = function() {
|
||||||
//var task = new RSVP.defer();
|
//var task = new RSVP.defer();
|
||||||
|
|
||||||
this.spreads = this.determineSpreads(this.settings.minSpreadWidth);
|
// this.spreads = this.determineSpreads(this.settings.minSpreadWidth);
|
||||||
|
|
||||||
this.layout = new EPUBJS.Layout.Reflowable(
|
this.layout = new EPUBJS.Layout.Reflowable();
|
||||||
this.stage.width,
|
|
||||||
this.stage.height,
|
this.layoutUpdate();
|
||||||
this.settings.gap,
|
|
||||||
this.spreads
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set the look ahead offset for what is visible
|
// Set the look ahead offset for what is visible
|
||||||
this.settings.offset = this.layout.delta;
|
|
||||||
|
|
||||||
this.map = new EPUBJS.Map(this.layout);
|
this.map = new EPUBJS.Map(this.layout);
|
||||||
|
|
||||||
|
@ -125,6 +126,21 @@ EPUBJS.Paginate.prototype.layoutMethod = function() {
|
||||||
// return layout;
|
// return layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EPUBJS.Paginate.prototype.layoutUpdate = function() {
|
||||||
|
|
||||||
|
this.spreads = this.determineSpreads(this.settings.minSpreadWidth);
|
||||||
|
|
||||||
|
this.layout.calculate(
|
||||||
|
this.stage.width,
|
||||||
|
this.stage.height,
|
||||||
|
this.settings.gap,
|
||||||
|
this.spreads
|
||||||
|
);
|
||||||
|
|
||||||
|
this.settings.offset = this.layout.delta;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
EPUBJS.Paginate.prototype.page = function(pg){
|
EPUBJS.Paginate.prototype.page = function(pg){
|
||||||
|
|
||||||
// this.currentPage = pg;
|
// this.currentPage = pg;
|
||||||
|
|
|
@ -4,7 +4,7 @@ EPUBJS.Rendition = function(book, options) {
|
||||||
infinite: true,
|
infinite: true,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
width: false,
|
width: false,
|
||||||
height: false,
|
height: null,
|
||||||
layoutOveride : null, // Default: { spread: 'reflowable', layout: 'auto', orientation: 'auto'},
|
layoutOveride : null, // Default: { spread: 'reflowable', layout: 'auto', orientation: 'auto'},
|
||||||
axis: "vertical"
|
axis: "vertical"
|
||||||
});
|
});
|
||||||
|
@ -15,10 +15,6 @@ EPUBJS.Rendition = function(book, options) {
|
||||||
|
|
||||||
this.book = book;
|
this.book = book;
|
||||||
|
|
||||||
if(this.settings.hidden) {
|
|
||||||
this.wrapper = this.wrap(this.container);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.views = [];
|
this.views = [];
|
||||||
|
|
||||||
//-- Adds Hook methods to the Rendition prototype
|
//-- Adds Hook methods to the Rendition prototype
|
||||||
|
@ -122,7 +118,12 @@ EPUBJS.Rendition.prototype.attachTo = function(_element){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.settings.hidden) {
|
||||||
|
this.wrapper = this.wrap(this.container);
|
||||||
|
this.element.appendChild(this.wrapper);
|
||||||
|
} else {
|
||||||
this.element.appendChild(this.container);
|
this.element.appendChild(this.container);
|
||||||
|
}
|
||||||
|
|
||||||
// Attach Listeners
|
// Attach Listeners
|
||||||
this.attachListeners();
|
this.attachListeners();
|
||||||
|
@ -285,7 +286,7 @@ EPUBJS.Rendition.prototype.stageSize = function(_width, _height){
|
||||||
var width = _width || this.settings.width;
|
var width = _width || this.settings.width;
|
||||||
var height = _height || this.settings.height;
|
var height = _height || this.settings.height;
|
||||||
|
|
||||||
// If width or height are set to "100%", inherit them from containing element
|
// If width or height are set to false, inherit them from containing element
|
||||||
if(width === false) {
|
if(width === false) {
|
||||||
bounds = this.element.getBoundingClientRect();
|
bounds = this.element.getBoundingClientRect();
|
||||||
|
|
||||||
|
@ -341,15 +342,22 @@ EPUBJS.Rendition.prototype.stageSize = function(_width, _height){
|
||||||
|
|
||||||
EPUBJS.Rendition.prototype.layoutMethod = function() {
|
EPUBJS.Rendition.prototype.layoutMethod = function() {
|
||||||
|
|
||||||
this.layout = new EPUBJS.Layout.Scroll(this.stage.width, this.stage.height);
|
this.layout = new EPUBJS.Layout.Scroll();
|
||||||
|
this.layoutUpdate();
|
||||||
|
};
|
||||||
|
|
||||||
|
EPUBJS.Rendition.prototype.layoutUpdate = function() {
|
||||||
|
|
||||||
|
this.layout.calculate(this.stage.width, this.stage.height);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
EPUBJS.Rendition.prototype.resize = function(width, height){
|
EPUBJS.Rendition.prototype.resize = function(width, height){
|
||||||
|
|
||||||
this.stageSize(width, height);
|
this.stageSize(width, height);
|
||||||
|
|
||||||
this.layoutMethod();
|
this.layoutUpdate();
|
||||||
|
|
||||||
this.views.forEach(this.resizeView.bind(this));
|
this.views.forEach(this.resizeView.bind(this));
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ EPUBJS.Section.prototype.replacements = function(_document){
|
||||||
var task = new RSVP.defer();
|
var task = new RSVP.defer();
|
||||||
var base = _document.createElement("base"); // TODO: check if exists
|
var base = _document.createElement("base"); // TODO: check if exists
|
||||||
var head;
|
var head;
|
||||||
|
|
||||||
base.setAttribute("href", this.url);
|
base.setAttribute("href", this.url);
|
||||||
|
|
||||||
if(_document) {
|
if(_document) {
|
||||||
|
|
|
@ -63,11 +63,16 @@ EPUBJS.View.prototype.create = function() {
|
||||||
// this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
// this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// Firefox has trouble with baseURI and srcdoc
|
||||||
|
// Disabled for now
|
||||||
|
/*
|
||||||
if(!!("srcdoc" in this.iframe)) {
|
if(!!("srcdoc" in this.iframe)) {
|
||||||
this.supportsSrcdoc = true;
|
this.supportsSrcdoc = true;
|
||||||
} else {
|
} else {
|
||||||
this.supportsSrcdoc = false;
|
this.supportsSrcdoc = false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
this.supportsSrcdoc = false;
|
||||||
|
|
||||||
return this.iframe;
|
return this.iframe;
|
||||||
};
|
};
|
||||||
|
@ -77,6 +82,7 @@ EPUBJS.View.prototype.lock = function(width, height) {
|
||||||
|
|
||||||
var elBorders = EPUBJS.core.borders(this.element);
|
var elBorders = EPUBJS.core.borders(this.element);
|
||||||
var iframeBorders;
|
var iframeBorders;
|
||||||
|
|
||||||
if(this.iframe) {
|
if(this.iframe) {
|
||||||
iframeBorders = EPUBJS.core.borders(this.iframe);
|
iframeBorders = EPUBJS.core.borders(this.iframe);
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,21 +92,19 @@ EPUBJS.View.prototype.lock = function(width, height) {
|
||||||
|
|
||||||
if(EPUBJS.core.isNumber(width)){
|
if(EPUBJS.core.isNumber(width)){
|
||||||
this.lockedWidth = width - elBorders.width - iframeBorders.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)){
|
if(EPUBJS.core.isNumber(height)){
|
||||||
this.lockedHeight = height - elBorders.height - iframeBorders.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) {
|
this.layout();
|
||||||
|
|
||||||
if (this.iframe && !this.resizing) {
|
|
||||||
this.expand();
|
this.expand();
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,12 +125,13 @@ EPUBJS.View.prototype.resize = function(width, height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
this.iframeBounds = EPUBJS.core.bounds(this.iframe);
|
||||||
|
|
||||||
this.reframe(this.iframeBounds.width, this.iframeBounds.height);
|
this.reframe(this.iframeBounds.width, this.iframeBounds.height);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.View.prototype.reframe = function(width, height) {
|
EPUBJS.View.prototype.reframe = function(width, height) {
|
||||||
var prevBounds;
|
//var prevBounds;
|
||||||
|
|
||||||
if(!this.shown) return;
|
if(!this.shown) return;
|
||||||
|
|
||||||
|
@ -138,15 +143,15 @@ EPUBJS.View.prototype.reframe = function(width, height) {
|
||||||
this.element.style.height = height + "px";
|
this.element.style.height = height + "px";
|
||||||
}
|
}
|
||||||
|
|
||||||
prevBounds = this.elementBounds;
|
this.prevBounds = this.elementBounds;
|
||||||
|
|
||||||
this.elementBounds = EPUBJS.core.bounds(this.element);
|
this.elementBounds = EPUBJS.core.bounds(this.element);
|
||||||
|
|
||||||
this.trigger("resized", {
|
this.trigger("resized", {
|
||||||
width: this.elementBounds.width,
|
width: this.elementBounds.width,
|
||||||
height: this.elementBounds.height,
|
height: this.elementBounds.height,
|
||||||
widthDelta: this.elementBounds.width - prevBounds.width,
|
widthDelta: this.elementBounds.width - this.prevBounds.width,
|
||||||
heightDelta: this.elementBounds.height - prevBounds.height,
|
heightDelta: this.elementBounds.height - this.prevBounds.height,
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -253,84 +258,27 @@ EPUBJS.View.prototype.listeners = function() {
|
||||||
this.mediaQueryListeners();
|
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() {
|
EPUBJS.View.prototype.expand = function() {
|
||||||
var width = this.lockedWidth;
|
var width = this.lockedWidth;
|
||||||
var height = this.lockedHeight;
|
var height = this.lockedHeight;
|
||||||
|
|
||||||
|
// Resize to the locked width;
|
||||||
|
//this.resize(width, height);
|
||||||
|
|
||||||
// Expand Vertically
|
// Expand Vertically
|
||||||
if(width && !height) {
|
if(width && !height) {
|
||||||
height = this.document.documentElement.scrollHeight;
|
height = this.document.documentElement.scrollHeight;
|
||||||
|
this.resize(null, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand Horizontally
|
// Expand Horizontally
|
||||||
if(height && !width) {
|
if(height && !width) {
|
||||||
width = this.document.body.scrollWidth;
|
width = this.document.body.scrollWidth;
|
||||||
|
this.resize(width, null);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.resize(width, height);
|
//this.reframe(width, height);
|
||||||
|
|
||||||
//this.width = width;
|
|
||||||
//this.height = height;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue