mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
fixed spinePos to include 0
This commit is contained in:
parent
d6dfbab3ff
commit
3c151efdb5
3 changed files with 22 additions and 57 deletions
|
@ -25,7 +25,6 @@ FPR.app.init = (function($){
|
||||||
}
|
}
|
||||||
|
|
||||||
Book = new FP.Book("area");
|
Book = new FP.Book("area");
|
||||||
//Book = new FP.Book("area", "/the-hound-of-the-baskervilles/");
|
|
||||||
|
|
||||||
Book.listen("book:metadataReady", meta);
|
Book.listen("book:metadataReady", meta);
|
||||||
Book.listen("book:tocReady", toc);
|
Book.listen("book:tocReady", toc);
|
||||||
|
@ -33,7 +32,6 @@ FPR.app.init = (function($){
|
||||||
Book.listen("book:online", goOnline);
|
Book.listen("book:online", goOnline);
|
||||||
Book.listen("book:offline", goOffline);
|
Book.listen("book:offline", goOffline);
|
||||||
|
|
||||||
//Book.setFootnotes(["glossterm", "footnote"]);//["glossterm", "footnote"]);
|
|
||||||
|
|
||||||
Book.start(bookURL + "/");
|
Book.start(bookURL + "/");
|
||||||
|
|
||||||
|
@ -67,33 +65,6 @@ FPR.app.init = (function($){
|
||||||
|
|
||||||
$toc.append($items);
|
$toc.append($items);
|
||||||
|
|
||||||
// contents.forEach(function(item){
|
|
||||||
// $wrapper = $("<li id='toc-"+item.id+"'>");
|
|
||||||
//
|
|
||||||
// $item = $("<a href='#"+item.href+"' data-spinepos='"+item.spinePos+"'>"+item.label+"</a>");
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// $item.on("click", function(e){
|
|
||||||
// $this = $(this);
|
|
||||||
// Book.displayChapter($this.data("spinepos"));
|
|
||||||
// e.preventDefault();
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// $wrapper.append($item);
|
|
||||||
//
|
|
||||||
// if(item.subitems && item.subitems.length){
|
|
||||||
// $subitems = $("<ul>");
|
|
||||||
// item.subitems.forEach(function(subitem){
|
|
||||||
// //console.log("subitem", subitem)
|
|
||||||
// $subitem = $("<li id='toc-"+subitem.id+"'><a href='#"+subitem.href+"' data-spinepos='"+subitem.spinePos+"'>"+subitem.label+"</a></li>");
|
|
||||||
// $subitems.append($subitem);
|
|
||||||
// });
|
|
||||||
// $wrapper.append($subitems);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// $toc.append($wrapper);
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,17 +75,11 @@ FPR.app.init = (function($){
|
||||||
contents.forEach(function(item){
|
contents.forEach(function(item){
|
||||||
var $subitems,
|
var $subitems,
|
||||||
$wrapper = $("<li id='toc-"+item.id+"'>"),
|
$wrapper = $("<li id='toc-"+item.id+"'>"),
|
||||||
$item = $("<a href='"+item.href+"'>"+item.label+"</a>");
|
$item = $("<a href='#"+item.href+"' data-url='"+item.href+"'>"+item.label+"</a>");
|
||||||
|
|
||||||
$item.data("spinepos", item.spinePos);
|
|
||||||
|
|
||||||
if(item.section) {
|
|
||||||
$item.data("section", item.section);
|
|
||||||
}
|
|
||||||
|
|
||||||
$item.on("click", function(e){
|
$item.on("click", function(e){
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
url = $this.attr("href");
|
url = $this.data("url");
|
||||||
//spinepos = $this.data("spinepos"),
|
//spinepos = $this.data("spinepos"),
|
||||||
//section = $this.data("section") || false;
|
//section = $this.data("section") || false;
|
||||||
|
|
||||||
|
|
|
@ -77,9 +77,9 @@ FP.Book.prototype.start = function(bookUrl){
|
||||||
|
|
||||||
this.bookUrl = bookUrl;
|
this.bookUrl = bookUrl;
|
||||||
|
|
||||||
if(this.bookUrl.search(window.location.origin) == -1){
|
if(this.bookUrl.search("://") == -1){
|
||||||
//-- get full path
|
//-- get full path
|
||||||
this.bookUrl = window.location.origin + window.location.pathname + this.bookUrl;
|
this.bookUrl = window.location.origin + folder + this.bookUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- TODO: Check what storage types are available
|
//-- TODO: Check what storage types are available
|
||||||
|
@ -138,8 +138,8 @@ FP.Book.prototype.isSaved = function(force) {
|
||||||
this.spine = JSON.parse(localStorage.getItem("spine"));
|
this.spine = JSON.parse(localStorage.getItem("spine"));
|
||||||
this.spineIndexByURL = JSON.parse(localStorage.getItem("spineIndexByURL"));
|
this.spineIndexByURL = JSON.parse(localStorage.getItem("spineIndexByURL"));
|
||||||
this.toc = JSON.parse(localStorage.getItem("toc"));
|
this.toc = JSON.parse(localStorage.getItem("toc"));
|
||||||
|
|
||||||
if(!this.assets || !this.spine){
|
if(!this.assets || !this.spine || !this.spineIndexByURL || !this.toc){
|
||||||
this.stored = 0;
|
this.stored = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -307,15 +307,15 @@ FP.Book.prototype.parseTOC = function(path){
|
||||||
var navMap = contents.querySelector("navMap"),
|
var navMap = contents.querySelector("navMap"),
|
||||||
cover = contents.querySelector("meta[name='cover']"),
|
cover = contents.querySelector("meta[name='cover']"),
|
||||||
coverID;
|
coverID;
|
||||||
|
|
||||||
//-- Add cover
|
//-- Add cover
|
||||||
if(cover){
|
if(cover){
|
||||||
coverID = cover.getAttribute("content");
|
coverID = cover.getAttribute("content");
|
||||||
that.toc.push({
|
that.toc.push({
|
||||||
"id": coverID,
|
"id": coverID,
|
||||||
"href": that.assets[coverID],
|
"href": that.assets[coverID],
|
||||||
"label": coverID,
|
"label": coverID
|
||||||
"spinePos": parseInt(that.spineIndexByID[coverID])
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,9 +330,9 @@ FP.Book.prototype.parseTOC = function(path){
|
||||||
content = item.querySelector("content"),
|
content = item.querySelector("content"),
|
||||||
src = content.getAttribute('src'), //that.assets[id],
|
src = content.getAttribute('src'), //that.assets[id],
|
||||||
split = src.split("#"),
|
split = src.split("#"),
|
||||||
href = that.basePath + split[0],
|
//href = that.basePath + split[0],
|
||||||
hash = split[1] || false,
|
//hash = split[1] || false,
|
||||||
spinePos = parseInt(that.spineIndexByID[id] || that.spineIndexByURL[href]),
|
//spinePos = parseInt(that.spineIndexByID[id] || that.spineIndexByURL[href]),
|
||||||
navLabel = item.querySelector("navLabel"),
|
navLabel = item.querySelector("navLabel"),
|
||||||
text = navLabel.textContent ? navLabel.textContent : "",
|
text = navLabel.textContent ? navLabel.textContent : "",
|
||||||
subitems = item.querySelectorAll("navPoint") || false,
|
subitems = item.querySelectorAll("navPoint") || false,
|
||||||
|
@ -349,8 +349,8 @@ FP.Book.prototype.parseTOC = function(path){
|
||||||
"id": id,
|
"id": id,
|
||||||
"href": src,
|
"href": src,
|
||||||
"label": text,
|
"label": text,
|
||||||
"spinePos": spinePos,
|
//"spinePos": spinePos,
|
||||||
"section" : hash || false,
|
//"section" : hash || false,
|
||||||
"subitems" : subs || false
|
"subitems" : subs || false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ FP.Book.prototype.getCreator = function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
FP.Book.prototype.chapterTitle = function(){
|
FP.Book.prototype.chapterTitle = function(){
|
||||||
return this.spine[this.spinePos].id;
|
return this.spine[this.spinePos].id; //-- TODO: clarify that this is returning title
|
||||||
}
|
}
|
||||||
|
|
||||||
FP.Book.prototype.startDisplay = function(){
|
FP.Book.prototype.startDisplay = function(){
|
||||||
|
@ -412,14 +412,14 @@ FP.Book.prototype.show = function(url){
|
||||||
var split = url.split("#"),
|
var split = url.split("#"),
|
||||||
chapter = split[0],
|
chapter = split[0],
|
||||||
section = split[1] || false,
|
section = split[1] || false,
|
||||||
absoluteURL = this.basePath + chapter,
|
absoluteURL = (chapter.search("://") == -1) ? this.basePath + chapter : chapter,
|
||||||
spinePos = this.spineIndexByURL[absoluteURL] || false;
|
spinePos = this.spineIndexByURL[absoluteURL];
|
||||||
|
|
||||||
if(!chapter){
|
if(!chapter){
|
||||||
spinePos = this.spinePos;
|
spinePos = this.spinePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!spinePos) return false;
|
if(typeof(spinePos) != "number") return false;
|
||||||
|
|
||||||
if(spinePos != this.spinePos){
|
if(spinePos != this.spinePos){
|
||||||
this.displayChapter(spinePos, function(chap){
|
this.displayChapter(spinePos, function(chap){
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var FP = FP || {};
|
var FP = FP || {};
|
||||||
FP.VERSION = 0.1;
|
FP.VERSION = "0.1";
|
||||||
|
|
||||||
document.onreadystatechange = function () {
|
document.onreadystatechange = function () {
|
||||||
if (document.readyState == "complete") {
|
if (document.readyState == "complete") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue