Skip to content

Commit

Permalink
Back button on ebook reader
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusa87 committed Aug 16, 2024
1 parent 3dc8aaa commit dbedf8d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
39 changes: 28 additions & 11 deletions assets/ReadEbook.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<template>
<div id="area" style="width: 100vw; height: 100vh; min-height: 95vh;">
<vue-reader
:url="props.file"
:showToc="true"
:getRendition="getRendition"
:backgroundColor="props.bgColor"
@update:location="locationChange"
:location="getInitialLocation()"
/>
<div class="flex">
<div class="area-back" v-if="canGoBack()" style="width: 10vw">
<button @click="goBack" class="arrow pre">
‹‹
</button>
</div>

<div id="area" :style="`width: ${canGoBack() ?80 : 100}vw; height: 100vh; min-height: 95vh;`">
<vue-reader
:url="props.file"
:showToc="true"
:getRendition="getRendition"
:backgroundColor="props.bgColor"
@update:location="locationChange"
:location="getInitialLocation()"
/>
</div>
</div>
</template>

Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
</script>
6 changes: 4 additions & 2 deletions assets/read-ebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
7 changes: 7 additions & 0 deletions assets/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ body.bg-darker{

#vue-book-reader{
width: 100%;
.flex{
display: flex;
button{
display: block;
}
}

}

/*
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
8 changes: 7 additions & 1 deletion templates/book/reader-files-epub.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
{% endblock %}

{% block content %}
<div id="vue-book-reader" data-progressionUrl="{{ app.request.pathInfo }}" data-percent="{{ percent??'undefined' }}" data-file="{{ file }}" data-css="{{ block('readercss')|e('html_attr') }}" data-background-color="{{ isDark ? '#000' : '#fff' }}">
<div id="vue-book-reader"
data-progression-url="{{ app.request.pathInfo }}"
data-percent="{{ percent??'undefined' }}"
data-file="{{ file }}"
data-css="{{ block('readercss')|e('html_attr') }}"
data-background-color="{{ isDark ? '#000' : '#fff' }}"
data-back-url="{{ backUrl }}">
<a href="{{ file }}">Loading book</a>
</div>
{% endblock %}
Expand Down

0 comments on commit dbedf8d

Please sign in to comment.