1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

Load fail error, fix scrolled-doc layout

This commit is contained in:
Fred Chasen 2016-09-23 14:38:59 +02:00
parent bef15e3af2
commit 0889e63a29
9 changed files with 130 additions and 61 deletions

77
dist/epub.js vendored
View file

@ -5485,7 +5485,12 @@ function Book(_url, options){
this.locations = new Locations(this.spine, this.request);
if(_url) {
this.open(_url);
this.open(_url).catch(function (error) {
var err = new Error("Cannot load book at "+ _url );
console.error(err);
this.trigger("loadFailed", error);
}.bind(this));
}
};
@ -5543,7 +5548,10 @@ Book.prototype.open = function(_url, options){
this.baseUrl = uri.directory() + "/";
}
epubPackage = this.request(this.packageUrl);
epubPackage = this.request(this.packageUrl)
.catch(function(error) {
book.opening.reject(error);
});
} else if(isArrayBuffer || isBase64 || this.isArchivedUrl(uri)) {
// Book is archived
@ -5553,8 +5561,10 @@ Book.prototype.open = function(_url, options){
epubContainer = this.unarchive(_url, isBase64).
then(function() {
return this.request(this.containerUrl);
}.bind(this));
}.bind(this))
.catch(function(error) {
book.opening.reject(error);
});
}
// Find the path to the Package from the container
else if (!uri.suffix()) {
@ -5595,13 +5605,16 @@ Book.prototype.open = function(_url, options){
return book.request(book.packageUrl);
}).catch(function(error) {
// handle errors in either of the two requests
console.error("Could not load book at: " + (this.packageUrl || this.containerPath));
book.trigger("book:loadFailed", (this.packageUrl || this.containerPath));
book.opening.reject(error);
});
}
epubPackage.then(function(packageXml) {
if (!packageXml) {
return;
}
// Get package information from epub opf
book.unpack(packageXml);
@ -5620,7 +5633,7 @@ Book.prototype.open = function(_url, options){
}).catch(function(error) {
// handle errors in parsing the book
console.error(error.message, error.stack);
// console.error(error.message, error.stack);
book.opening.reject(error);
});
@ -6343,9 +6356,8 @@ Contents.prototype.size = function(width, height){
this.height(height);
}
// if (width >= 0 && height >= 0) {
// this.overflow("hidden");
// }
this.css("margin", "0");
this.css("boxSizing", "border-box");
};
@ -7211,6 +7223,10 @@ EpubCFI.prototype.getCharecterOffsetComponent = function(cfiStr) {
};
EpubCFI.prototype.joinSteps = function(steps) {
if(!steps) {
return "";
}
return steps.map(function(part){
var segment = '';
@ -9328,11 +9344,7 @@ SingleViewManager.prototype.onScroll = function(){
SingleViewManager.prototype.bounds = function() {
var bounds;
if(!this.settings.height || !this.container) {
bounds = core.windowBounds();
} else {
bounds = this.stage.bounds();
}
return bounds;
};
@ -9349,12 +9361,15 @@ SingleViewManager.prototype.applyLayout = function(layout) {
SingleViewManager.prototype.updateLayout = function() {
var bounds;
if (this.stage) {
bound = this.stage.bounds();
if (!this.stage) {
return;
}
bounds = this.stage.size();
this.layout.calculate(bounds.width, bounds.height);
this.setLayout(this.layout);
}
};
@ -9379,6 +9394,7 @@ SingleViewManager.prototype.updateFlow = function(flow){
this.viewSettings.axis = axis;
this.settings.overflow = (flow === "paginated") ? "hidden" : "auto";
// this.views.each(function(view){
// view.setAxis(axis);
// });
@ -11259,6 +11275,16 @@ function request(url, type, withCredentials, headers) {
return deferred.promise;
}
if (this.status === 403) {
deferred.reject({
status: this.status,
response: this.response,
message : "Forbidden",
stack : new Error().stack
});
return deferred.promise;
}
if((this.responseType == '' || this.responseType == 'document')
&& this.responseXML){
r = this.responseXML;
@ -11735,10 +11761,10 @@ Stage.prototype.onResize = function(func){
};
Stage.prototype.size = function(_width, _height){
Stage.prototype.size = function(width, height){
var bounds;
var width = _width || this.settings.width;
var height = _height || this.settings.height;
// var width = _width || this.settings.width;
// var height = _height || this.settings.height;
// If width or height are set to false, inherit them from containing element
if(width === null) {
@ -11760,13 +11786,13 @@ Stage.prototype.size = function(_width, _height){
}
if(width && !core.isNumber(width)) {
if(!core.isNumber(width)) {
bounds = this.container.getBoundingClientRect();
width = bounds.width;
//height = bounds.height;
}
if(height && !core.isNumber(height)) {
if(!core.isNumber(height)) {
bounds = bounds || this.container.getBoundingClientRect();
//width = bounds.width;
height = bounds.height;
@ -11774,6 +11800,7 @@ Stage.prototype.size = function(_width, _height){
this.containerStyles = window.getComputedStyle(this.container);
this.containerPadding = {
left: parseFloat(this.containerStyles["padding-left"]) || 0,
right: parseFloat(this.containerStyles["padding-right"]) || 0,
@ -11793,9 +11820,15 @@ Stage.prototype.size = function(_width, _height){
};
Stage.prototype.bounds = function(){
if(!this.container) {
return core.windowBounds();
} else {
return this.container.getBoundingClientRect();
}
}
Stage.prototype.getSheet = function(){
var style = document.createElement("style");

2
dist/epub.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -20,10 +20,10 @@
overflow: hidden;
width: 800px;
margin: 0 auto;
position: relative;
}
#viewer .epub-view {
#viewer .epub-container {
background: white;
box-shadow: 0 0 4px #ccc;
margin: 10px;
@ -61,8 +61,11 @@
<script>
var currentSectionIndex = 8;
// Load the opf
var book = ePub("../books/alice/OPS/package.opf");
var rendition = book.renderTo("viewer", { view: "inline" });
var book = ePub("https://s3.amazonaws.com/epubjs/books/alice/OPS/package.opf");
var rendition = book.renderTo("viewer", {
manager: "single",
flow: "scrolled-doc",
});
rendition.display("chapter_008.xhtml");

View file

@ -56,7 +56,12 @@ function Book(_url, options){
this.locations = new Locations(this.spine, this.request);
if(_url) {
this.open(_url);
this.open(_url).catch(function (error) {
var err = new Error("Cannot load book at "+ _url );
console.error(err);
this.trigger("loadFailed", error);
}.bind(this));
}
};
@ -114,7 +119,10 @@ Book.prototype.open = function(_url, options){
this.baseUrl = uri.directory() + "/";
}
epubPackage = this.request(this.packageUrl);
epubPackage = this.request(this.packageUrl)
.catch(function(error) {
book.opening.reject(error);
});
} else if(isArrayBuffer || isBase64 || this.isArchivedUrl(uri)) {
// Book is archived
@ -124,8 +132,10 @@ Book.prototype.open = function(_url, options){
epubContainer = this.unarchive(_url, isBase64).
then(function() {
return this.request(this.containerUrl);
}.bind(this));
}.bind(this))
.catch(function(error) {
book.opening.reject(error);
});
}
// Find the path to the Package from the container
else if (!uri.suffix()) {
@ -166,13 +176,16 @@ Book.prototype.open = function(_url, options){
return book.request(book.packageUrl);
}).catch(function(error) {
// handle errors in either of the two requests
console.error("Could not load book at: " + (this.packageUrl || this.containerPath));
book.trigger("book:loadFailed", (this.packageUrl || this.containerPath));
book.opening.reject(error);
});
}
epubPackage.then(function(packageXml) {
if (!packageXml) {
return;
}
// Get package information from epub opf
book.unpack(packageXml);
@ -191,7 +204,7 @@ Book.prototype.open = function(_url, options){
}).catch(function(error) {
// handle errors in parsing the book
console.error(error.message, error.stack);
// console.error(error.message, error.stack);
book.opening.reject(error);
});

View file

@ -578,9 +578,8 @@ Contents.prototype.size = function(width, height){
this.height(height);
}
// if (width >= 0 && height >= 0) {
// this.overflow("hidden");
// }
this.css("margin", "0");
this.css("boxSizing", "border-box");
};

View file

@ -239,6 +239,10 @@ EpubCFI.prototype.getCharecterOffsetComponent = function(cfiStr) {
};
EpubCFI.prototype.joinSteps = function(steps) {
if(!steps) {
return "";
}
return steps.map(function(part){
var segment = '';

View file

@ -349,11 +349,7 @@ SingleViewManager.prototype.onScroll = function(){
SingleViewManager.prototype.bounds = function() {
var bounds;
if(!this.settings.height || !this.container) {
bounds = core.windowBounds();
} else {
bounds = this.stage.bounds();
}
return bounds;
};
@ -370,12 +366,15 @@ SingleViewManager.prototype.applyLayout = function(layout) {
SingleViewManager.prototype.updateLayout = function() {
var bounds;
if (this.stage) {
bound = this.stage.bounds();
if (!this.stage) {
return;
}
bounds = this.stage.size();
this.layout.calculate(bounds.width, bounds.height);
this.setLayout(this.layout);
}
};
@ -400,6 +399,7 @@ SingleViewManager.prototype.updateFlow = function(flow){
this.viewSettings.axis = axis;
this.settings.overflow = (flow === "paginated") ? "hidden" : "auto";
// this.views.each(function(view){
// view.setAxis(axis);
// });

View file

@ -90,6 +90,16 @@ function request(url, type, withCredentials, headers) {
return deferred.promise;
}
if (this.status === 403) {
deferred.reject({
status: this.status,
response: this.response,
message : "Forbidden",
stack : new Error().stack
});
return deferred.promise;
}
if((this.responseType == '' || this.responseType == 'document')
&& this.responseXML){
r = this.responseXML;

View file

@ -128,10 +128,10 @@ Stage.prototype.onResize = function(func){
};
Stage.prototype.size = function(_width, _height){
Stage.prototype.size = function(width, height){
var bounds;
var width = _width || this.settings.width;
var height = _height || this.settings.height;
// var width = _width || this.settings.width;
// var height = _height || this.settings.height;
// If width or height are set to false, inherit them from containing element
if(width === null) {
@ -153,13 +153,13 @@ Stage.prototype.size = function(_width, _height){
}
if(width && !core.isNumber(width)) {
if(!core.isNumber(width)) {
bounds = this.container.getBoundingClientRect();
width = bounds.width;
//height = bounds.height;
}
if(height && !core.isNumber(height)) {
if(!core.isNumber(height)) {
bounds = bounds || this.container.getBoundingClientRect();
//width = bounds.width;
height = bounds.height;
@ -167,6 +167,7 @@ Stage.prototype.size = function(_width, _height){
this.containerStyles = window.getComputedStyle(this.container);
this.containerPadding = {
left: parseFloat(this.containerStyles["padding-left"]) || 0,
right: parseFloat(this.containerStyles["padding-right"]) || 0,
@ -186,9 +187,15 @@ Stage.prototype.size = function(_width, _height){
};
Stage.prototype.bounds = function(){
if(!this.container) {
return core.windowBounds();
} else {
return this.container.getBoundingClientRect();
}
}
Stage.prototype.getSheet = function(){
var style = document.createElement("style");