1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

basic scrolling renderer

This commit is contained in:
Fred Chasen 2014-07-31 17:25:56 -04:00
parent 849625fc83
commit b1b98f9d57
15 changed files with 1020 additions and 22 deletions

View file

@ -2,6 +2,7 @@ EPUBJS.Book = function(_url){
// Promises
this.opening = new RSVP.defer();
this.opened = this.opening.promise;
this.isOpen = false;
this.url = undefined;
@ -25,17 +26,11 @@ EPUBJS.Book = function(_url){
pageList: this.loading.pageList.promise
};
this.loaders = [];
for(var promise in this.loaded){
this.loaders.push(this.loaded[promise]);
}
this.ready = RSVP.hash(this.loaded);
this.ready = RSVP.all(this.loaders);
// this.pageList = [];
// this.ready.all.then(this._ready.bind(this));
// Queue for methods used before opening
this.isRendered = false;
this._q = EPUBJS.core.queue(this);
if(_url) {
this.open(_url);
@ -48,6 +43,7 @@ EPUBJS.Book.prototype.open = function(_url){
var epubPackage;
var book = this;
var containerPath = "META-INF/container.xml";
var location;
// Reuse parsed url or create a new uri object
if(typeof(_url) === "object") {
@ -64,6 +60,9 @@ EPUBJS.Book.prototype.open = function(_url){
if(uri.origin) {
this.url = uri.origin + "/" + uri.directory;
} else if(window){
location = EPUBJS.core.uri(window.location.href);
this.url = EPUBJS.core.resolveUrl(location.base, uri.directory);
} else {
this.url = uri.directory;
}
@ -111,11 +110,13 @@ EPUBJS.Book.prototype.open = function(_url){
book.loading.spine.resolve(book.spine);
book.loading.cover.resolve(book.cover);
// Resolve book opened promise
book.opening.resolve(book);
this.isOpen = true;
// Clear queue of any waiting book request
// Resolve book opened promise
book.opening.resolve(book);
}).catch(function(error) {
// handle errors in parsing the book
console.error(error.message, error.stack);
@ -152,6 +153,13 @@ EPUBJS.Book.prototype.section = function(target) {
return this.spine.get(target);
};
// Sugar to render a book
EPUBJS.Book.prototype.renderTo = function(element, options) {
var rendition = new EPUBJS.Renderer(this, options);
rendition.attachTo(element);
return rendition;
};
EPUBJS.Book.prototype.request = function(_url) {
// Switch request methods
if(this.archived) {