From: Alexander Ebert Date: Wed, 4 Nov 2020 09:42:56 +0000 (+0100) Subject: Convert `Ui/Redactor/PseudoHeader` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~636^2~18 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ead855219a0d30033747adedda2674f6f7fc0ce8;p=GitHub%2FWoltLab%2FWCF.git Convert `Ui/Redactor/PseudoHeader` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.js index 022d57731e..8c3c01c85e 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.js @@ -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 * @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 index fe5aa7fee0..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.js +++ /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 - * @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 index 0000000000..b6d7023d7a --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/PseudoHeader.ts @@ -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 + * @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; +}