mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Callbacks for layout
This commit is contained in:
parent
1547830c36
commit
35701e5db7
3 changed files with 46 additions and 29 deletions
16
src/book.js
16
src/book.js
|
@ -69,6 +69,7 @@ Book.prototype.open = function(_url){
|
||||||
var containerPath = "META-INF/container.xml";
|
var containerPath = "META-INF/container.xml";
|
||||||
var location;
|
var location;
|
||||||
var absoluteUri;
|
var absoluteUri;
|
||||||
|
var isArrayBuffer = false;
|
||||||
|
|
||||||
if(!_url) {
|
if(!_url) {
|
||||||
this.opening.resolve(this);
|
this.opening.resolve(this);
|
||||||
|
@ -81,17 +82,24 @@ Book.prototype.open = function(_url){
|
||||||
// } else {
|
// } else {
|
||||||
// uri = core.uri(_url);
|
// uri = core.uri(_url);
|
||||||
// }
|
// }
|
||||||
uri = URI(_url);
|
if (_url instanceof ArrayBuffer) {
|
||||||
|
isArrayBuffer = true;
|
||||||
|
this.url = '/';
|
||||||
|
} else {
|
||||||
|
uri = URI(_url);
|
||||||
|
}
|
||||||
|
|
||||||
if (window && window.location) {
|
if (window && window.location && uri) {
|
||||||
absoluteUri = uri.absoluteTo(window.location.href);
|
absoluteUri = uri.absoluteTo(window.location.href);
|
||||||
this.url = absoluteUri.toString();
|
this.url = absoluteUri.toString();
|
||||||
|
} if (window && window.location) {
|
||||||
|
this.url = window.location.href;
|
||||||
} else {
|
} else {
|
||||||
this.url = _url;
|
this.url = _url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find path to the Container
|
// Find path to the Container
|
||||||
if(uri.suffix() === "opf") {
|
if(uri && uri.suffix() === "opf") {
|
||||||
// Direct link to package, no container
|
// Direct link to package, no container
|
||||||
this.packageUrl = _url;
|
this.packageUrl = _url;
|
||||||
this.containerUrl = '';
|
this.containerUrl = '';
|
||||||
|
@ -107,7 +115,7 @@ Book.prototype.open = function(_url){
|
||||||
|
|
||||||
epubPackage = this.request(this.packageUrl);
|
epubPackage = this.request(this.packageUrl);
|
||||||
|
|
||||||
} else if(this.isArchivedUrl(uri)) {
|
} else if(isArrayBuffer || this.isArchivedUrl(uri)) {
|
||||||
// Book is archived
|
// Book is archived
|
||||||
this.url = '/';
|
this.url = '/';
|
||||||
this.containerUrl = URI(containerPath).absoluteTo(this.url).toString();
|
this.containerUrl = URI(containerPath).absoluteTo(this.url).toString();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
var core = require('./core');
|
var core = require('./core');
|
||||||
|
var RSVP = require('rsvp');
|
||||||
|
|
||||||
function Reflowable(){
|
function Reflowable(){
|
||||||
this.columnAxis = core.prefixed('columnAxis');
|
this.columnAxis = core.prefixed('columnAxis');
|
||||||
|
@ -64,36 +65,37 @@ Reflowable.prototype.calculate = function(_width, _height, _gap, _devisor){
|
||||||
};
|
};
|
||||||
|
|
||||||
Reflowable.prototype.format = function(contents){
|
Reflowable.prototype.format = function(contents){
|
||||||
|
var promises = [];
|
||||||
// var $doc = doc.documentElement;
|
// var $doc = doc.documentElement;
|
||||||
// var $body = doc.body;//view.document.querySelector("body");
|
// var $body = doc.body;//view.document.querySelector("body");
|
||||||
|
|
||||||
// $doc.style.overflow = "hidden";
|
// $doc.style.overflow = "hidden";
|
||||||
contents.overflow("hidden");
|
promises.push(contents.overflow("hidden"));
|
||||||
|
|
||||||
// Must be set to the new calculated width or the columns will be off
|
// Must be set to the new calculated width or the columns will be off
|
||||||
// $body.style.width = this.width + "px";
|
// $body.style.width = this.width + "px";
|
||||||
// $doc.style.width = this.width + "px";
|
// $doc.style.width = this.width + "px";
|
||||||
contents.width(this.width);
|
promises.push(contents.width(this.width));
|
||||||
|
|
||||||
//-- Adjust height
|
//-- Adjust height
|
||||||
// $body.style.height = this.height + "px";
|
// $body.style.height = this.height + "px";
|
||||||
contents.height(this.height);
|
promises.push(contents.height(this.height));
|
||||||
|
|
||||||
contents.css("margin", "0");
|
promises.push(contents.css("margin", "0"));
|
||||||
|
|
||||||
//-- Add columns
|
//-- Add columns
|
||||||
// $body.style[this.columnAxis] = "horizontal";
|
// $body.style[this.columnAxis] = "horizontal";
|
||||||
contents.css(this.columnAxis, "horizontal");
|
promises.push(contents.css(this.columnAxis, "horizontal"));
|
||||||
// $body.style[this.columnFill] = "auto";
|
// $body.style[this.columnFill] = "auto";
|
||||||
contents.css(this.columnFill, "auto");
|
promises.push(contents.css(this.columnFill, "auto"));
|
||||||
// $body.style[this.columnGap] = this.gap+"px";
|
// $body.style[this.columnGap] = this.gap+"px";
|
||||||
contents.css(this.columnGap, this.gap+"px");
|
promises.push(contents.css(this.columnGap, this.gap+"px"));
|
||||||
// $body.style[this.columnWidth] = this.column +"px";
|
// $body.style[this.columnWidth] = this.column +"px";
|
||||||
contents.css(this.columnWidth, this.column+"px");
|
promises.push(contents.css(this.columnWidth, this.column+"px"));
|
||||||
|
|
||||||
// Add extra padding for the gap between this and the next view
|
// Add extra padding for the gap between this and the next view
|
||||||
// view.iframe.style.marginRight = this.gap+"px";
|
// view.iframe.style.marginRight = this.gap+"px";
|
||||||
|
return RSVP.all(promises);
|
||||||
};
|
};
|
||||||
|
|
||||||
Reflowable.prototype.count = function(totalWidth) {
|
Reflowable.prototype.count = function(totalWidth) {
|
||||||
|
@ -120,6 +122,7 @@ Fixed.prototype.calculate = function(_width, _height){
|
||||||
};
|
};
|
||||||
|
|
||||||
Fixed.prototype.format = function(contents){
|
Fixed.prototype.format = function(contents){
|
||||||
|
var promises = [];
|
||||||
var viewport = contents.viewport();
|
var viewport = contents.viewport();
|
||||||
// var width, height;
|
// var width, height;
|
||||||
//
|
//
|
||||||
|
@ -145,16 +148,18 @@ Fixed.prototype.format = function(contents){
|
||||||
// $doc.style.width = width + "px" || "auto";
|
// $doc.style.width = width + "px" || "auto";
|
||||||
// $doc.style.height = height + "px" || "auto";
|
// $doc.style.height = height + "px" || "auto";
|
||||||
if (viewport.width) {
|
if (viewport.width) {
|
||||||
contents.width(viewport.width);
|
promises.push(contents.width(viewport.width));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (viewport.height) {
|
if (viewport.height) {
|
||||||
contents.height(viewport.height);
|
promises.push(contents.height(viewport.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- Scroll
|
//-- Scroll
|
||||||
// $doc.style.overflow = "auto";
|
// $doc.style.overflow = "auto";
|
||||||
contents.overflow("auto");
|
promises.push(contents.overflow("auto"));
|
||||||
|
|
||||||
|
return RSVP.all(promises);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -181,13 +186,15 @@ Scroll.prototype.calculate = function(_width, _height){
|
||||||
};
|
};
|
||||||
|
|
||||||
Scroll.prototype.format = function(contents){
|
Scroll.prototype.format = function(contents){
|
||||||
|
var promises = [];
|
||||||
// var $doc = doc.documentElement;
|
// var $doc = doc.documentElement;
|
||||||
|
|
||||||
// $doc.style.width = "auto";
|
// $doc.style.width = "auto";
|
||||||
// $doc.style.height = "auto";
|
// $doc.style.height = "auto";
|
||||||
// contents.width("auto");
|
// contents.width("auto");
|
||||||
contents.height("auto");
|
promises.push(contents.height("auto"));
|
||||||
|
|
||||||
|
return RSVP.all(promises);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -66,15 +66,6 @@ function Rendition(book, options) {
|
||||||
this.replacements();
|
this.replacements();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ViewManager = this.requireManager(this.settings.manager);
|
|
||||||
this.View = this.requireView(this.settings.view);
|
|
||||||
|
|
||||||
this.manager = new this.ViewManager({
|
|
||||||
view: this.View,
|
|
||||||
queue: this.q,
|
|
||||||
settings: this.settings
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Rendition.prototype.setManager = function(manager) {
|
Rendition.prototype.setManager = function(manager) {
|
||||||
|
@ -88,7 +79,7 @@ Rendition.prototype.requireManager = function(manager) {
|
||||||
// or require included managers directly
|
// or require included managers directly
|
||||||
if (typeof manager === "string") {
|
if (typeof manager === "string") {
|
||||||
// Use global or require
|
// Use global or require
|
||||||
viewManager = typeof ePub != "undefined" ? ePub.ViewManagers[manager] : require('./managers/'+manager);
|
viewManager = typeof ePub != "undefined" ? ePub.ViewManagers[manager] : undefined; //require('./managers/'+manager);
|
||||||
} else {
|
} else {
|
||||||
// otherwise, assume we were passed a function
|
// otherwise, assume we were passed a function
|
||||||
viewManager = manager
|
viewManager = manager
|
||||||
|
@ -103,7 +94,7 @@ Rendition.prototype.requireView = function(view) {
|
||||||
// If view is a string, try to load from register managers,
|
// If view is a string, try to load from register managers,
|
||||||
// or require included managers directly
|
// or require included managers directly
|
||||||
if (typeof view == "string") {
|
if (typeof view == "string") {
|
||||||
View = typeof ePub != "undefined" ? ePub.Views[view] : require('./views/'+view);
|
View = typeof ePub != "undefined" ? ePub.Views[view] : undefined; //require('./views/'+view);
|
||||||
} else {
|
} else {
|
||||||
// otherwise, assume we were passed a function
|
// otherwise, assume we were passed a function
|
||||||
View = view
|
View = view
|
||||||
|
@ -114,6 +105,17 @@ Rendition.prototype.requireView = function(view) {
|
||||||
|
|
||||||
Rendition.prototype.start = function(){
|
Rendition.prototype.start = function(){
|
||||||
|
|
||||||
|
if(!this.manager) {
|
||||||
|
this.ViewManager = this.requireManager(this.settings.manager);
|
||||||
|
this.View = this.requireView(this.settings.view);
|
||||||
|
|
||||||
|
this.manager = new this.ViewManager({
|
||||||
|
view: this.View,
|
||||||
|
queue: this.q,
|
||||||
|
settings: this.settings
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Listen for displayed views
|
// Listen for displayed views
|
||||||
this.manager.on("added", this.afterDisplayed.bind(this))
|
this.manager.on("added", this.afterDisplayed.bind(this))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue