Helper methods to work with DOM elements
authorAlexander Ebert <ebert@woltlab.com>
Mon, 19 Oct 2020 14:47:48 +0000 (16:47 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 28 Oct 2020 11:32:57 +0000 (12:32 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Core.js
wcfsetup/install/files/js/WoltLabSuite/Core/Dom/Util.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts
wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts

index 9cfdf25dc0dddf7cfb5525d722eaabee3c64588e..ed43e1ac146d3d490f63844b900a5d77772084ed 100644 (file)
@@ -10,7 +10,7 @@
 define(["require", "exports"], function (require, exports) {
     "use strict";
     Object.defineProperty(exports, "__esModule", { value: true });
-    exports.getStoragePrefix = exports.triggerEvent = exports.serialize = exports.getUuid = exports.getType = exports.isPlainObject = exports.inherit = exports.extend = exports.convertLegacyUrl = exports.clone = void 0;
+    exports.stringToBool = exports.getStoragePrefix = exports.triggerEvent = exports.serialize = exports.getUuid = exports.getType = exports.isPlainObject = exports.inherit = exports.extend = exports.convertLegacyUrl = exports.clone = void 0;
     const _clone = function (variable) {
         if (typeof variable === 'object' && (Array.isArray(variable) || isPlainObject(variable))) {
             return _cloneObject(variable);
@@ -197,4 +197,12 @@ define(["require", "exports"], function (require, exports) {
         return _prefix;
     }
     exports.getStoragePrefix = getStoragePrefix;
+    /**
+     * Interprets a string value as a boolean value similar to the behavior of the
+     * legacy functions `elAttrBool()` and `elDataBool()`.
+     */
+    function stringToBool(value) {
+        return value === '1' || value === 'true';
+    }
+    exports.stringToBool = stringToBool;
 });
index 2e7520ae025c26d6d57301db56f04c127c33240b..da13bbd283dab53ae35e2019c9218d6b38e91625 100644 (file)
@@ -354,6 +354,18 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri
             }
             return null;
         },
+        /**
+         * Shorthand function to hide an element by setting its 'display' value to 'none'.
+         */
+        hide(element) {
+            element.style.setProperty('display', 'none', '');
+        },
+        /**
+         * Shorthand function to show an element previously hidden by using `elHide()`.
+         */
+        show(element) {
+            element.style.removeProperty('display');
+        },
     };
     // expose on window object for backward compatibility
     window.bc_wcfDomUtil = DomUtil;
index 10fba0524655456fda6f7a7c529e949c2c5500b4..481724c2dea5f8bbb46cb98630944184371bfc66 100644 (file)
@@ -206,4 +206,11 @@ export function triggerEvent(element: Element, eventName: string): void {
 export function getStoragePrefix() {
   return _prefix;
 }
-    
+
+/**
+ * Interprets a string value as a boolean value similar to the behavior of the 
+ * legacy functions `elAttrBool()` and `elDataBool()`.
+ */
+export function stringToBool(value: string | null): boolean {
+  return value === '1' || value === 'true';
+}
index 34530cc99db73af6e7d53a53cde4addf1ef75efa..1e5d4596c5776471a07d21643c6f4acc2266fb3b 100644 (file)
@@ -395,6 +395,20 @@ const DomUtil = {
 
     return null;
   },
+
+  /**
+   * Shorthand function to hide an element by setting its 'display' value to 'none'.
+   */
+  hide(element: HTMLElement): void {
+    element.style.setProperty('display', 'none', '');
+  },
+
+  /**
+   * Shorthand function to show an element previously hidden by using `elHide()`.
+   */
+  show(element: HTMLElement): void {
+    element.style.removeProperty('display');
+  },
 };
 
 interface Dimensions {