From bca9d802909ca846e0fa6294e3beba2b1934c416 Mon Sep 17 00:00:00 2001 From: Purbayan Chowdhury Date: Fri, 5 Jan 2024 20:58:18 +0530 Subject: [PATCH] Fixed theme related todos --- cps/static/js/reading/epub.js | 63 +++++----- cps/templates/read.html | 224 ++++++++++++++++++---------------- 2 files changed, 152 insertions(+), 135 deletions(-) diff --git a/cps/static/js/reading/epub.js b/cps/static/js/reading/epub.js index cfc12bad..3dc6332d 100644 --- a/cps/static/js/reading/epub.js +++ b/cps/static/js/reading/epub.js @@ -1,8 +1,8 @@ /* global $, calibre, EPUBJS, ePubReader */ -var reader; +let reader; -(function() { +(function () { "use strict"; EPUBJS.filePath = calibre.filePath; @@ -10,13 +10,12 @@ var reader; reader = ePubReader(calibre.bookUrl, { restore: true, - bookmarks: calibre.bookmark ? [calibre.bookmark] : [] + bookmarks: calibre.bookmark ? [calibre.bookmark] : [], }); - reader.rendition.themes.register("lightTheme", "/static/css/epub_themes.css"); - reader.rendition.themes.register("darkTheme", "/static/css/epub_themes.css"); - reader.rendition.themes.register("sepiaTheme", "/static/css/epub_themes.css"); - reader.rendition.themes.register("blackTheme", "/static/css/epub_themes.css"); + Object.keys(window.themes).forEach(function (theme) { + reader.rendition.themes.register(theme, window.themes[theme].css_path); + }); if (calibre.useBookmarks) { reader.on("reader:bookmarked", updateBookmark.bind(reader, "add")); @@ -27,28 +26,28 @@ var reader; // Enable swipe support // I have no idea why swiperRight/swiperLeft from plugins is not working, events just don't get fired - var touchStart = 0; - var touchEnd = 0; + let touchStart = 0; + let touchEnd = 0; - reader.rendition.on('touchstart', function(event) { + reader.rendition.on("touchstart", function (event) { touchStart = event.changedTouches[0].screenX; }); - reader.rendition.on('touchend', function(event) { - touchEnd = event.changedTouches[0].screenX; + reader.rendition.on("touchend", function (event) { + touchEnd = event.changedTouches[0].screenX; if (touchStart < touchEnd) { - if(reader.book.package.metadata.direction === "rtl") { - reader.rendition.next(); - } else { - reader.rendition.prev(); - } + if (reader.book.package.metadata.direction === "rtl") { + reader.rendition.next(); + } else { + reader.rendition.prev(); + } // Swiped Right } if (touchStart > touchEnd) { - if(reader.book.package.metadata.direction === "rtl") { - reader.rendition.prev(); - } else { + if (reader.book.package.metadata.direction === "rtl") { + reader.rendition.prev(); + } else { reader.rendition.next(); - } + } // Swiped Left } }); @@ -60,24 +59,26 @@ var reader; function updateBookmark(action, location) { // Remove other bookmarks (there can only be one) if (action === "add") { - this.settings.bookmarks.filter(function (bookmark) { - return bookmark && bookmark !== location; - }).map(function (bookmark) { - this.removeBookmark(bookmark); - }.bind(this)); + this.settings.bookmarks + .filter(function (bookmark) { + return bookmark && bookmark !== location; + }) + .map( + function (bookmark) { + this.removeBookmark(bookmark); + }.bind(this) + ); } - - var csrftoken = $("input[name='csrf_token']").val(); + + const csrftoken = $("input[name='csrf_token']").val(); // Save to database $.ajax(calibre.bookmarkUrl, { method: "post", data: { bookmark: location || "" }, - headers: { "X-CSRFToken": csrftoken } + headers: { "X-CSRFToken": csrftoken }, }).fail(function (xhr, status, error) { alert(error); }); } })(); - - diff --git a/cps/templates/read.html b/cps/templates/read.html index b75c31fe..fd90e8a7 100644 --- a/cps/templates/read.html +++ b/cps/templates/read.html @@ -1,33 +1,35 @@ - - - - {{_('epub Reader')}} | {{title}} - - - - {% if g.google_site_verification|length > 0 %} - - {% endif %} - - - - - - - - -