diff --git a/.DS_Store b/.DS_Store
index 0cd32da..c10b1a3 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/fpjs/reader/app.js b/fpjs/reader/app.js
index e230238..81a2f38 100644
--- a/fpjs/reader/app.js
+++ b/fpjs/reader/app.js
@@ -88,9 +88,12 @@ FPR.app.init = (function($){
//-- Provide the Book with the url to show
// The Url must be found in the books manifest
- Book.show(url);
- e.preventDefault();
+ if(!Book.useHash){
+ Book.show(url);
+ e.preventDefault();
+ }
+
});
}
@@ -102,7 +105,7 @@ FPR.app.init = (function($){
contents.forEach(function(item){
var $subitems,
$wrapper = $("
"),
- $item = $(""+item.label+"");
+ $item = $(""+item.label+"");
$wrapper.append($item);
diff --git a/fpjs/render/book.js b/fpjs/render/book.js
index f223b9d..77d8b6e 100644
--- a/fpjs/render/book.js
+++ b/fpjs/render/book.js
@@ -26,11 +26,13 @@ FP.Book = function(elem, bookPath){
"beforeChapterDisplay" : []
};
+ this.useHash = true;
+
this.initialize(this.el);
this.online = navigator.onLine;
this.listeners();
-
+
//-- Determine storage method
//-- Override options: none | ram | websql | indexedDB | filesystem
this.determineStorageMethod();
@@ -70,6 +72,9 @@ FP.Book.prototype.listeners = function(){
that.tell("book:online");
}, false);
+
+ window.addEventListener("hashchange", that.route.bind(this), false);
+
}
//-- Check bookUrl and start parsing book Assets or load them from storage
@@ -462,6 +467,8 @@ FP.Book.prototype.chapterTitle = function(){
FP.Book.prototype.startDisplay = function(){
this.tell("book:bookReady");
+
+
this.displayChapter(this.spinePos, function(chapter){
//-- If there is a saved page, and the pages haven't changed go to it
@@ -474,9 +481,14 @@ FP.Book.prototype.startDisplay = function(){
this.storeOffline();
}
+ //-- Go to hashed page if present
+ if(this.useHash){
+ this.route();
+ }
+
}.bind(this));
-
+
}
FP.Book.prototype.show = function(url){
@@ -634,6 +646,18 @@ FP.Book.prototype.determineStorageMethod = function(override) {
FP.storage.storageMethod(method);
}
+FP.Book.prototype.route = function(){
+ var location = window.location.hash.replace('#/', '');
+ if(this.useHash && location.length && location != this.prevLocation){
+ this.show(location);
+ this.prevLocation = location;
+ }
+}
+
+FP.Book.prototype.hideHashChanges = function(){
+ this.useHash = false;
+}
+
//-- Hooks allow for injecting async functions that must all complete before continuing
// Functions must have a callback as their first argument.
FP.Book.prototype.registerHook = function(type, toAdd){
diff --git a/fpjs/render/chapter.js b/fpjs/render/chapter.js
index 9ba462a..4501932 100644
--- a/fpjs/render/chapter.js
+++ b/fpjs/render/chapter.js
@@ -203,12 +203,17 @@ FP.Chapter.prototype.replaceLinks = function(callback){
links.forEach(function(link){
var path,
href = link.getAttribute("href"),
- relative = href.search("://");
+ relative = href.search("://"),
+ fragment = href[0] == "#";
if(relative != -1) return; //-- Only replace relative links
-
+
link.onclick = function(){
- that.book.show(href);
+ if(that.book.useHash){
+ window.location.hash = "#/"+href;
+ }else{
+ that.book.show(href);
+ }
}
});
@@ -266,10 +271,16 @@ FP.Chapter.prototype.page = function(pg){
//-- Find a section by fragement id
FP.Chapter.prototype.section = function(fragment){
var el = this.doc.getElementById(fragment),
+ left, pg;
+
+
+ if(el){
left = this.leftPos + el.offsetLeft, //-- Calculate left offset compaired to scrolled position
pg = Math.floor(left / this.spreadWidth) + 1; //-- pages start at 1
-
- this.page(pg);
+
+ this.page(pg);
+ }
+
}
FP.Chapter.prototype.beforeDisplay = function(callback){