Convert `Ui/Article/MarkAllAsRead` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Tue, 27 Oct 2020 13:26:33 +0000 (14:26 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 28 Oct 2020 11:57:21 +0000 (12:57 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Article/MarkAllAsRead.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/MarkAllAsRead.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/MarkAllAsRead.ts [new file with mode: 0644]

index 2c80cf6c4c4d8aa13cb897c7dec7ede580830d11..1790d31e99ece0040c88e432c62d3dddff0ff41b 100644 (file)
@@ -1,39 +1,65 @@
 /**
  * Handles the 'mark as read' action for articles.
  *
- * @author     Marcel Werk
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Ui/Article/MarkAllAsRead
+ * @author  Marcel Werk
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Ui/Article/MarkAllAsRead
  */
-define(['Ajax'], function (Ajax) {
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
+}) : (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+    Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+    o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+    __setModuleDefault(result, mod);
+    return result;
+};
+define(["require", "exports", "../../Ajax"], function (require, exports, Ajax) {
     "use strict";
-    return {
-        init: function () {
-            elBySelAll('.markAllAsReadButton', undefined, (function (button) {
-                button.addEventListener(WCF_CLICK_EVENT, this._click.bind(this));
-            }).bind(this));
-        },
-        _click: function (event) {
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.init = void 0;
+    Ajax = __importStar(Ajax);
+    class UiArticleMarkAllAsRead {
+        constructor() {
+            document.querySelectorAll('.markAllAsReadButton').forEach(button => {
+                button.addEventListener('click', this.click.bind(this));
+            });
+        }
+        click(event) {
             event.preventDefault();
             Ajax.api(this);
-        },
-        _ajaxSuccess: function () {
+        }
+        _ajaxSuccess() {
             /* remove obsolete badges */
             // main menu
-            var badge = elBySel('.mainMenu .active .badge');
+            const badge = document.querySelector('.mainMenu .active .badge');
             if (badge)
-                elRemove(badge);
+                badge.remove();
             // article list
-            elBySelAll('.articleList .newMessageBadge', undefined, elRemove);
-        },
-        _ajaxSetup: function () {
+            document.querySelectorAll('.articleList .newMessageBadge').forEach(el => el.remove());
+        }
+        _ajaxSetup() {
             return {
                 data: {
                     actionName: 'markAllAsRead',
-                    className: 'wcf\\data\\article\\ArticleAction'
-                }
+                    className: 'wcf\\data\\article\\ArticleAction',
+                },
             };
         }
-    };
+    }
+    function init() {
+        new UiArticleMarkAllAsRead();
+    }
+    exports.init = init;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/MarkAllAsRead.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/MarkAllAsRead.js
deleted file mode 100644 (file)
index 5cb8889..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Handles the 'mark as read' action for articles.
- * 
- * @author     Marcel Werk
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Ui/Article/MarkAllAsRead
- */
-define(['Ajax'], function(Ajax) {
-       "use strict";
-       
-       return {
-               init: function() {
-                       elBySelAll('.markAllAsReadButton', undefined, (function(button) {
-                               button.addEventListener(WCF_CLICK_EVENT, this._click.bind(this));
-                       }).bind(this));
-               },
-               
-               _click: function(event) {
-                       event.preventDefault();
-                       
-                       Ajax.api(this);
-               },
-               
-               _ajaxSuccess: function() {
-                       /* remove obsolete badges */
-                       // main menu
-                       var badge = elBySel('.mainMenu .active .badge');
-                       if (badge) elRemove(badge);
-                       
-                       // article list
-                       elBySelAll('.articleList .newMessageBadge', undefined, elRemove);
-               },
-               
-               _ajaxSetup: function() {
-                       return {
-                               data: {
-                                       actionName: 'markAllAsRead',
-                                       className: 'wcf\\data\\article\\ArticleAction'
-                               }
-                       };
-               }
-       };
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/MarkAllAsRead.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Article/MarkAllAsRead.ts
new file mode 100644 (file)
index 0000000..10a89e7
--- /dev/null
@@ -0,0 +1,48 @@
+/**
+ * Handles the 'mark as read' action for articles.
+ *
+ * @author  Marcel Werk
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Ui/Article/MarkAllAsRead
+ */
+
+import * as Ajax from '../../Ajax';
+import { AjaxCallbackObject } from '../../Ajax/Data';
+
+class UiArticleMarkAllAsRead implements AjaxCallbackObject {
+  constructor() {
+    document.querySelectorAll('.markAllAsReadButton').forEach(button => {
+      button.addEventListener('click', this.click.bind(this));
+    });
+  }
+
+  private click(event: MouseEvent): void {
+    event.preventDefault();
+
+    Ajax.api(this);
+  }
+
+  _ajaxSuccess() {
+    /* remove obsolete badges */
+    // main menu
+    const badge = document.querySelector('.mainMenu .active .badge');
+    if (badge) badge.remove();
+
+    // article list
+    document.querySelectorAll('.articleList .newMessageBadge').forEach(el => el.remove());
+  }
+
+  _ajaxSetup() {
+    return {
+      data: {
+        actionName: 'markAllAsRead',
+        className: 'wcf\\data\\article\\ArticleAction',
+      },
+    };
+  }
+}
+
+export function init() {
+  new UiArticleMarkAllAsRead();
+}