Convert `Controller/Notice/Dismiss` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Sat, 2 Jan 2021 11:52:05 +0000 (12:52 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 2 Jan 2021 11:52:05 +0000 (12:52 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Notice/Dismiss.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Notice/Dismiss.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Notice/Dismiss.ts [new file with mode: 0644]

index 59ddaf4a94b6626f645be2db43e4436ae73c2c24..28c4879e190ba5925c4ca4820752f5b17b5d04c0 100644 (file)
@@ -1,45 +1,39 @@
 /**
  * Handles dismissible user notices.
  *
- * @author     Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Controller/Notice/Dismiss
+ * @author  Alexander Ebert
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Controller/Notice/Dismiss
  */
-define(['Ajax'], function (Ajax) {
+define(["require", "exports", "tslib", "../../Ajax"], function (require, exports, tslib_1, Ajax) {
     "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.setup = void 0;
+    Ajax = tslib_1.__importStar(Ajax);
     /**
-     * @exports        WoltLabSuite/Core/Controller/Notice/Dismiss
+     * Initializes dismiss buttons.
      */
-    var ControllerNoticeDismiss = {
-        /**
-         * Initializes dismiss buttons.
-         */
-        setup: function () {
-            var buttons = elByClass('jsDismissNoticeButton');
-            if (buttons.length) {
-                var clickCallback = this._click.bind(this);
-                for (var i = 0, length = buttons.length; i < length; i++) {
-                    buttons[i].addEventListener('click', clickCallback);
-                }
-            }
-        },
-        /**
-         * Sends a request to dismiss a notice and removes it afterwards.
-         */
-        _click: function (event) {
-            var button = event.currentTarget;
-            Ajax.apiOnce({
-                data: {
-                    actionName: 'dismiss',
-                    className: 'wcf\\data\\notice\\NoticeAction',
-                    objectIDs: [elData(button, 'object-id')]
-                },
-                success: function () {
-                    elRemove(button.parentNode);
-                }
-            });
-        }
-    };
-    return ControllerNoticeDismiss;
+    function setup() {
+        document.querySelectorAll(".jsDismissNoticeButton").forEach((button) => {
+            button.addEventListener("click", (ev) => click(ev));
+        });
+    }
+    exports.setup = setup;
+    /**
+     * Sends a request to dismiss a notice and removes it afterwards.
+     */
+    function click(event) {
+        const button = event.currentTarget;
+        Ajax.apiOnce({
+            data: {
+                actionName: "dismiss",
+                className: "wcf\\data\\notice\\NoticeAction",
+                objectIDs: [button.dataset.objectId],
+            },
+            success: () => {
+                button.parentElement.remove();
+            },
+        });
+    }
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Notice/Dismiss.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Notice/Dismiss.js
deleted file mode 100644 (file)
index 1461cea..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Handles dismissible user notices.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Controller/Notice/Dismiss
- */
-define(['Ajax'], function(Ajax) {
-       "use strict";
-       
-       /**
-        * @exports     WoltLabSuite/Core/Controller/Notice/Dismiss
-        */
-       var ControllerNoticeDismiss = {
-               /**
-                * Initializes dismiss buttons.
-                */
-               setup: function() {
-                       var buttons = elByClass('jsDismissNoticeButton');
-                       
-                       if (buttons.length) {
-                               var clickCallback = this._click.bind(this);
-                               for (var i = 0, length = buttons.length; i < length; i++) {
-                                       buttons[i].addEventListener('click', clickCallback);
-                               }
-                       }
-               },
-               
-               /**
-                * Sends a request to dismiss a notice and removes it afterwards.
-                */
-               _click: function(event) {
-                       var button = event.currentTarget;
-                       
-                       Ajax.apiOnce({
-                               data: {
-                                       actionName: 'dismiss',
-                                       className: 'wcf\\data\\notice\\NoticeAction',
-                                       objectIDs: [ elData(button, 'object-id') ]
-                               },
-                               success: function() {
-                                       elRemove(button.parentNode);
-                               }
-                       });
-               }
-       };
-       
-       return ControllerNoticeDismiss;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Notice/Dismiss.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Notice/Dismiss.ts
new file mode 100644 (file)
index 0000000..3e9244e
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * Handles dismissible user notices.
+ *
+ * @author  Alexander Ebert
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Controller/Notice/Dismiss
+ */
+
+import * as Ajax from "../../Ajax";
+
+/**
+ * Initializes dismiss buttons.
+ */
+export function setup(): void {
+  document.querySelectorAll(".jsDismissNoticeButton").forEach((button) => {
+    button.addEventListener("click", (ev) => click(ev));
+  });
+}
+
+/**
+ * Sends a request to dismiss a notice and removes it afterwards.
+ */
+function click(event: Event): void {
+  const button = event.currentTarget as HTMLElement;
+
+  Ajax.apiOnce({
+    data: {
+      actionName: "dismiss",
+      className: "wcf\\data\\notice\\NoticeAction",
+      objectIDs: [button.dataset.objectId!],
+    },
+    success: () => {
+      button.parentElement!.remove();
+    },
+  });
+}