From fe88505aaa7ce84d2c6e5a706edf0e99490ab52d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 30 Jul 2017 23:18:28 +0300 Subject: simplify initial page selection on startup: prefer local CFI is stored, request possible uptodate position from the server afterwards --- read.html | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'read.html') diff --git a/read.html b/read.html index bc5e0b1..203eb2c 100644 --- a/read.html +++ b/read.html @@ -647,26 +647,26 @@ localforage.setItem(cacheId("pagination"), pageList); } - if (navigator.onLine) { - $.post("backend.php", { op: "getlastread", id: $.urlParam("id") }, function(data) { - console.log(data); - - if (navigator.onLine && data) { - localforage.setItem(cacheId("lastread"), - {cfi: data.cfi, page: data.page, total: data.total}); - - if (data.cfi) book.gotoCfi(data.cfi); - } else { - localforage.getItem(cacheId("lastread")).then(function(item) { - if (item && item.cfi) book.gotoCfi(item.cfi); - }); - } - }); - } else { - localforage.getItem(cacheId("lastread")).then(function(item) { - if (item && item.cfi) book.gotoCfi(item.cfi); - }); - } + localforage.getItem(cacheId("lastread")).then(function(item) { + console.log('lr local', item.cfi); + + if (item && item.cfi) book.gotoCfi(item.cfi); + + if (navigator.onLine) { + + $.post("backend.php", { op: "getlastread", id: $.urlParam("id") }, function(data) { + console.log('lr remote', data.cfi); + + if (navigator.onLine && data) { + localforage.setItem(cacheId("lastread"), + {cfi: data.cfi, page: data.page, total: data.total}); + + if (data.cfi) book.gotoCfi(data.cfi); + } + }); + } + + }); var curPage = book.pagination.pageFromCfi(book.getCurrentLocationCfi()); -- cgit v1.2.3