mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Refactor book player to make use of lambdas and get rid of self
This commit is contained in:
parent
c7a89ae74b
commit
063ef77ff1
1 changed files with 13 additions and 14 deletions
|
@ -78,7 +78,7 @@ export class BookPlayer {
|
||||||
links.forEach((link) => {
|
links.forEach((link) => {
|
||||||
let href = link.getAttribute('href');
|
let href = link.getAttribute('href');
|
||||||
|
|
||||||
link.onclick = function () {
|
link.onclick = () => {
|
||||||
f(href);
|
f(href);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -115,11 +115,11 @@ export class BookPlayer {
|
||||||
|
|
||||||
elem.innerHTML = html;
|
elem.innerHTML = html;
|
||||||
|
|
||||||
elem.querySelector('.btnBookplayerExit').addEventListener('click', function () {
|
elem.querySelector('.btnBookplayerExit').addEventListener('click', () => {
|
||||||
dialogHelper.close(elem);
|
dialogHelper.close(elem);
|
||||||
});
|
});
|
||||||
|
|
||||||
elem.querySelector('.btnBookplayerToc').addEventListener('click', function () {
|
elem.querySelector('.btnBookplayerToc').addEventListener('click', () => {
|
||||||
let rendition = this._rendition;
|
let rendition = this._rendition;
|
||||||
if (rendition) {
|
if (rendition) {
|
||||||
let tocElement = dialogHelper.createDialog({
|
let tocElement = dialogHelper.createDialog({
|
||||||
|
@ -143,7 +143,7 @@ export class BookPlayer {
|
||||||
tocHtml += '</ul>';
|
tocHtml += '</ul>';
|
||||||
tocElement.innerHTML = tocHtml;
|
tocElement.innerHTML = tocHtml;
|
||||||
|
|
||||||
tocElement.querySelector('.btnBookplayerTocClose').addEventListener('click', function () {
|
tocElement.querySelector('.btnBookplayerTocClose').addEventListener('click', () => {
|
||||||
dialogHelper.close(tocElement);
|
dialogHelper.close(tocElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ export class BookPlayer {
|
||||||
|
|
||||||
dialogHelper.open(tocElement);
|
dialogHelper.open(tocElement);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
});
|
||||||
|
|
||||||
dialogHelper.open(elem);
|
dialogHelper.open(elem);
|
||||||
|
|
||||||
|
@ -192,24 +192,23 @@ export class BookPlayer {
|
||||||
let serverId = item.ServerId;
|
let serverId = item.ServerId;
|
||||||
let apiClient = connectionManager.getApiClient(serverId);
|
let apiClient = connectionManager.getApiClient(serverId);
|
||||||
|
|
||||||
const self = this;
|
return new Promise((resolve, reject) => {
|
||||||
return new Promise(function (resolve, reject) {
|
require(['epubjs'], (epubjs) => {
|
||||||
require(['epubjs'], function (epubjs) {
|
|
||||||
let downloadHref = apiClient.getItemDownloadUrl(item.Id);
|
let downloadHref = apiClient.getItemDownloadUrl(item.Id);
|
||||||
let book = epubjs.default(downloadHref, {openAs: 'epub'});
|
let book = epubjs.default(downloadHref, {openAs: 'epub'});
|
||||||
let rendition = book.renderTo(elem, {width: '100%', height: '97%'});
|
let rendition = book.renderTo(elem, {width: '100%', height: '97%'});
|
||||||
|
|
||||||
self._currentSrc = downloadHref;
|
this._currentSrc = downloadHref;
|
||||||
self._rendition = rendition;
|
this._rendition = rendition;
|
||||||
return rendition.display().then(function () {
|
return rendition.display().then(() => {
|
||||||
document.addEventListener('keyup', self.onWindowKeyUp.bind(self));
|
document.addEventListener('keyup', this.onWindowKeyUp.bind(this));
|
||||||
|
|
||||||
// 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
|
||||||
self._rendition.on('keyup', self.onWindowKeyUp.bind(self));
|
this._rendition.on('keyup', this.onWindowKeyUp.bind(this));
|
||||||
|
|
||||||
loading.hide();
|
loading.hide();
|
||||||
return resolve();
|
return resolve();
|
||||||
}, function () {
|
}, () => {
|
||||||
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