Convert `Form/Builder/Field/Dependency/Container/Default` to TypeScript
authorMatthias Schmidt <gravatronics@live.com>
Sat, 12 Dec 2020 15:03:39 +0000 (16:03 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 15 Dec 2020 17:23:06 +0000 (18:23 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default.ts [new file with mode: 0644]

index dabbe7514615d99fe1acabfcdff9ebf477aa38ab..036d5644905f89e4dc5b9e3b2f601814cf53e761 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
- * @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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 99c0ce8..0000000
+++ /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 <http://opensource.org/licenses/lgpl-license.php>
- * @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 (file)
index 0000000..a3e7dd8
--- /dev/null
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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;