From 8aaf1fad0c1cfa65132f052f0f98b3452ddc4eeb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 26 Feb 2017 13:42:00 +0300 Subject: various offline-related fixes --- js/offline.js | 27 +++++++++++++++++++++++---- js/read.js | 3 ++- 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/offline.js b/js/offline.js index d1c49d6..7815b83 100644 --- a/js/offline.js +++ b/js/offline.js @@ -1,3 +1,7 @@ +function offline_remove2(elem) { + return offline_remove(elem, populate_list); +} + function populate_list() { var books = $("#books_container"); @@ -8,7 +12,8 @@ function populate_list() { Promise.all([ localforage.getItem(key), - localforage.getItem(key + ".cover") + localforage.getItem(key + ".cover"), + localforage.getItem(key + ".lastread") ]).then(function(results) { var info = results[0]; @@ -20,13 +25,27 @@ function populate_list() { cover = URL.createObjectURL(results[1]); } + var in_progress = false; + var is_read = false; + + var lastread = results[2]; + if (lastread) { + + in_progress = lastread.page > 0; + is_read = lastread.total - lastread.page < 5; + } + var cell = "
"; - cell += "
"; + var cover_read = is_read ? "read" : ""; + var title_class = in_progress ? "in_progress" : ""; + + cell += "
"; cell += ""; cell += "
"; - cell += ""; + cell += ""; cell += "
" + info.author_sort + "
"; if (info.series_name) { @@ -40,7 +59,7 @@ function populate_list() { "More..." + ""; cell += ""; cell += "
"; diff --git a/js/read.js b/js/read.js index dc968f4..4fb74ce 100644 --- a/js/read.js +++ b/js/read.js @@ -113,9 +113,10 @@ function save_and_close() { if (navigator.onLine) { var currentPage = book.pagination.pageFromCfi(book.getCurrentLocationCfi()); var currentCfi = book.getCurrentLocationCfi(); + var totalPages = book.pagination.totalPages; localforage.setItem("epube-book." + $.urlParam("b") + ".lastread", - {cfi: currentCfi, page: currentPage}); + {cfi: currentCfi, page: currentPage, total: totalPages}); $.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPage, cfi: currentCfi }, function(data) { -- cgit v1.2.3