Convert `Ui/Redactor/PseudoHeader` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Wed, 4 Nov 2020 09:42:56 +0000 (10:42 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 4 Nov 2020 09:42:56 +0000 (10:42 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.ts [new file with mode: 0644]

index 022d57731e5db1e79f832d764e841aec2ddf3014..8c3c01c85e7327752b7a20839d4cb3e023307ecb 100644 (file)
@@ -3,45 +3,36 @@
  * `::before` element.
  *
  * @author      Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
+ * @copyright  2001-2019 WoltLab GmbH
  * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module      WoltLabSuite/Core/Ui/Redactor/PseudoHeader
  */
-define([], function () {
+define(["require", "exports"], function (require, exports) {
     "use strict";
-    if (!COMPILER_TARGET_DEFAULT) {
-        var Fake = function () { };
-        Fake.prototype = {
-            getHeight: function () { }
-        };
-        return Fake;
-    }
-    return {
-        /**
-         * Returns the height within a click should be treated as a click
-         * within the block element's title. This method expects that the
-         * `::before` element is used and that removing the attribute
-         * `data-title` does cause the title to collapse.
-         *
-         * @param       {Element}       element         block element
-         * @return      {int}           clickable height spanning from the top border down to the bottom of the title
-         */
-        getHeight: function (element) {
-            var height = ~~window.getComputedStyle(element).paddingTop.replace(/px$/, '');
-            var styles = window.getComputedStyle(element, '::before');
-            height += ~~styles.paddingTop.replace(/px$/, '');
-            height += ~~styles.paddingBottom.replace(/px$/, '');
-            var titleHeight = ~~styles.height.replace(/px$/, '');
-            if (titleHeight === 0) {
-                // firefox returns garbage for pseudo element height
-                // https://bugzilla.mozilla.org/show_bug.cgi?id=925694
-                titleHeight = element.scrollHeight;
-                element.classList.add('redactorCalcHeight');
-                titleHeight -= element.scrollHeight;
-                element.classList.remove('redactorCalcHeight');
-            }
-            height += titleHeight;
-            return height;
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.getHeight = void 0;
+    /**
+     * Returns the height within a click should be treated as a click
+     * within the block element's title. This method expects that the
+     * `::before` element is used and that removing the attribute
+     * `data-title` does cause the title to collapse.
+     */
+    function getHeight(element) {
+        let height = ~~window.getComputedStyle(element).paddingTop.replace(/px$/, "");
+        const styles = window.getComputedStyle(element, "::before");
+        height += ~~styles.paddingTop.replace(/px$/, "");
+        height += ~~styles.paddingBottom.replace(/px$/, "");
+        let titleHeight = ~~styles.height.replace(/px$/, "");
+        if (titleHeight === 0) {
+            // firefox returns garbage for pseudo element height
+            // https://bugzilla.mozilla.org/show_bug.cgi?id=925694
+            titleHeight = element.scrollHeight;
+            element.classList.add("redactorCalcHeight");
+            titleHeight -= element.scrollHeight;
+            element.classList.remove("redactorCalcHeight");
         }
-    };
+        height += titleHeight;
+        return height;
+    }
+    exports.getHeight = getHeight;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.js
deleted file mode 100644 (file)
index fe5aa7f..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Helper class to deal with clickable block headers using the pseudo
- * `::before` element.
- * 
- * @author      Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
- * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module      WoltLabSuite/Core/Ui/Redactor/PseudoHeader
- */
-define([], function() {
-       "use strict";
-       
-       if (!COMPILER_TARGET_DEFAULT) {
-               var Fake = function() {};
-               Fake.prototype = {
-                       getHeight: function() {}
-               };
-               return Fake;
-       }
-       
-       return {
-               /**
-                * Returns the height within a click should be treated as a click
-                * within the block element's title. This method expects that the
-                * `::before` element is used and that removing the attribute
-                * `data-title` does cause the title to collapse.
-                * 
-                * @param       {Element}       element         block element
-                * @return      {int}           clickable height spanning from the top border down to the bottom of the title
-                */
-               getHeight: function (element) {
-                       var height = ~~window.getComputedStyle(element).paddingTop.replace(/px$/, '');
-                       
-                       var styles = window.getComputedStyle(element, '::before');
-                       height += ~~styles.paddingTop.replace(/px$/, '');
-                       height += ~~styles.paddingBottom.replace(/px$/, '');
-                       
-                       var titleHeight = ~~styles.height.replace(/px$/, '');
-                       if (titleHeight === 0) {
-                               // firefox returns garbage for pseudo element height
-                               // https://bugzilla.mozilla.org/show_bug.cgi?id=925694
-                               
-                               titleHeight = element.scrollHeight;
-                               element.classList.add('redactorCalcHeight');
-                               titleHeight -= element.scrollHeight;
-                               element.classList.remove('redactorCalcHeight');
-                       }
-                       
-                       height += titleHeight;
-                       
-                       return height;
-               }
-       }
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.ts
new file mode 100644 (file)
index 0000000..b6d7023
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * Helper class to deal with clickable block headers using the pseudo
+ * `::before` element.
+ *
+ * @author      Alexander Ebert
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module      WoltLabSuite/Core/Ui/Redactor/PseudoHeader
+ */
+
+/**
+ * Returns the height within a click should be treated as a click
+ * within the block element's title. This method expects that the
+ * `::before` element is used and that removing the attribute
+ * `data-title` does cause the title to collapse.
+ */
+export function getHeight(element: HTMLElement): number {
+  let height = ~~window.getComputedStyle(element).paddingTop.replace(/px$/, "");
+
+  const styles = window.getComputedStyle(element, "::before");
+  height += ~~styles.paddingTop.replace(/px$/, "");
+  height += ~~styles.paddingBottom.replace(/px$/, "");
+
+  let titleHeight = ~~styles.height.replace(/px$/, "");
+  if (titleHeight === 0) {
+    // firefox returns garbage for pseudo element height
+    // https://bugzilla.mozilla.org/show_bug.cgi?id=925694
+
+    titleHeight = element.scrollHeight;
+    element.classList.add("redactorCalcHeight");
+    titleHeight -= element.scrollHeight;
+    element.classList.remove("redactorCalcHeight");
+  }
+
+  height += titleHeight;
+
+  return height;
+}