diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/app.js | 10 | ||||
-rw-r--r-- | js/reader.js | 25 | ||||
-rw-r--r-- | js/reader_iframe.js | 4 |
3 files changed, 26 insertions, 13 deletions
@@ -199,8 +199,14 @@ const App = { .html("Could not communicate with service worker. Try reloading the page."); } }, + onLine: function() { + if (typeof EpubeApp != "undefined" && typeof EpubeApp.isOnline != "undefined") + return EpubeApp.isOnline; + else + return navigator.onLine; + }, appCheckOffline: function() { - EpubeApp.setOffline(!navigator.onLine); + EpubeApp.setOffline(!App.onLine); }, initOfflineEvents: function() { if (typeof EpubeApp != "undefined") { @@ -212,7 +218,7 @@ const App = { EpubeApp.setOffline(true); }); - EpubeApp.setOffline(!navigator.onLine); + EpubeApp.setOffline(!App.onLine); } }, initNightMode: function() { diff --git a/js/reader.js b/js/reader.js index 6227fbc..fda1d5d 100644 --- a/js/reader.js +++ b/js/reader.js @@ -1,6 +1,6 @@ 'use strict'; -/* global localforage, EpubeApp */ +/* global localforage, EpubeApp, App */ const DEFAULT_FONT_SIZE = 16; const DEFAULT_FONT_FAMILY = "Georgia"; @@ -75,7 +75,7 @@ const Reader = { console.log("loading from network"); - if (navigator.onLine) { + if (App.onLine) { const book_url = "backend.php?op=download&id=" + $.urlParam("id"); $(".loading_message").html("Downloading..."); @@ -264,7 +264,7 @@ const Reader = { else msg += "Unknown"; - msg += " (" + (navigator.onLine ? "Online" : "Offline") + ")"; + msg += " (" + (App.onLine ? "Online" : "Offline") + ")"; $(".last-mod-timestamp").text(msg) }); @@ -516,7 +516,7 @@ const Reader = { console.log("locations ready, stored=", Reader.Page._pagination_stored); if (locations) { - if (navigator.onLine && !Reader.Page._pagination_stored) { + if (App.onLine && !Reader.Page._pagination_stored) { $.post("backend.php", { op: "storepagination", id: $.urlParam("id"), payload: JSON.stringify(locations), total: 100}); } @@ -629,7 +629,7 @@ const Reader = { if (Reader.Page._store_position && new Date().getTime()/1000 - Reader.Page._last_position_sync > 15) { console.log("storing lastread", currentPct, currentCfi); - if (navigator.onLine) { + if (App.onLine) { $.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPct, cfi: currentCfi }, function(data) { @@ -858,7 +858,7 @@ const Reader = { const total = 100; const lastCfi = window.book.locations.cfiFromPercentage(1); - if (navigator.onLine) { + if (App.onLine) { $.post("backend.php", { op: "storelastread", page: total, cfi: lastCfi, id: $.urlParam("id") }, function(data) { $(".lastread_input").val(data.page + '%'); }); @@ -879,7 +879,7 @@ const Reader = { localforage.setItem(Reader.cacheId("lastread"), {cfi: currentCfi, page: currentPage, total: totalPages}); - if (navigator.onLine) { + if (App.onLine) { $.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPage, cfi: currentCfi }, function() { window.location = $.urlParam("rt") ? "index.php?mode=" + $.urlParam("rt") : "index.php"; @@ -1054,7 +1054,7 @@ const Reader = { if (confirm("Clear stored last read location?")) { const total = window.book.locations.length(); - if (navigator.onLine) { + if (App.onLine) { $.post("backend.php", { op: "storelastread", page: -1, cfi: "", id: $.urlParam("id") }, function(data) { $(".lastread_input").val(data.page + '%'); }); @@ -1088,11 +1088,11 @@ const Reader = { console.warn(e); } - if (navigator.onLine && !local_only) { + if (App.onLine && !local_only) { $.post("backend.php", { op: "getlastread", id: $.urlParam("id") }, function(data) { console.log('lr remote', data); - if (navigator.onLine && data) { + if (App.onLine && data) { try { if (item.cfi != data.cfi && (!item.page || data.page >= item.page)) console.log('using remote lastread...'); @@ -1153,3 +1153,8 @@ const Reader = { function __get_reader() { return Reader; } + +/* exported __get_app */ +function __get_app() { + return App; +} diff --git a/js/reader_iframe.js b/js/reader_iframe.js index bcc5b44..c58061e 100644 --- a/js/reader_iframe.js +++ b/js/reader_iframe.js @@ -3,6 +3,7 @@ /* global EpubeApp */ let Reader; +let App; function enable_swipes() { $(window).off("swipeleft swiperight"); @@ -18,6 +19,7 @@ function enable_swipes() { $(document).ready(function() { Reader = parent.__get_reader(); + App = parent.__get_app(); /*$(window).on("doubletap", function(evt) { const sel = getSelection().toString().trim(); @@ -59,7 +61,7 @@ $(document).ready(function() { let selectionChangeTimeout = null; $(document).on("selectionchange", function() { - if (!navigator.onLine) return; + if (!App.onLine) return; window.clearTimeout(selectionChangeTimeout); |