From 0f83f9992c13c666e3e6db8fa25d6c0e954ad44c Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 24 Jan 2021 14:19:46 +0100 Subject: [PATCH] Added swipe support for epub reader (fixes #925) Cleaned reader js include files --- cps/static/js/reading/epub.js | 30 ++++++++++++++++++++++++++++++ cps/templates/read.html | 5 +---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/cps/static/js/reading/epub.js b/cps/static/js/reading/epub.js index 8b7fb0759..edafa82c0 100644 --- a/cps/static/js/reading/epub.js +++ b/cps/static/js/reading/epub.js @@ -20,6 +20,34 @@ var reader; $("#bookmark, #show-Bookmarks").remove(); } + // 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; + + reader.rendition.on('touchstart', function(event) { + touchStart = 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(); + } + // Swiped Right + } + if (touchStart > touchEnd) { + if(reader.book.package.metadata.direction === "rtl") { + reader.rendition.prev(); + } else { + reader.rendition.next(); + } + // Swiped Left + } + }); + /** * @param {string} action - Add or remove bookmark * @param {string|int} location - Location or zero @@ -43,3 +71,5 @@ var reader; }); } })(); + + diff --git a/cps/templates/read.html b/cps/templates/read.html index a4361fa03..b38f783cf 100644 --- a/cps/templates/read.html +++ b/cps/templates/read.html @@ -78,7 +78,7 @@

{{_('Settings')}}

- + - - -