diff options
author | Andrew Dolgov <[email protected]> | 2017-02-27 18:26:31 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2017-02-27 18:26:31 +0300 |
commit | 5f01164c809da30ae19ca009b6fdbe6f063e4a31 (patch) | |
tree | b2c2cbdd015966a4175d0bee51b9d27a5f23dd4d /read.html | |
parent | 946564f7ff9a81fc76efdde294ab79dabf90794a (diff) |
generate dummy toc when no usable one has been found
Diffstat (limited to 'read.html')
-rw-r--r-- | read.html | 46 |
1 files changed, 37 insertions, 9 deletions
@@ -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)); + + }); + } + }); }) |