From dbedf8d77ebca2c5228435378e6a5cbc26e5c1f7 Mon Sep 17 00:00:00 2001 From: Laurent Constantin Date: Fri, 16 Aug 2024 23:37:34 +0200 Subject: [PATCH] Back button on ebook reader --- assets/ReadEbook.vue | 39 ++++++++++++++++------ assets/read-ebook.js | 6 ++-- assets/styles/global.scss | 7 ++++ src/Controller/BookController.php | 4 +++ templates/book/reader-files-epub.html.twig | 8 ++++- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/assets/ReadEbook.vue b/assets/ReadEbook.vue index 17ec3d64..992db459 100644 --- a/assets/ReadEbook.vue +++ b/assets/ReadEbook.vue @@ -1,13 +1,21 @@ @@ -17,11 +25,12 @@ const props = defineProps({ 'css': String, 'bgColor': String, 'percent': String, - 'progressionUrl': String + 'progressionUrl': String, + 'backUrl': { type: String, default: ''} }) import { VueReader } from 'vue-book-reader' const initialCfi = new URLSearchParams(window.location.search).get('cfi'); - +const initialReferrer = document.referrer function debounce(func, delay) { let timeoutId; return function(...args) { @@ -71,4 +80,12 @@ const getRendition = async (rendition) => { rendition.renderer.setStyles([props.css]) } +const canGoBack = () => { + return initialReferrer !== "" || props.backUrl !== "" +} + +const goBack = (e) => { + e.preventDefault() + window.location.href = props.backUrl ?? initialReferrer; +} diff --git a/assets/read-ebook.js b/assets/read-ebook.js index e6c94892..bae845b8 100644 --- a/assets/read-ebook.js +++ b/assets/read-ebook.js @@ -7,12 +7,14 @@ document.addEventListener('DOMContentLoaded', () => { const css = document.getElementById(mountId).getAttribute('data-css') const bgColor = document.getElementById(mountId).getAttribute('data-background-color') const percent = document.getElementById(mountId).getAttribute('data-percent') - const progressionUrl = document.getElementById(mountId).getAttribute('data-progressionUrl') + const progressionUrl = document.getElementById(mountId).getAttribute('data-progression-url') + const backUrl = document.getElementById(mountId).getAttribute('data-back-url') createApp(ReadEBook, { file: file, css: css, bgColor: bgColor, percent: percent, - progressionUrl: progressionUrl + progressionUrl: progressionUrl, + backUrl: backUrl }).mount(`#${mountId}`); }); diff --git a/assets/styles/global.scss b/assets/styles/global.scss index b1f7373d..1679bdf0 100644 --- a/assets/styles/global.scss +++ b/assets/styles/global.scss @@ -9,6 +9,13 @@ body.bg-darker{ #vue-book-reader{ width: 100%; + .flex{ + display: flex; + button{ + display: block; + } + } + } /* diff --git a/src/Controller/BookController.php b/src/Controller/BookController.php index 3cfc95bb..fa63fe50 100644 --- a/src/Controller/BookController.php +++ b/src/Controller/BookController.php @@ -130,6 +130,10 @@ public function read( 'file' => $fileSystemManager->getBookPublicPath($book), 'body_class' => $themeSelector->isDark() ? 'bg-darker' : '', 'isDark' => $themeSelector->isDark(), + 'backUrl' => $this->generateUrl('app_book', [ + 'book' => $book->getId(), + 'slug' => $book->getSlug(), + ]), ]); case 'pdf': case 'cbr': diff --git a/templates/book/reader-files-epub.html.twig b/templates/book/reader-files-epub.html.twig index fa0f7e2d..f05ba187 100644 --- a/templates/book/reader-files-epub.html.twig +++ b/templates/book/reader-files-epub.html.twig @@ -13,7 +13,13 @@ {% endblock %} {% block content %} -
+ {% endblock %}