mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-03-24 00:16:39 +01:00
Epub reader updates for mobile
This commit is contained in:
parent
f2baf3fafd
commit
d2e0844493
@ -1,13 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="h-full w-full">
|
<div class="h-full w-full">
|
||||||
<div class="h-full flex items-center">
|
<div class="h-full flex items-center justify-center">
|
||||||
<div style="width: 100px; max-width: 100px" class="h-full flex items-center overflow-x-hidden justify-center">
|
<div style="width: 100px; max-width: 100px" class="h-full hidden sm:flex items-center overflow-x-hidden justify-center">
|
||||||
<span v-if="hasPrev" class="material-icons text-white text-opacity-50 hover:text-opacity-80 cursor-pointer text-6xl" @mousedown.prevent @click="prev">chevron_left</span>
|
<span v-if="hasPrev" class="material-icons text-white text-opacity-50 hover:text-opacity-80 cursor-pointer text-6xl" @mousedown.prevent @click="prev">chevron_left</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="frame" class="w-full" style="height: 80%">
|
<div id="frame" class="w-full" style="height: 80%">
|
||||||
<div id="viewer"></div>
|
<div id="viewer"></div>
|
||||||
</div>
|
</div>
|
||||||
<div style="width: 100px; max-width: 100px" class="h-full flex items-center justify-center overflow-x-hidden">
|
<div style="width: 100px; max-width: 100px" class="h-full hidden sm:flex items-center justify-center overflow-x-hidden">
|
||||||
<span v-if="hasNext" class="material-icons text-white text-opacity-50 hover:text-opacity-80 cursor-pointer text-6xl" @mousedown.prevent @click="next">chevron_right</span>
|
<span v-if="hasNext" class="material-icons text-white text-opacity-50 hover:text-opacity-80 cursor-pointer text-6xl" @mousedown.prevent @click="next">chevron_right</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -32,6 +32,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
windowWidth: 0,
|
||||||
/** @type {ePub.Book} */
|
/** @type {ePub.Book} */
|
||||||
book: null,
|
book: null,
|
||||||
/** @type {ePub.Rendition} */
|
/** @type {ePub.Rendition} */
|
||||||
@ -59,6 +60,10 @@ export default {
|
|||||||
},
|
},
|
||||||
localStorageLocationsKey() {
|
localStorageLocationsKey() {
|
||||||
return `ebookLocations-${this.libraryItemId}`
|
return `ebookLocations-${this.libraryItemId}`
|
||||||
|
},
|
||||||
|
readerWidth() {
|
||||||
|
if (this.windowWidth < 640) return this.windowWidth
|
||||||
|
return this.windowWidth - 200
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -197,13 +202,13 @@ export default {
|
|||||||
|
|
||||||
/** @type {ePub.Book} */
|
/** @type {ePub.Book} */
|
||||||
reader.book = new ePub(reader.url, {
|
reader.book = new ePub(reader.url, {
|
||||||
width: window.innerWidth - 200,
|
width: this.readerWidth,
|
||||||
height: window.innerHeight - 50
|
height: window.innerHeight - 50
|
||||||
})
|
})
|
||||||
|
|
||||||
/** @type {ePub.Rendition} */
|
/** @type {ePub.Rendition} */
|
||||||
reader.rendition = reader.book.renderTo('viewer', {
|
reader.rendition = reader.book.renderTo('viewer', {
|
||||||
width: window.innerWidth - 200,
|
width: this.readerWidth,
|
||||||
height: window.innerHeight * 0.8
|
height: window.innerHeight * 0.8
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -218,6 +223,23 @@ export default {
|
|||||||
reader.rendition.on('relocated', reader.relocated)
|
reader.rendition.on('relocated', reader.relocated)
|
||||||
reader.rendition.on('keydown', reader.keyUp)
|
reader.rendition.on('keydown', reader.keyUp)
|
||||||
|
|
||||||
|
let touchStart = 0
|
||||||
|
let touchEnd = 0
|
||||||
|
reader.rendition.on('touchstart', (event) => {
|
||||||
|
touchStart = event.changedTouches[0].screenX
|
||||||
|
})
|
||||||
|
|
||||||
|
reader.rendition.on('touchend', (event) => {
|
||||||
|
touchEnd = event.changedTouches[0].screenX
|
||||||
|
const touchDistanceX = Math.abs(touchEnd - touchStart)
|
||||||
|
if (touchStart < touchEnd && touchDistanceX > 120) {
|
||||||
|
this.next()
|
||||||
|
}
|
||||||
|
if (touchStart > touchEnd && touchDistanceX > 120) {
|
||||||
|
this.prev()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// load ebook cfi locations
|
// load ebook cfi locations
|
||||||
const savedLocations = this.loadLocations()
|
const savedLocations = this.loadLocations()
|
||||||
if (savedLocations) {
|
if (savedLocations) {
|
||||||
@ -228,9 +250,19 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
resize() {
|
||||||
|
this.windowWidth = window.innerWidth
|
||||||
|
this.rendition?.resize(this.readerWidth, window.innerHeight * 0.8)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
window.removeEventListener('resize', this.resize)
|
||||||
|
this.book?.destroy()
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
this.windowWidth = window.innerWidth
|
||||||
|
window.addEventListener('resize', this.resize)
|
||||||
this.initEpub()
|
this.initEpub()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="absolute top-4 left-1/2 transform -translate-x-1/2">
|
<div class="absolute top-4 left-1/2 transform -translate-x-1/2">
|
||||||
<h1 class="text-2xl mb-1" style="line-height: 1.15; font-weight: 100">
|
<h1 class="text-lg sm:text-xl md:text-2xl mb-1" style="line-height: 1.15; font-weight: 100">
|
||||||
<span style="font-weight: 600">{{ abTitle }}</span>
|
<span style="font-weight: 600">{{ abTitle }}</span>
|
||||||
<span v-if="abAuthor" style="display: inline"> – </span>
|
<span v-if="abAuthor" style="display: inline"> – </span>
|
||||||
<span v-if="abAuthor">{{ abAuthor }}</span>
|
<span v-if="abAuthor">{{ abAuthor }}</span>
|
||||||
@ -150,13 +150,19 @@ export default {
|
|||||||
if (!this.$refs.readerComponent) return
|
if (!this.$refs.readerComponent) return
|
||||||
|
|
||||||
if (action === this.$hotkeys.EReader.NEXT_PAGE) {
|
if (action === this.$hotkeys.EReader.NEXT_PAGE) {
|
||||||
if (this.$refs.readerComponent.next) this.$refs.readerComponent.next()
|
this.next()
|
||||||
} else if (action === this.$hotkeys.EReader.PREV_PAGE) {
|
} else if (action === this.$hotkeys.EReader.PREV_PAGE) {
|
||||||
if (this.$refs.readerComponent.prev) this.$refs.readerComponent.prev()
|
this.prev()
|
||||||
} else if (action === this.$hotkeys.EReader.CLOSE) {
|
} else if (action === this.$hotkeys.EReader.CLOSE) {
|
||||||
this.close()
|
this.close()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
next() {
|
||||||
|
if (this.$refs.readerComponent?.next) this.$refs.readerComponent.next()
|
||||||
|
},
|
||||||
|
prev() {
|
||||||
|
if (this.$refs.readerComponent?.prev) this.$refs.readerComponent.prev()
|
||||||
|
},
|
||||||
registerListeners() {
|
registerListeners() {
|
||||||
this.$eventBus.$on('reader-hotkey', this.hotkey)
|
this.$eventBus.$on('reader-hotkey', this.hotkey)
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user