1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +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

79
dist/epub.js vendored
View file

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

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

View file

@ -56,7 +56,12 @@ function Book(_url, options){
this.locations = new Locations(this.spine, this.request); this.locations = new Locations(this.spine, this.request);
if(_url) { 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() + "/"; 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)) { } else if(isArrayBuffer || isBase64 || this.isArchivedUrl(uri)) {
// Book is archived // Book is archived
@ -124,8 +132,10 @@ Book.prototype.open = function(_url, options){
epubContainer = this.unarchive(_url, isBase64). epubContainer = this.unarchive(_url, isBase64).
then(function() { then(function() {
return this.request(this.containerUrl); 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 // Find the path to the Package from the container
else if (!uri.suffix()) { else if (!uri.suffix()) {
@ -166,13 +176,16 @@ Book.prototype.open = function(_url, options){
return book.request(book.packageUrl); return book.request(book.packageUrl);
}).catch(function(error) { }).catch(function(error) {
// handle errors in either of the two requests // 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); book.opening.reject(error);
}); });
} }
epubPackage.then(function(packageXml) { epubPackage.then(function(packageXml) {
if (!packageXml) {
return;
}
// Get package information from epub opf // Get package information from epub opf
book.unpack(packageXml); book.unpack(packageXml);
@ -191,7 +204,7 @@ Book.prototype.open = function(_url, options){
}).catch(function(error) { }).catch(function(error) {
// handle errors in parsing the book // handle errors in parsing the book
console.error(error.message, error.stack); // console.error(error.message, error.stack);
book.opening.reject(error); book.opening.reject(error);
}); });

View file

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

View file

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

View file

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

View file

@ -90,6 +90,16 @@ function request(url, type, withCredentials, headers) {
return deferred.promise; 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') if((this.responseType == '' || this.responseType == 'document')
&& this.responseXML){ && this.responseXML){
r = 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 bounds;
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 false, inherit them from containing element // If width or height are set to false, inherit them from containing element
if(width === null) { 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(); bounds = this.container.getBoundingClientRect();
width = bounds.width; width = bounds.width;
//height = bounds.height; //height = bounds.height;
} }
if(height && !core.isNumber(height)) { if(!core.isNumber(height)) {
bounds = bounds || this.container.getBoundingClientRect(); bounds = bounds || this.container.getBoundingClientRect();
//width = bounds.width; //width = bounds.width;
height = bounds.height; height = bounds.height;
@ -167,6 +167,7 @@ Stage.prototype.size = function(_width, _height){
this.containerStyles = window.getComputedStyle(this.container); this.containerStyles = window.getComputedStyle(this.container);
this.containerPadding = { this.containerPadding = {
left: parseFloat(this.containerStyles["padding-left"]) || 0, left: parseFloat(this.containerStyles["padding-left"]) || 0,
right: parseFloat(this.containerStyles["padding-right"]) || 0, right: parseFloat(this.containerStyles["padding-right"]) || 0,
@ -186,7 +187,13 @@ Stage.prototype.size = function(_width, _height){
}; };
Stage.prototype.bounds = function(){ Stage.prototype.bounds = function(){
if(!this.container) {
return core.windowBounds();
} else {
return this.container.getBoundingClientRect(); return this.container.getBoundingClientRect();
}
} }
Stage.prototype.getSheet = function(){ Stage.prototype.getSheet = function(){