diff options
author | Andrew Dolgov <[email protected]> | 2018-06-29 15:07:39 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-06-29 15:07:39 +0300 |
commit | 27dfbb1f00bfe018311b92d709ce0b9eae9774cd (patch) | |
tree | 98a76b901225e94f167ecd1c2d00fbbf967891af | |
parent | 49cf8bbd4d7e2a7e98777a271f04c2268e146e95 (diff) |
minor location check on rendered
-rw-r--r-- | read.html | 51 |
1 files changed, 27 insertions, 24 deletions
@@ -791,40 +791,43 @@ $(".chapter").html(""); try { + var location = book.rendition.currentLocation(); - var cur_href = book.canonical(book.rendition.currentLocation().start.href); - var toc_entry = false; + if (location.start) { + var cur_href = book.canonical(location.start.href); + var toc_entry = false; - function iterate_sublist(row, nest) { - if (nest == 3) return false; + function iterate_sublist(row, nest) { + if (nest == 3) return false; - if (row.subitems) { - $.each(row.subitems, function (i, r) { + 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; - }); - } + if (book.spine.get(r.href).canonical == cur_href) { + toc_entry = r; + return true; + } - return false; - } + if (iterate_sublist(r, nest + 1)) + return true; + }); + } - $.each(book.navigation.toc, function(i, a) { - if (book.spine.get(a.href).canonical == cur_href) { - toc_entry = a; - return; + return false; } - if (iterate_sublist(a, 0)) return; + $.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); + }); + + if (toc_entry) $(".chapter").html(toc_entry.label); + } } catch (e) { console.warn(e); |