From dbfda6ff8abb6ad69956f5f4506dc11a31fdd68d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 21 Oct 2020 22:26:25 +0200 Subject: [PATCH] Convert `Ui/CloseOverlay` to TypeScript --- .../js/WoltLabSuite/Core/Ui/CloseOverlay.js | 43 ++++++++----------- .../ts/WoltLabSuite/Core/Ui/CloseOverlay.js | 42 ------------------ .../ts/WoltLabSuite/Core/Ui/CloseOverlay.ts | 36 ++++++++++++++++ 3 files changed, 54 insertions(+), 67 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/CloseOverlay.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/CloseOverlay.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/CloseOverlay.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/CloseOverlay.js index 42073d6dcc..9acd0c4a8c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/CloseOverlay.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/CloseOverlay.js @@ -1,42 +1,35 @@ /** * Allows to be informed when a click event bubbled up to the document's body. * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module Ui/CloseOverlay (alias) - * @module WoltLabSuite/Core/Ui/CloseOverlay + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module Ui/CloseOverlay (alias) + * @module WoltLabSuite/Core/Ui/CloseOverlay */ -define(['CallbackList'], function (CallbackList) { +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +define(["require", "exports", "../CallbackList"], function (require, exports, CallbackList_1) { "use strict"; - var _callbackList = new CallbackList(); - /** - * @exports WoltLabSuite/Core/Ui/CloseOverlay - */ - var UiCloseOverlay = { + CallbackList_1 = __importDefault(CallbackList_1); + const _callbackList = new CallbackList_1.default(); + const UiCloseOverlay = { /** - * Sets up global event listener for bubbled clicks events. - */ - setup: function () { - document.body.addEventListener(WCF_CLICK_EVENT, this.execute.bind(this)); - }, - /** - * @see WoltLabSuite/Core/CallbackList#add + * @see CallbackList.add */ add: _callbackList.add.bind(_callbackList), /** - * @see WoltLabSuite/Core/CallbackList#remove + * @see CallbackList.remove */ remove: _callbackList.remove.bind(_callbackList), /** * Invokes all registered callbacks. */ - execute: function () { - _callbackList.forEach(null, function (callback) { - callback(); - }); - } + execute() { + _callbackList.forEach(null, callback => callback()); + }, }; - UiCloseOverlay.setup(); + document.body.addEventListener('click', UiCloseOverlay.execute); return UiCloseOverlay; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/CloseOverlay.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/CloseOverlay.js deleted file mode 100644 index 42073d6dcc..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/CloseOverlay.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Allows to be informed when a click event bubbled up to the document's body. - * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module Ui/CloseOverlay (alias) - * @module WoltLabSuite/Core/Ui/CloseOverlay - */ -define(['CallbackList'], function (CallbackList) { - "use strict"; - var _callbackList = new CallbackList(); - /** - * @exports WoltLabSuite/Core/Ui/CloseOverlay - */ - var UiCloseOverlay = { - /** - * Sets up global event listener for bubbled clicks events. - */ - setup: function () { - document.body.addEventListener(WCF_CLICK_EVENT, this.execute.bind(this)); - }, - /** - * @see WoltLabSuite/Core/CallbackList#add - */ - add: _callbackList.add.bind(_callbackList), - /** - * @see WoltLabSuite/Core/CallbackList#remove - */ - remove: _callbackList.remove.bind(_callbackList), - /** - * Invokes all registered callbacks. - */ - execute: function () { - _callbackList.forEach(null, function (callback) { - callback(); - }); - } - }; - UiCloseOverlay.setup(); - return UiCloseOverlay; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/CloseOverlay.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/CloseOverlay.ts new file mode 100644 index 0000000000..6e9c8a4c17 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/CloseOverlay.ts @@ -0,0 +1,36 @@ +/** + * Allows to be informed when a click event bubbled up to the document's body. + * + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module Ui/CloseOverlay (alias) + * @module WoltLabSuite/Core/Ui/CloseOverlay + */ + +import CallbackList from '../CallbackList'; + +const _callbackList = new CallbackList(); + +const UiCloseOverlay = { + /** + * @see CallbackList.add + */ + add: _callbackList.add.bind(_callbackList), + + /** + * @see CallbackList.remove + */ + remove: _callbackList.remove.bind(_callbackList), + + /** + * Invokes all registered callbacks. + */ + execute() { + _callbackList.forEach(null, callback => callback()); + }, +}; + +document.body.addEventListener('click', UiCloseOverlay.execute); + +export = UiCloseOverlay; -- 2.20.1