From: Alexander Ebert Date: Sat, 2 Jan 2021 11:52:05 +0000 (+0100) Subject: Convert `Controller/Notice/Dismiss` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~484^2~14 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=016b08a0635af671f1b86620d6fac50b6ad4e8f9;p=GitHub%2FWoltLab%2FWCF.git Convert `Controller/Notice/Dismiss` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Notice/Dismiss.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Notice/Dismiss.js index 59ddaf4a94..28c4879e19 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Notice/Dismiss.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Notice/Dismiss.js @@ -1,45 +1,39 @@ /** * Handles dismissible user notices. * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Controller/Notice/Dismiss + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @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 index 1461cea1d5..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Notice/Dismiss.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Handles dismissible user notices. - * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @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 index 0000000000..3e9244eeef --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Notice/Dismiss.ts @@ -0,0 +1,37 @@ +/** + * Handles dismissible user notices. + * + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @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(); + }, + }); +}