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

index 5fde68b34a7b1003c011b38546ea39a70df94091..2c370e197053974f72a6a089723afa855a65eeb7 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/BootstrapFrontend
+ * @author  Alexander Ebert
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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<string, *>}     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 (file)
index 5fde68b..0000000
+++ /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 <http://opensource.org/licenses/lgpl-license.php>
- * @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<string, *>}     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 (file)
index 0000000..07c2e56
--- /dev/null
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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();
+}
index 545ccea6a3113eaa83984dd697348030de0735a2..a311ac378e3c12f48329a9522f324b5bdb9f30b6 100644 (file)
@@ -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;
 }