summaryrefslogtreecommitdiff
path: root/read.html
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-06-29 14:51:34 +0300
committerAndrew Dolgov <[email protected]>2018-06-29 14:51:34 +0300
commit2ec9a469649636c54977e9e1bfa04a493813b1a2 (patch)
treea6fde4dd9445326658d5b45fa59940372c9523cc /read.html
parent9d8ca2924f83b481162291ccebc2c48d9d538c54 (diff)
toc-related stuff
Diffstat (limited to 'read.html')
-rw-r--r--read.html74
1 files changed, 55 insertions, 19 deletions
diff --git a/read.html b/read.html
index 30e6615..9cc523f 100644
--- a/read.html
+++ b/read.html
@@ -594,10 +594,10 @@
var a = $("<a>")
.attr('href', '#')
.html(row.label + " <b class='pull-right'>" +
- book.pagination.pageFromCfi(row.cfi) + "</b>")
- .attr('data-cfi', row.cfi)
- .click(function() {
- book.gotoCfi(a.attr('data-cfi'));
+ "FIXME" + "</b>")
+ .attr('data-href', row.href)
+ .click(function() {
+ book.rendition.display(a.attr('data-href'));
});
sublist.append($("<li>").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 = $("<a>")
.attr('href', '#')
.html(row.label + " <b class='pull-right'>" +
- book.pagination.pageFromCfi(row.cfi) + "</b>")
- .attr('data-cfi', row.cfi)
- .click(function() {
- book.gotoCfi(a.attr('data-cfi'));
+ "FIXME" + "</b>")
+ .attr('data-href', row.href)
+ .click(function() {
+ book.rendition.display(a.attr('data-href'));
});
list.append($("<li>").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;