Permalink
Browse files

add very preliminary ToC browser

  • Loading branch information...
1 parent 71d165d commit 5a34f057f9841f92642a85df1391dc1ceecd8103 @blaine committed Apr 13, 2010
Showing with 58 additions and 3 deletions.
  1. +14 −0 book.css
  2. +29 −0 index.html
  3. +9 −3 js/epub.js
  4. +6 −0 js/pageHandler.js
View
@@ -257,3 +257,17 @@ div#spinner {
div#spinner img {
margin: 34px;
}
+
+div#contents {
+ position: absolute;
+ left: 0;
+ top: 0;
+ height: 100%;
+ background-color: #eeeeff;
+ padding: 20px;
+ z-index: 100000;
+}
+
+div#contents a {
+ display: block;
+}
View
@@ -40,6 +40,28 @@
rn = document.getElementsByClassName('right pagenum')[0];
pageHandler = new PageHandler(book, [lc, rc], [ln, rn]);
+
+ var contents = document.getElementById('contents');
+ for (var i = 0, l = book.toc.length; i < l; i++) {
+
+ // Sometimes navpoints aren't all covered, or they are done so in weird ways.
+ // try to be liberal about things.
+ if (book.toc[i] === undefined) continue;
+
+ var chapter = document.createElement('a');
+ var secName = book.toc[i].fileName;
+ chapter.setAttribute('href', '#section=' + secName);
+ chapter.textContent = book.toc[i].title;
+ chapter.onclick = function (secName) {
+ return function () {
+ pageHandler.goToSection(secName);
+ pageHandler.display();
+ contents.style.display = 'none';
+ }
+ }(secName);
+ contents.appendChild(chapter);
+ }
+
pageHandler.display();
swipe(null, pageHandler);
@@ -54,6 +76,9 @@
case 39:
pageHandler.nextPage();
break;
+ case 67:
+ document.getElementById('contents').style.display = 'block';
+ break;
}
}
}
@@ -68,6 +93,10 @@
<div id="spinner">
<img src="loader.gif" alt="Loading" />
</div>
+
+ <div id="contents" style="display: none;">
+ </div>
+
<div id="selector">
<div style="text-align: center; font-family: Helvetica, sans; margin-top: 20px; background-color: rgba(255,255,255,0.3); line-height: 1.5em;">
<span style="color: #0000dd">r</span><span style="color: #4444ee">ePub</span><span style="color: #0000dd">lish</span> &#8212; Pure-JavaScript ePub Reader
View
@@ -27,6 +27,7 @@ var ePub = new function () {
this.author = opf.creator;
this.contents = opf.contents;
+ this.contentsByFile = opf.contentsByFile;
this.toc = opf.toc.contents;
};
@@ -75,13 +76,16 @@ var ePub = new function () {
var itemrefs = spine.querySelectorAll('itemref');
var il = itemrefs.length;
var contents = [];
+ var contentsByFile = {};
while (il--) {
var id = itemrefs[il].getAttribute('idref');
var file = this.getFileById(id);
contents.unshift(file);
+ contentsByFile[file.name] = file;
}
this.contents = contents;
+ this.contentsByFile = contentsByFile;
// Basic metadata. Needs some work.
this.title = opf.querySelector('title').textContent;
@@ -116,15 +120,17 @@ var ePub = new function () {
}
var point = {
- title: navpoints[i].querySelector('navLabel text').textContent,
- content: content
+ title: navpoints[i].querySelector('navLabel text').textContent,
+ fileName: file.name,
+ content: content
}
if (!file) {
// console.log("Couldn't find a file named " + src + " for section named " + point.title);
}
- contents[navpoints[i].getAttribute('playOrder')] = point;
+ var pos = navpoints[i].getAttribute('playOrder') - 1;
+ contents[navpoints[i].getAttribute('playOrder')-1] = point;
}
this.contents = contents;
View
@@ -120,6 +120,11 @@ var PageHandler = function (book, displayElements, pageNumbers, chapterName) {
}
};
+ this.goToSection = function (secName) {
+ currSection = this.sectionsByName[secName];
+ sections[currSection].seekBeginning();
+ };
+
/*
*
* The content collector. This uses the first displayElement as a template
@@ -189,6 +194,7 @@ var PageHandler = function (book, displayElements, pageNumbers, chapterName) {
var section = new Section(func);
this.sections.push(section);
+ this.sectionsByName[contentRef.name] = sections.length - 1;
return section;
};

0 comments on commit 5a34f05

Please sign in to comment.