You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2024/04/08 08:22:35 UTC

(myfaces-tobago) branch main updated: refactor(TypeScript): separat file for Collapse class

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/main by this push:
     new bb6f6816e3 refactor(TypeScript): separat file for Collapse class
bb6f6816e3 is described below

commit bb6f6816e33cbe9720e3b02f7aadf24529659b59
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Thu Mar 28 12:54:42 2024 +0100

    refactor(TypeScript): separat file for Collapse class
    
    * put Collapse in a separat file
    * rename tobago-collapsible-operation.ts to match class name
---
 .../src/main/ts/tobago-behavior.ts                 |  4 +-
 ...n.test.ts => tobago-collapse-operation.test.ts} |  2 +-
 ...e-operation.ts => tobago-collapse-operation.ts} |  0
 .../src/main/ts/tobago-collapse.ts                 | 60 ++++++++++++++++++++++
 .../src/main/ts/tobago-popup.ts                    | 40 +--------------
 5 files changed, 64 insertions(+), 42 deletions(-)

diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
index 9b7b928c68..339e9b35c7 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
@@ -15,9 +15,9 @@
  * limitations under the License.
  */
 
-import {Collapse} from "./tobago-popup";
+import {Collapse} from "./tobago-collapse";
 import {Page} from "./tobago-page";
-import {CollapseOperation} from "./tobago-collapsible-operation";
+import {CollapseOperation} from "./tobago-collapse-operation";
 import {BehaviorMode} from "./tobago-behavior-mode";
 import {Overlay} from "./tobago-overlay";
 import {OverlayType} from "./tobago-overlay-type";
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapsible-operation.test.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapse-operation.test.ts
similarity index 95%
rename from tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapsible-operation.test.ts
rename to tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapse-operation.test.ts
index b1c6e11c59..d71c0a8e6f 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapsible-operation.test.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapse-operation.test.ts
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-import {CollapseOperation} from "./tobago-collapsible-operation";
+import {CollapseOperation} from "./tobago-collapse-operation";
 
 test("enum values to strings", () => {
   expect(CollapseOperation[CollapseOperation.show]).toBe("show");
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapsible-operation.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapse-operation.ts
similarity index 100%
rename from tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapsible-operation.ts
rename to tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapse-operation.ts
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapse.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapse.ts
new file mode 100644
index 0000000000..a4bb51ba99
--- /dev/null
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-collapse.ts
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import {CollapseOperation} from "./tobago-collapse-operation";
+import {BehaviorMode} from "./tobago-behavior-mode";
+import {Css} from "./tobago-css";
+import {Popup} from "./tobago-popup";
+
+export class Collapse {
+
+  static findHidden(element: HTMLElement): HTMLInputElement {
+    const rootNode = element.getRootNode() as ShadowRoot | Document;
+    return rootNode.getElementById(element.id + "::collapse") as HTMLInputElement;
+  }
+
+  static execute = function (operation: CollapseOperation, target: HTMLElement, behaviorMode: BehaviorMode): void {
+    const hidden = Collapse.findHidden(target);
+    let newCollapsed;
+    switch (operation) {
+      case CollapseOperation.hide:
+        newCollapsed = true;
+        break;
+      case CollapseOperation.show:
+        newCollapsed = false;
+        break;
+      default:
+        console.error("unknown operation: '%s'", operation);
+    }
+    if (newCollapsed) {
+      if (target instanceof Popup) {
+        target.clientBehaviorHide(behaviorMode);
+      } else {
+        target.classList.add(Css.TOBAGO_COLLAPSED);
+      }
+    } else {
+      if (target instanceof Popup) {
+        target.clientBehaviorShow(behaviorMode);
+      } else {
+        target.classList.remove(Css.TOBAGO_COLLAPSED);
+      }
+    }
+    hidden.value = newCollapsed;
+  };
+}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-popup.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-popup.ts
index 6a1631726f..4fcf2d8e84 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-popup.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-popup.ts
@@ -17,8 +17,7 @@
 
 import {Modal} from "bootstrap";
 import {BehaviorMode} from "./tobago-behavior-mode";
-import {CollapseOperation} from "./tobago-collapsible-operation";
-import {Css} from "./tobago-css";
+import {Collapse} from "./tobago-collapse";
 
 export class Popup extends HTMLElement {
 
@@ -70,40 +69,3 @@ document.addEventListener("tobago.init", function (event: Event): void {
     window.customElements.define("tobago-popup", Popup);
   }
 });
-
-export class Collapse {
-
-  static findHidden(element: HTMLElement): HTMLInputElement {
-    const rootNode = element.getRootNode() as ShadowRoot | Document;
-    return rootNode.getElementById(element.id + "::collapse") as HTMLInputElement;
-  }
-
-  static execute = function (operation: CollapseOperation, target: HTMLElement, behaviorMode: BehaviorMode): void {
-    const hidden = Collapse.findHidden(target);
-    let newCollapsed;
-    switch (operation) {
-      case CollapseOperation.hide:
-        newCollapsed = true;
-        break;
-      case CollapseOperation.show:
-        newCollapsed = false;
-        break;
-      default:
-        console.error("unknown operation: '%s'", operation);
-    }
-    if (newCollapsed) {
-      if (target instanceof Popup) {
-        target.clientBehaviorHide(behaviorMode);
-      } else {
-        target.classList.add(Css.TOBAGO_COLLAPSED);
-      }
-    } else {
-      if (target instanceof Popup) {
-        target.clientBehaviorShow(behaviorMode);
-      } else {
-        target.classList.remove(Css.TOBAGO_COLLAPSED);
-      }
-    }
-    hidden.value = newCollapsed;
-  };
-}