Skip to content

Commit

Permalink
Added locations
Browse files Browse the repository at this point in the history
  • Loading branch information
fchasen committed Jul 9, 2015
1 parent d7371a6 commit 80787fc
Show file tree
Hide file tree
Showing 10 changed files with 648 additions and 125 deletions.
377 changes: 319 additions & 58 deletions dist/epub.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/epub.min.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions examples/spreads.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<script>
// Load the opf
// var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf");
var book = ePub("books/alice/OPS/package.opf");
var book = ePub("../books/alice/OPS/package.opf");
var rendition = book.renderTo("viewer", {
method: "paginate",
width: "100%",
Expand Down Expand Up @@ -148,7 +148,7 @@
rendition.prev();
}, false);

document.addEventListener("keyup", function(e){
var keyListener = function(e){

// Left Key
if ((e.keyCode || e.which) == 37) {
Expand All @@ -160,7 +160,10 @@
rendition.next();
}

}, false);
};

rendition.on("keyup", keyListener);
document.addEventListener("keyup", keyListener, false);


</script>
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var files = [
'src/rendition.js',
'src/continuous.js',
'src/paginate.js',
'src/map.js'
'src/map.js',
'src/locations.js'
];

// Lint JS
Expand Down
26 changes: 14 additions & 12 deletions src/book.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
EPUBJS.Book = function(_url){
EPUBJS.Book = function(_url, options){
// Promises
this.opening = new RSVP.defer();
this.opened = this.opening.promise;
this.isOpen = false;

this.url = undefined;

this.spine = new EPUBJS.Spine(this.request);

this.loading = {
manifest: new RSVP.defer(),
spine: new RSVP.defer(),
Expand All @@ -34,6 +32,9 @@ EPUBJS.Book = function(_url){

this.request = this.requestMethod.bind(this);

this.spine = new EPUBJS.Spine(this.request);
this.locations = new EPUBJS.Locations(this.spine, this.request);

if(_url) {
this.open(_url);
}
Expand Down Expand Up @@ -64,7 +65,7 @@ EPUBJS.Book.prototype.open = function(_url){
// Direct link to package, no container
this.packageUrl = uri.href;
this.containerUrl = '';

if(uri.origin) {
this.url = uri.base;
} else if(window){
Expand All @@ -82,9 +83,9 @@ EPUBJS.Book.prototype.open = function(_url){
this.url = '';
}

// Find the path to the Package from the container
// Find the path to the Package from the container
else if (!uri.extension) {

this.containerUrl = _url + containerPath;

epubPackage = this.request(this.containerUrl).
Expand All @@ -95,7 +96,7 @@ EPUBJS.Book.prototype.open = function(_url){
var packageUri = EPUBJS.core.uri(paths.packagePath);
book.packageUrl = _url + paths.packagePath;
book.encoding = paths.encoding;

// Set Url relative to the content
if(packageUri.origin) {
book.url = packageUri.base;
Expand All @@ -106,7 +107,7 @@ EPUBJS.Book.prototype.open = function(_url){
book.url = packageUri.directory;
}

return book.request(book.packageUrl);
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));
Expand Down Expand Up @@ -156,7 +157,7 @@ EPUBJS.Book.prototype.unpack = function(packageXml){
book.toc = toc;
book.loading.navigation.resolve(book.toc);
});

// //-- Set Global Layout setting based on metadata
// MOVE TO RENDER
// book.globalLayoutProperties = book.parseLayoutProperties(book.package.metadata);
Expand All @@ -171,7 +172,7 @@ EPUBJS.Book.prototype.section = function(target) {

// Sugar to render a book
EPUBJS.Book.prototype.renderTo = function(element, options) {
var renderer = (options && options.method) ?
var renderer = (options && options.method) ?
options.method.charAt(0).toUpperCase() + options.method.substr(1) :
"Rendition";

Expand All @@ -183,7 +184,7 @@ EPUBJS.Book.prototype.renderTo = function(element, options) {
EPUBJS.Book.prototype.requestMethod = function(_url) {
// Switch request methods
if(this.archived) {
// TODO: handle archived
// TODO: handle archived
} else {
return EPUBJS.core.request(_url, 'xml', this.requestCredentials, this.requestHeaders);
}
Expand All @@ -197,6 +198,7 @@ EPUBJS.Book.prototype.setRequestCredentials = function(_credentials) {
EPUBJS.Book.prototype.setRequestHeaders = function(_headers) {
this.requestHeaders = _headers;
};

//-- Enable binding events to book
RSVP.EventTarget.mixin(EPUBJS.Book.prototype);

Expand All @@ -211,4 +213,4 @@ RSVP.configure('instrument', true); //-- true | will logging out all RSVP reject
// RSVP.on('fulfilled', listener);
RSVP.on('rejected', function(event){
console.error(event.detail.message, event.detail.stack);
});
});
Loading

0 comments on commit 80787fc

Please sign in to comment.