Convert `Acp/Ui/Box/Copy` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Sat, 28 Nov 2020 15:48:43 +0000 (16:48 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 28 Nov 2020 15:48:43 +0000 (16:48 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Box/Copy.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Box/Copy.ts [new file with mode: 0644]

index 128e1478d590a0e6b962f2a7a0a9b431f4068a82..7a38228156ec6702a480a43f88b245622eaa797d 100644 (file)
@@ -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 (file)
index 3948830..0000000
+++ /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 (file)
index 0000000..1ecf5fe
--- /dev/null
@@ -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<DialogCallbackSetup> {
+    return {
+      id: "acpBoxCopyDialog",
+      options: {
+        title: Language.get("wcf.acp.box.copy"),
+      },
+    };
+  }
+}
+
+let acpUiBoxCopy: AcpUiBoxCopy;
+
+export function init(): void {
+  if (!acpUiBoxCopy) {
+    acpUiBoxCopy = new AcpUiBoxCopy();
+  }
+}