Convert `Acp/Ui/Page/Copy` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Mon, 30 Nov 2020 00:39:47 +0000 (01:39 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 30 Nov 2020 00:39:47 +0000 (01:39 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Page/Copy.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Copy.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Copy.ts [new file with mode: 0644]

index f6ebe6489172f5cc30ee0c4dcbb353f1e80ce541..65bde4ade3f2da1eb35a6362c195d8773ee25397 100644 (file)
@@ -1,25 +1,33 @@
-define(['Language', 'Ui/Dialog'], function (Language, UiDialog) {
-    return {
-        init: function () {
-            elBySelAll('.jsButtonCopyPage', 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, Dialog_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.init = void 0;
+    Language = tslib_1.__importStar(Language);
+    Dialog_1 = tslib_1.__importDefault(Dialog_1);
+    class AcpUiPageCopy {
+        constructor() {
+            document.querySelectorAll(".jsButtonCopyPage").forEach((button) => {
+                button.addEventListener("click", (ev) => this.click(ev));
+            });
+        }
+        click(event) {
             event.preventDefault();
-            UiDialog.open(this);
-        },
-        _dialogSetup: function () {
+            Dialog_1.default.open(this);
+        }
+        _dialogSetup() {
             return {
-                id: 'acpPageCopyDialog',
+                id: "acpPageCopyDialog",
                 options: {
-                    title: Language.get('wcf.acp.page.copy')
-                }
+                    title: Language.get("wcf.acp.page.copy"),
+                },
             };
         }
-    };
+    }
+    let acpUiPageCopy;
+    function init() {
+        if (!acpUiPageCopy) {
+            acpUiPageCopy = new AcpUiPageCopy();
+        }
+    }
+    exports.init = init;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Copy.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Copy.js
deleted file mode 100644 (file)
index 41a1c21..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-define(['Language', 'Ui/Dialog'], function(Language, UiDialog) {
-       return {
-               init: function () {
-                       elBySelAll('.jsButtonCopyPage', 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: 'acpPageCopyDialog',
-                               options: {
-                                       title: Language.get('wcf.acp.page.copy')
-                               }
-                       };
-               }
-       };
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Copy.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Page/Copy.ts
new file mode 100644 (file)
index 0000000..7e25611
--- /dev/null
@@ -0,0 +1,34 @@
+import { DialogCallbackObject, DialogCallbackSetup } from "../../../Ui/Dialog/Data";
+import * as Language from "../../../Language";
+import UiDialog from "../../../Ui/Dialog";
+
+class AcpUiPageCopy implements DialogCallbackObject {
+  constructor() {
+    document.querySelectorAll(".jsButtonCopyPage").forEach((button: HTMLAnchorElement) => {
+      button.addEventListener("click", (ev) => this.click(ev));
+    });
+  }
+
+  private click(event: MouseEvent): void {
+    event.preventDefault();
+
+    UiDialog.open(this);
+  }
+
+  _dialogSetup(): ReturnType<DialogCallbackSetup> {
+    return {
+      id: "acpPageCopyDialog",
+      options: {
+        title: Language.get("wcf.acp.page.copy"),
+      },
+    };
+  }
+}
+
+let acpUiPageCopy: AcpUiPageCopy;
+
+export function init(): void {
+  if (!acpUiPageCopy) {
+    acpUiPageCopy = new AcpUiPageCopy();
+  }
+}