summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-09-14 08:01:43 +0300
committerAndrew Dolgov <[email protected]>2020-09-14 08:01:43 +0300
commit220dd45af04d7c5fda75610d792fc115fced5a36 (patch)
treee73dbf0a9d6a0344e4e349e3af2419c22653c06d /js
parenta50e03516bcdc5aceee1abddea7e750bfb90ea91 (diff)
show current chapter (section) progress in the UI
Diffstat (limited to 'js')
-rw-r--r--js/reader.js29
1 files changed, 19 insertions, 10 deletions
diff --git a/js/reader.js b/js/reader.js
index 246d203..e9b3fc2 100644
--- a/js/reader.js
+++ b/js/reader.js
@@ -573,7 +573,8 @@ const Reader = {
return false;
}
- /* eslint-enable no-inne-declarations */
+
+ /* eslint-enable no-inner-declarations */
$.each(book.navigation.toc, function(i, a) {
if (book.spine.get(a.href).canonical == cur_href) {
@@ -586,7 +587,7 @@ const Reader = {
});
if (toc_entry && toc_entry.label.trim())
- $(".chapter").append("&nbsp;" + toc_entry.label);
+ $(".chapter").append("&nbsp;" + toc_entry.label + " | ");
}
} catch (e) {
@@ -601,20 +602,28 @@ const Reader = {
return;
const currentCfi = location.start.cfi;
- const currentPage = parseInt(book.locations.percentageFromCfi(currentCfi) * 100);
- const pct = book.locations.percentageFromCfi(currentCfi);
+ const currentPct = parseInt(book.locations.percentageFromCfi(currentCfi) * 100);
+
+ $("#cur_page").text(location.start.location);
+ $("#total_pages").text(book.locations.length());
+ $("#page_pct").text(parseInt(book.locations.percentageFromCfi(currentCfi)*100) + '%');
- $("#cur_page").html(location.start.location);
- $("#total_pages").html(book.locations.length());
+ const displayed = location.start.displayed;
- $("#page_pct").html(parseInt(pct*100) + '%');
+ if (displayed) {
+ $("#chapter_cur_page").text(displayed.page);
+ $("#chapter_total_pages").text(displayed.total);
+
+ if (displayed.total > 0)
+ $("#chapter_pct").text(parseInt(displayed.page / displayed.total * 100) + '%')
+ }
if (Reader.Page._store_position && new Date().getTime()/1000 - Reader.Page._last_position_sync > 15) {
- console.log("storing lastread", currentPage, currentCfi);
+ console.log("storing lastread", currentPct, currentCfi);
if (navigator.onLine) {
- $.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPage,
+ $.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPct,
cfi: currentCfi }, function(data) {
if (data.cfi) {
@@ -634,7 +643,7 @@ const Reader = {
}
localforage.setItem(Reader.cacheId("lastread"),
- {cfi: currentCfi, page: currentPage, total: 100});
+ {cfi: currentCfi, page: currentPct, total: 100});
}
});