1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Disallow scripted content in epubs

This commit is contained in:
Bill Thornton 2024-06-27 14:07:39 -04:00
parent 21ced03987
commit 71d4f7083d
2 changed files with 14 additions and 22 deletions

View file

@ -6,9 +6,9 @@ import dialogHelper from '../../components/dialogHelper/dialogHelper';
import ServerConnections from '../../components/ServerConnections'; import ServerConnections from '../../components/ServerConnections';
import Screenfull from 'screenfull'; import Screenfull from 'screenfull';
import TableOfContents from './tableOfContents'; import TableOfContents from './tableOfContents';
import dom from '../../scripts/dom';
import { translateHtml } from '../../scripts/globalize'; import { translateHtml } from '../../scripts/globalize';
import * as userSettings from '../../scripts/settings/userSettings'; import * as userSettings from '../../scripts/settings/userSettings';
import TouchHelper from 'scripts/touchHelper';
import { PluginType } from '../../types/plugin.ts'; import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts'; import Events from '../../utils/events.ts';
@ -45,7 +45,6 @@ export class BookPlayer {
this.previous = this.previous.bind(this); this.previous = this.previous.bind(this);
this.next = this.next.bind(this); this.next = this.next.bind(this);
this.onWindowKeyUp = this.onWindowKeyUp.bind(this); this.onWindowKeyUp = this.onWindowKeyUp.bind(this);
this.onTouchStart = this.onTouchStart.bind(this);
} }
play(options) { play(options) {
@ -156,19 +155,6 @@ export class BookPlayer {
} }
} }
onTouchStart(e) {
if (!this.loaded || !e.touches || e.touches.length === 0) return;
// epubjs stores pages off the screen or something for preloading
// get the modulus of the touch event to account for the increased width
const touchX = e.touches[0].clientX % dom.getWindowSize().innerWidth;
if (touchX < dom.getWindowSize().innerWidth / 2) {
this.previous();
} else {
this.next();
}
}
onDialogClosed() { onDialogClosed() {
this.stop(); this.stop();
} }
@ -191,9 +177,12 @@ export class BookPlayer {
this.bindMediaElementEvents(); this.bindMediaElementEvents();
document.addEventListener('keyup', this.onWindowKeyUp); document.addEventListener('keyup', this.onWindowKeyUp);
this.rendition?.on('keyup', this.onWindowKeyUp);
this.rendition.on('touchstart', this.onTouchStart); const player = document.getElementById('bookPlayerContainer');
this.rendition.on('keyup', this.onWindowKeyUp); this.touchHelper = new TouchHelper(player);
Events.on(this.touchHelper, 'swipeleft', () => this.next());
Events.on(this.touchHelper, 'swiperight', () => this.previous());
} }
unbindMediaElementEvents() { unbindMediaElementEvents() {
@ -216,9 +205,9 @@ export class BookPlayer {
} }
document.removeEventListener('keyup', this.onWindowKeyUp); document.removeEventListener('keyup', this.onWindowKeyUp);
this.rendition?.off('touchstart', this.onTouchStart);
this.rendition?.off('keyup', this.onWindowKeyUp); this.rendition?.off('keyup', this.onWindowKeyUp);
this.touchHelper?.destroy();
} }
openTableOfContents() { openTableOfContents() {
@ -335,9 +324,7 @@ export class BookPlayer {
width: '100%', width: '100%',
height: renderHeight, height: renderHeight,
// TODO: Add option for scrolled-doc // TODO: Add option for scrolled-doc
flow: 'paginated', flow: 'paginated'
// Scripted content is required to allow touch event passthrough in Safari
allowScriptedContent: true
}); });
this.currentSrc = downloadHref; this.currentSrc = downloadHref;

View file

@ -1,3 +1,8 @@
html { html {
font-size: 82% !important; font-size: 82% !important;
} }
// Fix touch events being swallowed by the epubjs iframe
#bookPlayer iframe {
pointer-events: none;
}