From 5a345090641781dcb67bfcf2c2a0517129f5cc0a Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 12 Dec 2020 16:03:39 +0100 Subject: [PATCH] Convert `Form/Builder/Field/Dependency/Container/Default` to TypeScript --- .../Field/Dependency/Container/Default.js | 64 +++++++---------- .../Field/Dependency/Container/Default.js | 68 ------------------- .../Field/Dependency/Container/Default.ts | 54 +++++++++++++++ 3 files changed, 80 insertions(+), 106 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js index dabbe75146..036d564490 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js @@ -2,60 +2,48 @@ * Default implementation for a container visibility handler due to the dependencies of its * children that only considers the visibility of all of its children. * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default - * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract - * @since 5.2 + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default + * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract + * @since 5.2 */ -define(['./Abstract', 'Core', '../Manager'], function (Abstract, Core, DependencyManager) { +define(["require", "exports", "tslib", "./Abstract", "../../../../../Core", "../Manager"], function (require, exports, tslib_1, Abstract_1, Core, Manager_1) { "use strict"; - /** - * @constructor - */ - function Default(containerId) { - this.init(containerId); - } - ; - Core.inherit(Default, Abstract, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default#checkContainer - */ - checkContainer: function () { - if (elDataBool(this._container, 'ignore-dependencies')) { + Abstract_1 = tslib_1.__importDefault(Abstract_1); + Core = tslib_1.__importStar(Core); + Manager_1 = tslib_1.__importDefault(Manager_1); + class Default extends Abstract_1.default { + checkContainer() { + if (Core.stringToBool(this._container.dataset.ignoreDependencies || "")) { return; } // only consider containers that have not been hidden by their own dependencies - if (DependencyManager.isHiddenByDependencies(this._container)) { + if (Manager_1.default.isHiddenByDependencies(this._container)) { return; } - var containerIsVisible = !elIsHidden(this._container); - var containerShouldBeVisible = false; - var children = this._container.children; - var start = 0; - // ignore container header for visibility considerations - if (this._container.children.item(0).tagName === 'H2' || this._container.children.item(0).tagName === 'HEADER') { - var start = 1; - } - for (var i = start, length = children.length; i < length; i++) { - if (!elIsHidden(children.item(i))) { - containerShouldBeVisible = true; - break; + const containerIsVisible = this._container.style.display !== "none"; + const containerShouldBeVisible = Array.from(this._container.children).some((child, index) => { + // ignore container header for visibility considerations + if (index === 0 && (child.tagName === "H2" || child.tagName === "HEADER")) { + return false; } - } + return child.style.display !== "none"; + }); if (containerIsVisible !== containerShouldBeVisible) { if (containerShouldBeVisible) { - elShow(this._container); + this._container.style.display = "block"; } else { - elHide(this._container); + this._container.style.display = "none"; } // check containers again to make sure parent containers can react to // changing the visibility of this container - DependencyManager.checkContainers(); + Manager_1.default.checkContainers(); } } - }); + } + Core.enableLegacyInheritance(Default); return Default; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js deleted file mode 100644 index 99c0ce829d..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Default implementation for a container visibility handler due to the dependencies of its - * children that only considers the visibility of all of its children. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default - * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract - * @since 5.2 - */ -define(['./Abstract', 'Core', '../Manager'], function(Abstract, Core, DependencyManager) { - "use strict"; - - /** - * @constructor - */ - function Default(containerId) { - this.init(containerId); - }; - Core.inherit(Default, Abstract, { - /** - * @see WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default#checkContainer - */ - checkContainer: function() { - if (elDataBool(this._container, 'ignore-dependencies')) { - return; - } - - // only consider containers that have not been hidden by their own dependencies - if (DependencyManager.isHiddenByDependencies(this._container)) { - return; - } - - var containerIsVisible = !elIsHidden(this._container); - var containerShouldBeVisible = false; - - var children = this._container.children; - var start = 0; - // ignore container header for visibility considerations - if (this._container.children.item(0).tagName === 'H2' || this._container.children.item(0).tagName === 'HEADER') { - var start = 1; - } - - for (var i = start, length = children.length; i < length; i++) { - if (!elIsHidden(children.item(i))) { - containerShouldBeVisible = true; - break; - } - } - - if (containerIsVisible !== containerShouldBeVisible) { - if (containerShouldBeVisible) { - elShow(this._container); - } - else { - elHide(this._container); - } - - // check containers again to make sure parent containers can react to - // changing the visibility of this container - DependencyManager.checkContainers(); - } - } - }); - - return Default; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.ts new file mode 100644 index 0000000000..a3e7dd82e8 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.ts @@ -0,0 +1,54 @@ +/** + * Default implementation for a container visibility handler due to the dependencies of its + * children that only considers the visibility of all of its children. + * + * @author Matthias Schmidt + * @copyright 2001-2020 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default + * @see module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract + * @since 5.2 + */ + +import Abstract from "./Abstract"; +import * as Core from "../../../../../Core"; +import DependencyManager from "../Manager"; + +class Default extends Abstract { + public checkContainer(): void { + if (Core.stringToBool(this._container.dataset.ignoreDependencies || "")) { + return; + } + + // only consider containers that have not been hidden by their own dependencies + if (DependencyManager.isHiddenByDependencies(this._container)) { + return; + } + + const containerIsVisible = this._container.style.display !== "none"; + const containerShouldBeVisible = Array.from(this._container.children).some((child: HTMLElement, index) => { + // ignore container header for visibility considerations + if (index === 0 && (child.tagName === "H2" || child.tagName === "HEADER")) { + return false; + } + + return child.style.display !== "none"; + }); + + if (containerIsVisible !== containerShouldBeVisible) { + if (containerShouldBeVisible) { + this._container.style.display = "block"; + } else { + this._container.style.display = "none"; + } + + // check containers again to make sure parent containers can react to + // changing the visibility of this container + DependencyManager.checkContainers(); + } + } +} + +Core.enableLegacyInheritance(Default); + +export = Default; -- 2.20.1