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
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
|
@ -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 = $("<li id='toc-"+item.id+"'>"),
|
||||
$item = $("<a class='toc_link' href='#"+item.href+"' data-url='"+item.href+"'>"+item.label+"</a>");
|
||||
$item = $("<a class='toc_link' href='#/"+item.href+"' data-url='"+item.href+"'>"+item.label+"</a>");
|
||||
|
||||
$wrapper.append($item);
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ FP.Book = function(elem, bookPath){
|
|||
"beforeChapterDisplay" : []
|
||||
};
|
||||
|
||||
this.useHash = true;
|
||||
|
||||
this.initialize(this.el);
|
||||
|
||||
this.online = navigator.onLine;
|
||||
|
@ -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,6 +481,11 @@ FP.Book.prototype.startDisplay = function(){
|
|||
this.storeOffline();
|
||||
}
|
||||
|
||||
//-- Go to hashed page if present
|
||||
if(this.useHash){
|
||||
this.route();
|
||||
}
|
||||
|
||||
}.bind(this));
|
||||
|
||||
|
||||
|
@ -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){
|
||||
|
|
|
@ -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){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue