mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
add paging in book player with touch events
This commit is contained in:
parent
6f1fc1e4a5
commit
c76f550b91
1 changed files with 36 additions and 11 deletions
|
@ -2,6 +2,7 @@ import connectionManager from 'connectionManager';
|
||||||
import loading from 'loading';
|
import loading from 'loading';
|
||||||
import keyboardnavigation from 'keyboardnavigation';
|
import keyboardnavigation from 'keyboardnavigation';
|
||||||
import dialogHelper from 'dialogHelper';
|
import dialogHelper from 'dialogHelper';
|
||||||
|
import dom from 'dom';
|
||||||
import events from 'events';
|
import events from 'events';
|
||||||
import 'css!./style';
|
import 'css!./style';
|
||||||
import 'material-icons';
|
import 'material-icons';
|
||||||
|
@ -93,23 +94,22 @@ export class BookPlayer {
|
||||||
|
|
||||||
onWindowKeyUp(e) {
|
onWindowKeyUp(e) {
|
||||||
let key = keyboardnavigation.getKeyName(e);
|
let key = keyboardnavigation.getKeyName(e);
|
||||||
let rendition = this._rendition;
|
|
||||||
|
// TODO: depending on the event this can be the document or the rendition itself
|
||||||
|
let rendition = this._rendition || this;
|
||||||
let book = rendition.book;
|
let book = rendition.book;
|
||||||
|
|
||||||
|
if (this._loaded === false) return;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'l':
|
case 'l':
|
||||||
case 'ArrowRight':
|
case 'ArrowRight':
|
||||||
case 'Right':
|
case 'Right':
|
||||||
if (this._loaded) {
|
book.package.metadata.direction === 'rtl' ? rendition.prev() : rendition.next();
|
||||||
book.package.metadata.direction === 'rtl' ? rendition.prev() : rendition.next();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
case 'ArrowLeft':
|
case 'ArrowLeft':
|
||||||
case 'Left':
|
case 'Left':
|
||||||
if (this._loaded) {
|
book.package.metadata.direction === 'rtl' ? rendition.next() : rendition.prev();
|
||||||
book.package.metadata.direction === 'rtl' ? rendition.next() : rendition.prev();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'Escape':
|
case 'Escape':
|
||||||
if (this._tocElement) {
|
if (this._tocElement) {
|
||||||
|
@ -123,6 +123,25 @@ export class BookPlayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onTouchStart(e) {
|
||||||
|
// TODO: depending on the event this can be the document or the rendition itself
|
||||||
|
let rendition = this._rendition || this;
|
||||||
|
let book = rendition.book;
|
||||||
|
|
||||||
|
// check that the event is from the book or the document
|
||||||
|
if (!book || this._loaded === false) return;
|
||||||
|
|
||||||
|
// epubjs stores pages off the screen or something for preloading
|
||||||
|
// get the modulus of the touch event to account for the increased width
|
||||||
|
if (!e.touches || e.touches.length === 0) return;
|
||||||
|
let touch = e.touches[0].clientX % dom.getWindowSize().innerWidth;
|
||||||
|
if (touch < dom.getWindowSize().innerWidth / 2) {
|
||||||
|
book.package.metadata.direction === 'rtl' ? rendition.next() : rendition.prev();
|
||||||
|
} else {
|
||||||
|
book.package.metadata.direction === 'rtl' ? rendition.prev() : rendition.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onDialogClosed() {
|
onDialogClosed() {
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
@ -139,8 +158,11 @@ export class BookPlayer {
|
||||||
this.bindMediaElementEvents();
|
this.bindMediaElementEvents();
|
||||||
|
|
||||||
document.addEventListener('keyup', this.onWindowKeyUp);
|
document.addEventListener('keyup', this.onWindowKeyUp);
|
||||||
|
document.addEventListener('touchstart', this.onTouchStart);
|
||||||
|
|
||||||
// FIXME: I don't really get why document keyup event is not triggered when epub is in focus
|
// FIXME: I don't really get why document keyup event is not triggered when epub is in focus
|
||||||
this._rendition.on('keyup', this.onWindowKeyUp);
|
this._rendition.on('keyup', this.onWindowKeyUp);
|
||||||
|
this._rendition.on('touchstart', this.onTouchStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
unbindMediaElementEvents() {
|
unbindMediaElementEvents() {
|
||||||
|
@ -155,9 +177,13 @@ export class BookPlayer {
|
||||||
if (this._mediaElement) {
|
if (this._mediaElement) {
|
||||||
this.unbindMediaElementEvents();
|
this.unbindMediaElementEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.removeEventListener('keyup', this.onWindowKeyUp);
|
document.removeEventListener('keyup', this.onWindowKeyUp);
|
||||||
|
document.removeEventListener('touchstart', this.onTouchStart);
|
||||||
|
|
||||||
if (this._rendition) {
|
if (this._rendition) {
|
||||||
this._rendition.off('keyup', this.onWindowKeyUp);
|
this._rendition.off('keyup', this.onWindowKeyUp);
|
||||||
|
this._rendition.off('touchstart', this.onTouchStart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,13 +195,11 @@ export class BookPlayer {
|
||||||
|
|
||||||
createMediaElement() {
|
createMediaElement() {
|
||||||
let elem = this._mediaElement;
|
let elem = this._mediaElement;
|
||||||
|
|
||||||
if (elem) {
|
if (elem) {
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
elem = document.getElementById('bookPlayer');
|
elem = document.getElementById('bookPlayer');
|
||||||
|
|
||||||
if (!elem) {
|
if (!elem) {
|
||||||
elem = dialogHelper.createDialog({
|
elem = dialogHelper.createDialog({
|
||||||
exitAnimationDuration: 400,
|
exitAnimationDuration: 400,
|
||||||
|
@ -185,6 +209,7 @@ export class BookPlayer {
|
||||||
exitAnimation: 'fadeout',
|
exitAnimation: 'fadeout',
|
||||||
removeOnClose: true
|
removeOnClose: true
|
||||||
});
|
});
|
||||||
|
|
||||||
elem.id = 'bookPlayer';
|
elem.id = 'bookPlayer';
|
||||||
|
|
||||||
let html = '';
|
let html = '';
|
||||||
|
@ -230,6 +255,7 @@ export class BookPlayer {
|
||||||
let cancellationToken = {
|
let cancellationToken = {
|
||||||
shouldCancel: false
|
shouldCancel: false
|
||||||
};
|
};
|
||||||
|
|
||||||
this._cancellationToken = cancellationToken;
|
this._cancellationToken = cancellationToken;
|
||||||
|
|
||||||
return rendition.display().then(() => {
|
return rendition.display().then(() => {
|
||||||
|
@ -253,7 +279,6 @@ export class BookPlayer {
|
||||||
epubElem.style.display = 'block';
|
epubElem.style.display = 'block';
|
||||||
rendition.on('relocated', (locations) => {
|
rendition.on('relocated', (locations) => {
|
||||||
this._progress = book.locations.percentageFromCfi(locations.start.cfi);
|
this._progress = book.locations.percentageFromCfi(locations.start.cfi);
|
||||||
|
|
||||||
events.trigger(this, 'timeupdate');
|
events.trigger(this, 'timeupdate');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -262,7 +287,7 @@ export class BookPlayer {
|
||||||
return resolve();
|
return resolve();
|
||||||
});
|
});
|
||||||
}, () => {
|
}, () => {
|
||||||
console.error('Failed to display epub');
|
console.error('failed to display epub');
|
||||||
return reject();
|
return reject();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue