summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-04-21 07:49:42 +0300
committerAndrew Dolgov <[email protected]>2020-04-21 07:49:42 +0300
commitbb0bbfb1ed76bb9c429b92d3769c19adef553e43 (patch)
tree14c6cb620fd9d1851d077800c93c951c83e86f14 /js
parentf28a75864777b72027275f620feb31a357a5ae3d (diff)
epubeapp-related stuff
Diffstat (limited to 'js')
-rw-r--r--js/common.js23
-rw-r--r--js/read.js53
-rw-r--r--js/reader.js8
3 files changed, 68 insertions, 16 deletions
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);
}
});