mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
added hash changes
This commit is contained in:
parent
954aba9627
commit
1554dda914
4 changed files with 48 additions and 10 deletions
|
@ -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){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue