From 2ec9a469649636c54977e9e1bfa04a493813b1a2 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 29 Jun 2018 14:51:34 +0300 Subject: toc-related stuff --- read.html | 74 +++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 19 deletions(-) (limited to 'read.html') diff --git a/read.html b/read.html index 30e6615..9cc523f 100644 --- a/read.html +++ b/read.html @@ -594,10 +594,10 @@ var a = $("") .attr('href', '#') .html(row.label + " " + - book.pagination.pageFromCfi(row.cfi) + "") - .attr('data-cfi', row.cfi) - .click(function() { - book.gotoCfi(a.attr('data-cfi')); + "FIXME" + "") + .attr('data-href', row.href) + .click(function() { + book.rendition.display(a.attr('data-href')); }); sublist.append($("
  • ").append(a)); @@ -610,7 +610,7 @@ } } - book.getToc().then(function(toc) { + var toc = book.navigation.toc; var list = $(".toc_list"); list.html(""); @@ -622,10 +622,10 @@ var a = $("") .attr('href', '#') .html(row.label + " " + - book.pagination.pageFromCfi(row.cfi) + "") - .attr('data-cfi', row.cfi) - .click(function() { - book.gotoCfi(a.attr('data-cfi')); + "FIXME" + "") + .attr('data-href', row.href) + .click(function() { + book.rendition.display(a.attr('data-href')); }); list.append($("
  • ").append(a)); @@ -660,16 +660,8 @@ } }); - }) - - /*rendition.hooks.unloaded.register(function() { - console.log('unloaded'); - - $(".loading").show(); - $(".loading_message").html("Opening chapter..."); - });*/ - book.on("renderer:chapterDisplayed", function() { + /*book.on("renderer:chapterDisplayed", function() { $(".chapter").html(""); localforage.getItem("epube.disable-transitions").then(function(notransitions) { @@ -716,7 +708,7 @@ console.log('toc', toc_entry); if (toc_entry) $(".chapter").html(toc_entry.label); - }); + }); */ book.ready.then(function() { @@ -825,6 +817,50 @@ rendition.on("keyup", hotkey_handler); + rendition.on('rendered', function(chapter) { + $(".chapter").html(""); + + try { + + var cur_href = book.canonical(book.rendition.currentLocation().start.href); + var toc_entry = false; + + function iterate_sublist(row, nest) { + if (nest == 3) return false; + + if (row.subitems) { + $.each(row.subitems, function (i, r) { + + if (book.spine.get(r.href).canonical == cur_href) { + toc_entry = r; + return true; + } + + if (iterate_sublist(r, nest + 1)) + return true; + }); + } + + return false; + } + + $.each(book.navigation.toc, function(i, a) { + if (book.spine.get(a.href).canonical == cur_href) { + toc_entry = a; + return; + } + + if (iterate_sublist(a, 0)) return; + + }); + + if (toc_entry) $(".chapter").html(toc_entry.label); + + } catch (e) { + console.warn(e); + } + }); + rendition.on('relocated', function(location) { var currentCfi = location.start.cfi; -- cgit v1.2.3