From 007c11f04a256a2e8704a9b26320e5c0e3457994 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 26 Oct 2023 21:04:02 +0200 Subject: treewide: use fat arrow syntax --- beamer/viewer/presentation.js | 17 ++++++++--------- beamer/viewer/screen/screen.js | 14 +++++--------- beamer/viewer/stage/actions.js | 28 ++++++++++------------------ beamer/viewer/stage/stage.js | 29 +++++++++++++---------------- beamer/viewer/viewer.js | 29 +++++++++++++---------------- 5 files changed, 49 insertions(+), 68 deletions(-) (limited to 'beamer') diff --git a/beamer/viewer/presentation.js b/beamer/viewer/presentation.js index fd03288..753027b 100644 --- a/beamer/viewer/presentation.js +++ b/beamer/viewer/presentation.js @@ -30,11 +30,11 @@ class Presentation { } _setupStage() { - const self = this; - const onStageReadyCallback = function() { self._onStageReady(); }; - const onNextCallback = function() { self._onNext(); }; - const onPreviousCallback = function() { self._onPrevious(); }; - return new Stage(onStageReadyCallback, onNextCallback, onPreviousCallback); + return new Stage( + () => this._onStageReady(), + () => this._onNext(), + () => this._onPrevious(), + ); } _onStageReady() { @@ -52,10 +52,9 @@ class Presentation { } _setPage(pageIndex) { - const self = this; this.currentPageIndex = pageIndex; - this.pdf.getPage(this.currentPageIndex).then(function(page) { - self.stage.setPage(page); - }) + this.pdf + .getPage(this.currentPageIndex) + .then(page => this.stage.setPage(page)) } } diff --git a/beamer/viewer/screen/screen.js b/beamer/viewer/screen/screen.js index c65ebc3..7cfc54b 100644 --- a/beamer/viewer/screen/screen.js +++ b/beamer/viewer/screen/screen.js @@ -1,6 +1,6 @@ /* * Beamer Viewer, a web-based PDF presentation viewer - * Copyright (C) 2018 Pacien TRAN-GIRARD + * Copyright (C) 2018-2023 Pacien TRAN-GIRARD * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -42,10 +42,7 @@ class Screen { } _registerListeners() { - const self = this; - this.window.addEventListener("resize", function() { - self._repaint(); - }); + this.window.addEventListener("resize", () => this._repaint()); } _hideWelcomeScreen() { @@ -91,10 +88,9 @@ class Screen { viewport: this.page.getViewport(scaleFactor) }; - const self = this; - this.page.render(renderContext).then(function() { - self._showCanvas(canvas); - }); + this.page + .render(renderContext) + .then(() => this._showCanvas(canvas)); } _repaint() { diff --git a/beamer/viewer/stage/actions.js b/beamer/viewer/stage/actions.js index 30634ae..47eda60 100644 --- a/beamer/viewer/stage/actions.js +++ b/beamer/viewer/stage/actions.js @@ -1,6 +1,6 @@ /* * Beamer Viewer, a web-based PDF presentation viewer - * Copyright (C) 2018 Pacien TRAN-GIRARD + * Copyright (C) 2018-2023 Pacien TRAN-GIRARD * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -27,10 +27,7 @@ class ActionEventHandler { class KeyboardEventHandler extends ActionEventHandler { register(window) { - const self = this; - window.addEventListener("keydown", function(event) { - self._onCommand(event); - }) + window.addEventListener("keydown", event => this._onCommand(event)); } _onCommand(keyboardEvent) { @@ -52,10 +49,7 @@ class KeyboardEventHandler extends ActionEventHandler { class MouseClickEventHandler extends ActionEventHandler { register(window) { - const self = this; - window.addEventListener("click", function(event) { - self._onCommand(event); - }) + window.addEventListener("click", event => this._onCommand(event)); } _onCommand(mouseEvent) { @@ -71,24 +65,22 @@ class TouchSwipeEventHandler extends ActionEventHandler { } register(window) { - const self = this; - - window.addEventListener("touchstart", function(event) { + window.addEventListener("touchstart", event => { event.preventDefault(); - self._onTouchStart(event); + this._onTouchStart(event); }); - window.addEventListener("touchmove", function(event) { + window.addEventListener("touchmove", event => { event.preventDefault(); - self._onTouchMove(event); + this._onTouchMove(event); }); - window.addEventListener("touchend", function(event) { + window.addEventListener("touchend", event => { event.preventDefault(); - self._onTouchEnd(); + this._onTouchEnd(); }); - window.addEventListener("touchcancel", function(event) { + window.addEventListener("touchcancel", event => { event.preventDefault(); }); } diff --git a/beamer/viewer/stage/stage.js b/beamer/viewer/stage/stage.js index 3f1a5f5..4882c31 100644 --- a/beamer/viewer/stage/stage.js +++ b/beamer/viewer/stage/stage.js @@ -36,12 +36,11 @@ class Stage { if (this.projector == null) alert("Please allow pop-ups, then refresh this page."); - const self = this; - this.projector.addEventListener("load", function() { - self.audienceScreen = new Screen(self.projector, false, false); - self.presenterScreen = new Screen(window, true, true); - self._watchDetach(); - self.onReady(); + this.projector.addEventListener("load", () => { + this.audienceScreen = new Screen(this.projector, false, false); + this.presenterScreen = new Screen(window, true, true); + this._watchDetach(); + this.onReady(); }); this._registerEventHandler(window); @@ -56,20 +55,18 @@ class Stage { _registerEventHandler(window) { if (window == null) return; - this.eventHandlers.forEach(function(eventHandler) { - eventHandler.register(window); - }); + this.eventHandlers + .forEach(eventHandler => eventHandler.register(window)); } _watchDetach() { - const self = this; - window.addEventListener("beforeunload", function() { - self._setMessage(self.projector, "Controller detached"); - }); + window.addEventListener("beforeunload", () => + this._setMessage(this.projector, "Controller detached") + ); - this.projector.addEventListener("beforeunload", function() { - self._setMessage(window, "Viewer detached"); - }); + this.projector.addEventListener("beforeunload", () => + this._setMessage(window, "Viewer detached") + ); } _setMessage(window, message) { diff --git a/beamer/viewer/viewer.js b/beamer/viewer/viewer.js index d8d7668..a10e6de 100644 --- a/beamer/viewer/viewer.js +++ b/beamer/viewer/viewer.js @@ -35,10 +35,9 @@ class Viewer { } _preparePresentation(source) { - const self = this; - pdfjsLib.getDocument(source).then(function(pdf) { - self.presentation = new Presentation(pdf); - }).catch(function(error) { + pdfjsLib.getDocument(source).then(pdf => { + this.presentation = new Presentation(pdf); + }).catch(error => { console.error(error); window.alert("Error while loading presentation:\n\n" + error.message); window.location.href = window.location.pathname; // reload without "?file=..." @@ -46,9 +45,8 @@ class Viewer { } _readFile(file) { - const self = this; - this.fileReader.onload = function() { - self._setPresentation(new Uint8Array(this.result)); + this.fileReader.onload = () => { + this._setPresentation(new Uint8Array(this.result)); } this.fileReader.abort(); @@ -72,25 +70,24 @@ class Viewer { } _listenForInput() { - const self = this; - fileInput.addEventListener("change", function(event) { - self._readFile(event.target.files[0]); + fileInput.addEventListener("change", event => { + this._readFile(event.target.files[0]); }); - startButton.addEventListener("click", function(event) { + startButton.addEventListener("click", event => { event.preventDefault(); event.stopPropagation(); - self.presentation.start(); + this.presentation.start(); }); - document.body.addEventListener("drop", function(event) { + document.body.addEventListener("drop", event => { event.preventDefault(); event.stopPropagation(); - self.fileInput.files = event.dataTransfer.files; - self._readFile(event.dataTransfer.files[0]); + this.fileInput.files = event.dataTransfer.files; + this._readFile(event.dataTransfer.files[0]); }); - document.body.addEventListener("dragover", function(event) { + document.body.addEventListener("dragover", event => { event.preventDefault(); event.stopPropagation(); }); -- cgit v1.2.3