diff options
author | Andrew Dolgov <[email protected]> | 2017-07-30 23:18:28 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2017-07-30 23:18:28 +0300 |
commit | fe88505aaa7ce84d2c6e5a706edf0e99490ab52d (patch) | |
tree | 3522379ff628143c270993838d96041435bd756c | |
parent | 70f38e9c4fc9eec74a7f648474433184b4dede18 (diff) |
simplify initial page selection on startup: prefer local CFI is stored, request possible uptodate position from the server afterwards
-rw-r--r-- | read.html | 40 |
1 files changed, 20 insertions, 20 deletions
@@ -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()); |