From 5f01164c809da30ae19ca009b6fdbe6f063e4a31 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 27 Feb 2017 18:26:31 +0300 Subject: generate dummy toc when no usable one has been found --- read.html | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'read.html') 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 = $("") - .attr('href', '#') - .html(row.label) + // if anything fails here the toc entry is likely useless anyway (i.e. no cfi) + try { + var a = $("") + .attr('href', '#') + .html(row.label + " (Loc. " + + book.pagination.pageFromCfi(row.cfi) + ")") .attr('data-cfi', row.cfi) - .attr('data-id', row.id) - .click(function() { - book.gotoCfi(a.attr('data-cfi')); - }); - - list.append($("
  • ").append(a)); + .click(function() { + book.gotoCfi(a.attr('data-cfi')); + }); + + list.append($("
  • ").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 = $("") + .attr('href', '#') + .attr('title', row.url) + .html("Section " + (i+1) + " (Loc. " + + book.pagination.pageFromCfi(row.cfi) + ")") + .attr('data-cfi', row.cfi) + .click(function() { + book.gotoCfi(a.attr('data-cfi')); + }); + + list.append($("
  • ").append(a)); + + }); + } + }); }) -- cgit v1.2.3