summaryrefslogtreecommitdiff
path: root/read.html
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2017-02-27 18:26:31 +0300
committerAndrew Dolgov <[email protected]>2017-02-27 18:26:31 +0300
commit5f01164c809da30ae19ca009b6fdbe6f063e4a31 (patch)
treeb2c2cbdd015966a4175d0bee51b9d27a5f23dd4d /read.html
parent946564f7ff9a81fc76efdde294ab79dabf90794a (diff)
generate dummy toc when no usable one has been found
Diffstat (limited to 'read.html')
-rw-r--r--read.html46
1 files changed, 37 insertions, 9 deletions
diff --git a/read.html b/read.html
index a1e4942..aa29f15 100644
--- a/read.html
+++ b/read.html
@@ -373,17 +373,45 @@
$.each(toc, function(i, row) {
- var a = $("<a>")
- .attr('href', '#')
- .html(row.label)
+ // if anything fails here the toc entry is likely useless anyway (i.e. no cfi)
+ try {
+ var a = $("<a>")
+ .attr('href', '#')
+ .html(row.label + " <b>(Loc. " +
+ book.pagination.pageFromCfi(row.cfi) + ")</b>")
.attr('data-cfi', row.cfi)
- .attr('data-id', row.id)
- .click(function() {
- book.gotoCfi(a.attr('data-cfi'));
- });
-
- list.append($("<li>").append(a));
+ .click(function() {
+ book.gotoCfi(a.attr('data-cfi'));
+ });
+
+ list.append($("<li>").append(a));
+ } catch (e) {
+ console.warn(e);
+ }
});
+
+ // well the toc didn't work out, might as well generate one
+ if (list.children().length <= 1) {
+
+ list.html("");
+
+ $.each(book.spine, function (i, row) {
+
+ var a = $("<a>")
+ .attr('href', '#')
+ .attr('title', row.url)
+ .html("Section " + (i+1) + " <b>(Loc. " +
+ book.pagination.pageFromCfi(row.cfi) + ")</b>")
+ .attr('data-cfi', row.cfi)
+ .click(function() {
+ book.gotoCfi(a.attr('data-cfi'));
+ });
+
+ list.append($("<li>").append(a));
+
+ });
+ }
+
});
})