1
0
Fork 0
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:
Fred Chasen 2013-01-26 14:33:44 -08:00
parent d6dfbab3ff
commit 3c151efdb5
3 changed files with 22 additions and 57 deletions

View file

@ -25,7 +25,6 @@ FPR.app.init = (function($){
}
Book = new FP.Book("area");
//Book = new FP.Book("area", "/the-hound-of-the-baskervilles/");
Book.listen("book:metadataReady", meta);
Book.listen("book:tocReady", toc);
@ -33,7 +32,6 @@ FPR.app.init = (function($){
Book.listen("book:online", goOnline);
Book.listen("book:offline", goOffline);
//Book.setFootnotes(["glossterm", "footnote"]);//["glossterm", "footnote"]);
Book.start(bookURL + "/");
@ -67,33 +65,6 @@ FPR.app.init = (function($){
$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){
var $subitems,
$wrapper = $("<li id='toc-"+item.id+"'>"),
$item = $("<a href='"+item.href+"'>"+item.label+"</a>");
$item.data("spinepos", item.spinePos);
if(item.section) {
$item.data("section", item.section);
}
$item = $("<a href='#"+item.href+"' data-url='"+item.href+"'>"+item.label+"</a>");
$item.on("click", function(e){
var $this = $(this),
url = $this.attr("href");
url = $this.data("url");
//spinepos = $this.data("spinepos"),
//section = $this.data("section") || false;

View file

@ -77,9 +77,9 @@ FP.Book.prototype.start = function(bookUrl){
this.bookUrl = bookUrl;
if(this.bookUrl.search(window.location.origin) == -1){
if(this.bookUrl.search("://") == -1){
//-- 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
@ -139,7 +139,7 @@ FP.Book.prototype.isSaved = function(force) {
this.spineIndexByURL = JSON.parse(localStorage.getItem("spineIndexByURL"));
this.toc = JSON.parse(localStorage.getItem("toc"));
if(!this.assets || !this.spine){
if(!this.assets || !this.spine || !this.spineIndexByURL || !this.toc){
this.stored = 0;
return false;
}
@ -314,8 +314,8 @@ FP.Book.prototype.parseTOC = function(path){
that.toc.push({
"id": coverID,
"href": that.assets[coverID],
"label": coverID,
"spinePos": parseInt(that.spineIndexByID[coverID])
"label": coverID
});
}
@ -330,9 +330,9 @@ FP.Book.prototype.parseTOC = function(path){
content = item.querySelector("content"),
src = content.getAttribute('src'), //that.assets[id],
split = src.split("#"),
href = that.basePath + split[0],
hash = split[1] || false,
spinePos = parseInt(that.spineIndexByID[id] || that.spineIndexByURL[href]),
//href = that.basePath + split[0],
//hash = split[1] || false,
//spinePos = parseInt(that.spineIndexByID[id] || that.spineIndexByURL[href]),
navLabel = item.querySelector("navLabel"),
text = navLabel.textContent ? navLabel.textContent : "",
subitems = item.querySelectorAll("navPoint") || false,
@ -349,8 +349,8 @@ FP.Book.prototype.parseTOC = function(path){
"id": id,
"href": src,
"label": text,
"spinePos": spinePos,
"section" : hash || false,
//"spinePos": spinePos,
//"section" : hash || false,
"subitems" : subs || false
});
@ -390,7 +390,7 @@ FP.Book.prototype.getCreator = 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(){
@ -412,14 +412,14 @@ FP.Book.prototype.show = function(url){
var split = url.split("#"),
chapter = split[0],
section = split[1] || false,
absoluteURL = this.basePath + chapter,
spinePos = this.spineIndexByURL[absoluteURL] || false;
absoluteURL = (chapter.search("://") == -1) ? this.basePath + chapter : chapter,
spinePos = this.spineIndexByURL[absoluteURL];
if(!chapter){
spinePos = this.spinePos;
}
if(!spinePos) return false;
if(typeof(spinePos) != "number") return false;
if(spinePos != this.spinePos){
this.displayChapter(spinePos, function(chap){

View file

@ -18,7 +18,7 @@
"use strict";
var FP = FP || {};
FP.VERSION = 0.1;
FP.VERSION = "0.1";
document.onreadystatechange = function () {
if (document.readyState == "complete") {