From 46a92eee384530354806ef527abbf1e37bb68810 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 20 Nov 2020 21:05:02 +0300 Subject: remove previous offline/online events, add endpoint for the app --- js/reader.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'js/reader.js') diff --git a/js/reader.js b/js/reader.js index 40ed656..8d54701 100644 --- a/js/reader.js +++ b/js/reader.js @@ -23,15 +23,12 @@ const Reader = { Reader.Loader.init(); }, - initSecondStage: function() { - - if (typeof EpubeApp != "undefined") { - EpubeApp.setPage("PAGE_READER"); - } + onOfflineModeChanged: function(offline) { + console.log('onOfflineModeChanged', offline); - Reader.applyTheme(); + if (!offline) { + const book = window.book; - $(window).on('online', function() { console.log("we're online, storing lastread"); const currentCfi = book.rendition.currentLocation().start.cfi; @@ -49,6 +46,22 @@ const Reader = { window.location = "index.php"; } }); + } + }, + initSecondStage: function() { + + if (typeof EpubeApp != "undefined") { + EpubeApp.setPage("PAGE_READER"); + } + + Reader.applyTheme(); + + $(window).on('online', function() { + Reader.onOfflineModeChanged(false); + }); + + $(window).on('offline', function() { + Reader.onOfflineModeChanged(true); }); localforage.getItem(Reader.cacheId("book")).then(function(item) { -- cgit v1.2.3