mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Added error handles, sections, updated url resolving, use book.request for requests
This commit is contained in:
parent
c6465177c5
commit
c29e5f84ee
19 changed files with 3049 additions and 683 deletions
|
@ -6,7 +6,7 @@ EPUBJS.Book = function(_url){
|
|||
|
||||
this.url = undefined;
|
||||
|
||||
this.spine = undefined;
|
||||
this.spine = new EPUBJS.Spine(this.request);
|
||||
|
||||
this.loading = {
|
||||
manifest: new RSVP.defer(),
|
||||
|
@ -32,6 +32,8 @@ EPUBJS.Book = function(_url){
|
|||
this.isRendered = false;
|
||||
this._q = EPUBJS.core.queue(this);
|
||||
|
||||
this.request = this.requestMethod.bind(this);
|
||||
|
||||
if(_url) {
|
||||
this.open(_url);
|
||||
}
|
||||
|
@ -45,6 +47,11 @@ EPUBJS.Book.prototype.open = function(_url){
|
|||
var containerPath = "META-INF/container.xml";
|
||||
var location;
|
||||
|
||||
if(!_url) {
|
||||
this.opening.resolve(this);
|
||||
return this.opened;
|
||||
}
|
||||
|
||||
// Reuse parsed url or create a new uri object
|
||||
if(typeof(_url) === "object") {
|
||||
uri = _url;
|
||||
|
@ -133,7 +140,7 @@ EPUBJS.Book.prototype.unpack = function(packageXml){
|
|||
book.package = parse.packageContents(packageXml); // Extract info from contents
|
||||
book.package.baseUrl = book.url; // Provides a url base for resolving paths
|
||||
|
||||
book.spine = new EPUBJS.Spine(book.package, this.request);
|
||||
this.spine.load(book.package);
|
||||
|
||||
book.navigation = new EPUBJS.Navigation(book.package, this.request);
|
||||
book.navigation.load().then(function(toc){
|
||||
|
@ -160,20 +167,23 @@ EPUBJS.Book.prototype.renderTo = function(element, options) {
|
|||
return rendition;
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.request = function(_url) {
|
||||
EPUBJS.Book.prototype.requestMethod = function(_url) {
|
||||
// Switch request methods
|
||||
if(this.archived) {
|
||||
// TODO: handle archived
|
||||
} else {
|
||||
return EPUBJS.core.request(_url, 'xml', this.credentials);
|
||||
return EPUBJS.core.request(_url, 'xml', this.requestCredentials, this.requestHeaders);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.setCredentials = function(_credentials) {
|
||||
this.credentials = _credentials;
|
||||
EPUBJS.Book.prototype.setRequestCredentials = function(_credentials) {
|
||||
this.requestCredentials = _credentials;
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.setRequestHeaders = function(_headers) {
|
||||
this.requestHeaders = _headers;
|
||||
};
|
||||
//-- Enable binding events to book
|
||||
RSVP.EventTarget.mixin(EPUBJS.Book.prototype);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue