From bb0bbfb1ed76bb9c429b92d3769c19adef553e43 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 21 Apr 2020 07:49:42 +0300 Subject: epubeapp-related stuff --- js/common.js | 23 +++++++++++++++++++++++ js/read.js | 53 +++++++++++++++++++++++++++++++++++++++-------------- js/reader.js | 8 ++++++-- 3 files changed, 68 insertions(+), 16 deletions(-) (limited to 'js') diff --git a/js/common.js b/js/common.js index ecc8206..45851a7 100644 --- a/js/common.js +++ b/js/common.js @@ -50,3 +50,26 @@ function apply_night_mode(is_night) { $("#theme_css").attr("href", "lib/bootstrap/v3/css/" + (is_night ? "theme-dark.min.css" : "bootstrap-theme.min.css")); } + +const Cookie = { + set: function (name, value, lifetime) { + const d = new Date(); + d.setTime(d.getTime() + lifetime * 1000); + const expires = "expires=" + d.toUTCString(); + document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires; + }, + get: function (name) { + name = name + "="; + const ca = document.cookie.split(';'); + for (let i=0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1); + if (c.indexOf(name) == 0) return decodeURIComponent(c.substring(name.length, c.length)); + } + return ""; + }, + delete: function(name) { + const expires = "expires=Thu, 01-Jan-1970 00:00:01 GMT"; + document.cookie = name + "=" + "" + "; " + expires; + } +}; diff --git a/js/read.js b/js/read.js index 86a630f..c22b4d0 100644 --- a/js/read.js +++ b/js/read.js @@ -1,6 +1,6 @@ 'use strict'; -/* globals ePub, localforage, book, cacheId */ +/* globals ePub, localforage, book, cacheId, EpubeApp */ let _pagination_stored = 0; let _last_position_sync = 0; @@ -62,8 +62,18 @@ function check_resource_load(res_names, res_data, attempt) { } function init_reader() { + if (typeof EpubeApp != "undefined") { + EpubeApp.setPage("PAGE_READER"); + } + apply_theme(); + /* global Cookie */ + + if (Cookie.get("is-epube-app") == "true") { + $("body").addClass("is-epube-app"); + } + $(window).on('online', function() { console.log("we're online, storing lastread"); @@ -471,6 +481,11 @@ function init_reader() { document.title = meta.title + " – " + meta.creator + " – The Epube"; $(".title").text(meta.title); + if (typeof EpubeApp != "undefined") { + EpubeApp.setTitle(meta.title); + EpubeApp.showActionBar(false); + } + return localforage.getItem(cacheId("locations")).then(function(locations) { console.log('stored pagination', locations != null); @@ -664,16 +679,20 @@ function init_reader() { /* exported toggle_fullscreen */ function toggle_fullscreen() { - const element = document.documentElement; - const isFullscreen = document.webkitIsFullScreen || document.mozFullScreen || false; + if (typeof EpubeApp != "undefined") { + EpubeApp.toggleSystemUI(); + } else { + const element = document.documentElement; + const isFullscreen = document.webkitIsFullScreen || document.mozFullScreen || false; - element.requestFullScreen = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || - function () { return false; }; + element.requestFullScreen = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || + function () { return false; }; - document.cancelFullScreen = document.cancelFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen || - function () { return false; }; + document.cancelFullScreen = document.cancelFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen || + function () { return false; }; - isFullscreen ? document.cancelFullScreen() : element.requestFullScreen(); + isFullscreen ? document.cancelFullScreen() : element.requestFullScreen(); + } } function show_ui(show) { @@ -746,17 +765,23 @@ function next_page() { window.book.rendition.next(); - localforage.getItem("epube.keep-ui-visible").then(function(keep) { - if (!keep) show_ui(false); - }); + if (typeof EpubeApp != "undefined") + EpubeApp.showActionBar(false); + else + localforage.getItem("epube.keep-ui-visible").then(function(keep) { + if (!keep) show_ui(false); + }); } function prev_page() { window.book.rendition.prev(); - localforage.getItem("epube.keep-ui-visible").then(function(keep) { - if (!keep) show_ui(false); - }); + if (typeof EpubeApp != "undefined") + EpubeApp.showActionBar(false); + else + localforage.getItem("epube.keep-ui-visible").then(function(keep) { + if (!keep) show_ui(false); + }); } function hotkey_handler(e) { diff --git a/js/reader.js b/js/reader.js index 537835a..1f6509a 100644 --- a/js/reader.js +++ b/js/reader.js @@ -1,5 +1,7 @@ 'use strict'; +/* global EpubeApp */ + function enable_swipes() { $(window).off("swipeleft swiperight"); @@ -15,7 +17,6 @@ function enable_swipes() { $(document).ready(function() { $(window).on("doubletap", function(/* evt */) { - const sel = getSelection().toString().trim(); if (sel.match(/^$/)) { @@ -29,7 +30,10 @@ $(document).ready(function() { if ($(".modal").is(":visible")) return; - parent.show_ui(true); + if (typeof EpubeApp != "undefined") + EpubeApp.toggleActionBar(); + else + parent.show_ui(true); } }); -- cgit v1.2.3