1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

Update toc nav subitem parsing

This commit is contained in:
Fred Chasen 2017-10-31 18:27:26 -07:00
parent 4bbec4501d
commit 5f53b7223c
3 changed files with 110 additions and 56 deletions

View file

@ -102,14 +102,22 @@
var $nav = document.getElementById("toc"),
docfrag = document.createDocumentFragment();
toc.forEach(function(chapter, index) {
var processTocItem = function(chapter, parent) {
var item = document.createElement("li");
var link = document.createElement("a");
link.id = "chap-" + chapter.id;
link.textContent = chapter.label;
link.href = chapter.href;
item.appendChild(link);
docfrag.appendChild(item);
parent.appendChild(item);
if (chapter.subitems.length) {
var ul = document.createElement("ul");
item.appendChild(ul);
chapter.subitems.forEach(function(subchapter) {
processTocItem(subchapter, ul);
});
}
link.onclick = function(){
var url = link.getAttribute("href");
@ -118,6 +126,10 @@
return false;
};
}
toc.forEach(function(chapter) {
processTocItem(chapter, docfrag);
});
$nav.appendChild(docfrag);