From a511569ea58db245f48eab047b154a458a74cb03 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 28 Nov 2020 16:48:43 +0100 Subject: [PATCH] Convert `Acp/Ui/Box/Copy` to TypeScript --- .../js/WoltLabSuite/Core/Acp/Ui/Box/Copy.js | 44 +++++++++++-------- .../ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.js | 28 ------------ .../ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.ts | 34 ++++++++++++++ 3 files changed, 60 insertions(+), 46 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Box/Copy.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Box/Copy.js index 128e1478d5..7a38228156 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Box/Copy.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Box/Copy.js @@ -1,25 +1,33 @@ -define(['Language', 'Ui/Dialog'], function (Language, UiDialog) { - return { - init: function () { - elBySelAll('.jsButtonCopyBox', undefined, (function (button) { - button.addEventListener('click', this._click.bind(this)); - }).bind(this)); - }, - /** - * @param {Event} event - * @protected - */ - _click: function (event) { +define(["require", "exports", "tslib", "../../../Language", "../../../Ui/Dialog"], function (require, exports, tslib_1, Language, UiDialog) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.init = void 0; + Language = tslib_1.__importStar(Language); + UiDialog = tslib_1.__importStar(UiDialog); + class AcpUiBoxCopy { + constructor() { + document.querySelectorAll(".jsButtonCopyBox").forEach((button) => { + button.addEventListener("click", (ev) => this.click(ev)); + }); + } + click(event) { event.preventDefault(); UiDialog.open(this); - }, - _dialogSetup: function () { + } + _dialogSetup() { return { - id: 'acpBoxCopyDialog', + id: "acpBoxCopyDialog", options: { - title: Language.get('wcf.acp.box.copy') - } + title: Language.get("wcf.acp.box.copy"), + }, }; } - }; + } + let acpUiBoxCopy; + function init() { + if (!acpUiBoxCopy) { + acpUiBoxCopy = new AcpUiBoxCopy(); + } + } + exports.init = init; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.js deleted file mode 100644 index 3948830d9d..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.js +++ /dev/null @@ -1,28 +0,0 @@ -define(['Language', 'Ui/Dialog'], function(Language, UiDialog) { - return { - init: function () { - elBySelAll('.jsButtonCopyBox', undefined, (function(button) { - button.addEventListener('click', this._click.bind(this)); - }).bind(this)); - }, - - /** - * @param {Event} event - * @protected - */ - _click: function (event) { - event.preventDefault(); - - UiDialog.open(this); - }, - - _dialogSetup: function () { - return { - id: 'acpBoxCopyDialog', - options: { - title: Language.get('wcf.acp.box.copy') - } - }; - } - }; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.ts new file mode 100644 index 0000000000..1ecf5fe509 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.ts @@ -0,0 +1,34 @@ +import { DialogCallbackObject, DialogCallbackSetup } from "../../../Ui/Dialog/Data"; +import * as Language from "../../../Language"; +import * as UiDialog from "../../../Ui/Dialog"; + +class AcpUiBoxCopy implements DialogCallbackObject { + constructor() { + document.querySelectorAll(".jsButtonCopyBox").forEach((button: HTMLElement) => { + button.addEventListener("click", (ev) => this.click(ev)); + }); + } + + private click(event: MouseEvent): void { + event.preventDefault(); + + UiDialog.open(this); + } + + _dialogSetup(): ReturnType { + return { + id: "acpBoxCopyDialog", + options: { + title: Language.get("wcf.acp.box.copy"), + }, + }; + } +} + +let acpUiBoxCopy: AcpUiBoxCopy; + +export function init(): void { + if (!acpUiBoxCopy) { + acpUiBoxCopy = new AcpUiBoxCopy(); + } +} -- 2.20.1