From: Alexander Ebert Date: Sat, 2 Jan 2021 11:10:28 +0000 (+0100) Subject: Convert `BootstrapFrontend` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~484^2~17 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=22548180d2a5be68da352c5f788afa53891bc3f3;p=GitHub%2FWoltLab%2FWCF.git Convert `BootstrapFrontend` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js b/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js index 5fde68b34a..2c370e1970 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js @@ -1,63 +1,62 @@ /** * Bootstraps WCF's JavaScript with additions for the frontend usage. * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/BootstrapFrontend + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/BootstrapFrontend */ -define([ - 'WoltLabSuite/Core/BackgroundQueue', 'WoltLabSuite/Core/Bootstrap', 'WoltLabSuite/Core/Controller/Style/Changer', - 'WoltLabSuite/Core/Controller/Popover', 'WoltLabSuite/Core/Ui/User/Ignore', 'WoltLabSuite/Core/Ui/Page/Header/Menu', - 'WoltLabSuite/Core/Ui/Message/UserConsent' -], function (BackgroundQueue, Bootstrap, ControllerStyleChanger, ControllerPopover, UiUserIgnore, UiPageHeaderMenu, UiMessageUserConsent) { +define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Controller/Style/Changer", "./Controller/Popover", "./Ui/User/Ignore", "./Ui/Page/Header/Menu", "./Ui/Message/UserConsent"], function (require, exports, tslib_1, BackgroundQueue, Bootstrap, ControllerStyleChanger, ControllerPopover, UiUserIgnore, UiPageHeaderMenu, UiMessageUserConsent) { "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.setup = void 0; + BackgroundQueue = tslib_1.__importStar(BackgroundQueue); + Bootstrap = tslib_1.__importStar(Bootstrap); + ControllerStyleChanger = tslib_1.__importStar(ControllerStyleChanger); + ControllerPopover = tslib_1.__importStar(ControllerPopover); + UiUserIgnore = tslib_1.__importStar(UiUserIgnore); + UiPageHeaderMenu = tslib_1.__importStar(UiPageHeaderMenu); + UiMessageUserConsent = tslib_1.__importStar(UiMessageUserConsent); /** - * @exports WoltLabSuite/Core/BootstrapFrontend + * Initializes user profile popover. */ - return { - /** - * Bootstraps general modules and frontend exclusive ones. - * - * @param {object} options bootstrap options - */ - setup: function (options) { - // fix the background queue URL to always run against the current domain (avoiding CORS) - options.backgroundQueue.url = WSC_API_URL + options.backgroundQueue.url.substr(WCF_PATH.length); - Bootstrap.setup(); - UiPageHeaderMenu.init(); - if (options.styleChanger) { - ControllerStyleChanger.setup(); - } - if (options.enableUserPopover) { - this._initUserPopover(); - } - BackgroundQueue.setUrl(options.backgroundQueue.url); - if (Math.random() < 0.1 || options.backgroundQueue.force) { - // invoke the queue roughly every 10th request or on demand - BackgroundQueue.invoke(); - } - if (COMPILER_TARGET_DEFAULT) { - UiUserIgnore.init(); - } - UiMessageUserConsent.init(); - }, - /** - * Initializes user profile popover. - */ - _initUserPopover: function () { - ControllerPopover.init({ - className: 'userLink', - dboAction: 'wcf\\data\\user\\UserProfileAction', - identifier: 'com.woltlab.wcf.user' - }); - // @deprecated since 5.3 - ControllerPopover.init({ - attributeName: 'data-user-id', - className: 'userLink', - dboAction: 'wcf\\data\\user\\UserProfileAction', - identifier: 'com.woltlab.wcf.user.deprecated' - }); + function _initUserPopover() { + ControllerPopover.init({ + className: "userLink", + dboAction: "wcf\\data\\user\\UserProfileAction", + identifier: "com.woltlab.wcf.user", + }); + // @deprecated since 5.3 + ControllerPopover.init({ + attributeName: "data-user-id", + className: "userLink", + dboAction: "wcf\\data\\user\\UserProfileAction", + identifier: "com.woltlab.wcf.user.deprecated", + }); + } + /** + * Bootstraps general modules and frontend exclusive ones. + */ + function setup(options) { + // Modify the URL of the background queue URL to always target the current domain to avoid CORS. + options.backgroundQueue.url = window.WSC_API_URL + options.backgroundQueue.url.substr(window.WCF_PATH.length); + Bootstrap.setup({ enableMobileMenu: true }); + UiPageHeaderMenu.init(); + if (options.styleChanger) { + ControllerStyleChanger.setup(); + } + if (options.enableUserPopover) { + _initUserPopover(); + } + BackgroundQueue.setUrl(options.backgroundQueue.url); + if (Math.random() < 0.1 || options.backgroundQueue.force) { + // invoke the queue roughly every 10th request or on demand + BackgroundQueue.invoke(); + } + if (globalThis.COMPILER_TARGET_DEFAULT) { + UiUserIgnore.init(); } - }; + UiMessageUserConsent.init(); + } + exports.setup = setup; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/BootstrapFrontend.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/BootstrapFrontend.js deleted file mode 100644 index 5fde68b34a..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/BootstrapFrontend.js +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Bootstraps WCF's JavaScript with additions for the frontend usage. - * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/BootstrapFrontend - */ -define([ - 'WoltLabSuite/Core/BackgroundQueue', 'WoltLabSuite/Core/Bootstrap', 'WoltLabSuite/Core/Controller/Style/Changer', - 'WoltLabSuite/Core/Controller/Popover', 'WoltLabSuite/Core/Ui/User/Ignore', 'WoltLabSuite/Core/Ui/Page/Header/Menu', - 'WoltLabSuite/Core/Ui/Message/UserConsent' -], function (BackgroundQueue, Bootstrap, ControllerStyleChanger, ControllerPopover, UiUserIgnore, UiPageHeaderMenu, UiMessageUserConsent) { - "use strict"; - /** - * @exports WoltLabSuite/Core/BootstrapFrontend - */ - return { - /** - * Bootstraps general modules and frontend exclusive ones. - * - * @param {object} options bootstrap options - */ - setup: function (options) { - // fix the background queue URL to always run against the current domain (avoiding CORS) - options.backgroundQueue.url = WSC_API_URL + options.backgroundQueue.url.substr(WCF_PATH.length); - Bootstrap.setup(); - UiPageHeaderMenu.init(); - if (options.styleChanger) { - ControllerStyleChanger.setup(); - } - if (options.enableUserPopover) { - this._initUserPopover(); - } - BackgroundQueue.setUrl(options.backgroundQueue.url); - if (Math.random() < 0.1 || options.backgroundQueue.force) { - // invoke the queue roughly every 10th request or on demand - BackgroundQueue.invoke(); - } - if (COMPILER_TARGET_DEFAULT) { - UiUserIgnore.init(); - } - UiMessageUserConsent.init(); - }, - /** - * Initializes user profile popover. - */ - _initUserPopover: function () { - ControllerPopover.init({ - className: 'userLink', - dboAction: 'wcf\\data\\user\\UserProfileAction', - identifier: 'com.woltlab.wcf.user' - }); - // @deprecated since 5.3 - ControllerPopover.init({ - attributeName: 'data-user-id', - className: 'userLink', - dboAction: 'wcf\\data\\user\\UserProfileAction', - identifier: 'com.woltlab.wcf.user.deprecated' - }); - } - }; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/BootstrapFrontend.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/BootstrapFrontend.ts new file mode 100644 index 0000000000..07c2e563ef --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/BootstrapFrontend.ts @@ -0,0 +1,75 @@ +/** + * Bootstraps WCF's JavaScript with additions for the frontend usage. + * + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/BootstrapFrontend + */ + +import * as BackgroundQueue from "./BackgroundQueue"; +import * as Bootstrap from "./Bootstrap"; +import * as ControllerStyleChanger from "./Controller/Style/Changer"; +import * as ControllerPopover from "./Controller/Popover"; +import * as UiUserIgnore from "./Ui/User/Ignore"; +import * as UiPageHeaderMenu from "./Ui/Page/Header/Menu"; +import * as UiMessageUserConsent from "./Ui/Message/UserConsent"; + +interface BoostrapOptions { + backgroundQueue: { + url: string; + force: boolean; + }; + enableUserPopover: boolean; + styleChanger: boolean; +} + +/** + * Initializes user profile popover. + */ +function _initUserPopover(): void { + ControllerPopover.init({ + className: "userLink", + dboAction: "wcf\\data\\user\\UserProfileAction", + identifier: "com.woltlab.wcf.user", + }); + + // @deprecated since 5.3 + ControllerPopover.init({ + attributeName: "data-user-id", + className: "userLink", + dboAction: "wcf\\data\\user\\UserProfileAction", + identifier: "com.woltlab.wcf.user.deprecated", + }); +} + +/** + * Bootstraps general modules and frontend exclusive ones. + */ +export function setup(options: BoostrapOptions): void { + // Modify the URL of the background queue URL to always target the current domain to avoid CORS. + options.backgroundQueue.url = window.WSC_API_URL + options.backgroundQueue.url.substr(window.WCF_PATH.length); + + Bootstrap.setup({ enableMobileMenu: true }); + UiPageHeaderMenu.init(); + + if (options.styleChanger) { + ControllerStyleChanger.setup(); + } + + if (options.enableUserPopover) { + _initUserPopover(); + } + + BackgroundQueue.setUrl(options.backgroundQueue.url); + if (Math.random() < 0.1 || options.backgroundQueue.force) { + // invoke the queue roughly every 10th request or on demand + BackgroundQueue.invoke(); + } + + if (globalThis.COMPILER_TARGET_DEFAULT) { + UiUserIgnore.init(); + } + + UiMessageUserConsent.init(); +} diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Popover.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Popover.ts index 545ccea6a3..a311ac378e 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Popover.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Controller/Popover.ts @@ -28,19 +28,19 @@ const enum Delay { type CallbackLoad = (objectId: number | string, popover: ControllerPopover, element: HTMLElement) => void; interface PopoverOptions { - attributeName: string; + attributeName?: string; className: string; dboAction: string; identifier: string; - legacy: boolean; - loadCallback: CallbackLoad; + legacy?: boolean; + loadCallback?: CallbackLoad; } interface HandlerData { attributeName: string; dboAction: string; legacy: boolean; - loadCallback: CallbackLoad; + loadCallback?: CallbackLoad; selector: string; }