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 2023/03/17 17:46:34 UTC

[myfaces-tobago] branch main updated (0cebbf7e83 -> e2f590c431)

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

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


    from 0cebbf7e83 build(deps): bump maven-scm-plugin from 1.13.0 to 2.0.0
     new 8fe24011e2 fix(ajax): dropdown menu
     new e2f590c431 build(theme): rebuild after fixing dropdown menu ajax

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../900-test/6500-behavior/Behavior.test.js        | 82 ++++++++++++++++++++++
 .../content/900-test/6500-behavior/Behavior.xhtml  | 16 ++++-
 .../tobago-theme-standard/src/main/js/tobago.js    |  2 +-
 .../src/main/js/tobago.js.map                      |  2 +-
 .../src/main/ts/tobago-behavior.ts                 | 16 ++++-
 5 files changed, 113 insertions(+), 5 deletions(-)


[myfaces-tobago] 01/02: fix(ajax): dropdown menu

Posted by hn...@apache.org.
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

commit 8fe24011e2760e7d91e30f24f6fad8fb1b54f5da
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri Mar 17 14:31:26 2023 +0100

    fix(ajax): dropdown menu
    
    * implement disconnectedCallback() for tobago-behavior
    * add test
    
    Issue: TOBAGO-2200
---
 .../900-test/6500-behavior/Behavior.test.js        | 82 ++++++++++++++++++++++
 .../content/900-test/6500-behavior/Behavior.xhtml  | 16 ++++-
 .../src/main/ts/tobago-behavior.ts                 | 16 ++++-
 3 files changed, 111 insertions(+), 3 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.test.js
index f47ba774cc..0cb72f7280 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.test.js
@@ -78,6 +78,88 @@ it("Simple EventAjax", function (done) {
   test.start();
 });
 
+it("Dropdown: Simple Event", function (done) {
+  const dropdownButtonFn = elementByIdFn("page:mainForm:dropdown::command");
+  const dropdownMenuFn = querySelectorFn(".dropdown-menu[name='page:mainForm:dropdown']");
+  const entryFn = elementByIdFn("page:mainForm:simpleEventEntry");
+  const oldCounterValues = getCounterValues();
+
+  const test = new JasmineTestTool(done);
+  test.event("click", dropdownButtonFn, () => dropdownMenuFn().parentElement.classList.contains("tobago-page-menuStore"))
+  test.do(() => expect(dropdownMenuFn().parentElement.tagName).not.toEqual("TOBAGO-DROPDOWN"));
+  test.do(() => expect(dropdownMenuFn().parentElement.classList.contains("tobago-page-menuStore")).toBeTrue());
+
+  test.event("click", entryFn, () => getCounterValues().action1 > oldCounterValues.action1)
+  test.do(() => expect(getCounterValues().buttonAction).toBe(oldCounterValues.buttonAction));
+  test.do(() => expect(getCounterValues().buttonActionListener).toBe(oldCounterValues.buttonActionListener));
+  test.do(() => expect(getCounterValues().action1).toBe(oldCounterValues.action1 + 1));
+  test.do(() => expect(getCounterValues().actionListener1).toBe(oldCounterValues.actionListener1 + 1));
+  test.do(() => expect(getCounterValues().ajaxListener1).toBe(oldCounterValues.ajaxListener1));
+  test.do(() => expect(getCounterValues().action2).toBe(oldCounterValues.action2));
+  test.do(() => expect(getCounterValues().actionListener2).toBe(oldCounterValues.actionListener2));
+  test.do(() => expect(getCounterValues().ajaxListener2).toBe(oldCounterValues.ajaxListener2));
+  test.do(() => expect(getCounterValues().action3).toBe(oldCounterValues.action3));
+  test.do(() => expect(getCounterValues().actionListener3).toBe(oldCounterValues.actionListener3));
+  test.do(() => expect(getCounterValues().ajaxListener3).toBe(oldCounterValues.ajaxListener3));
+  test.do(() => expect(dropdownMenuFn().parentElement.tagName).toEqual("TOBAGO-DROPDOWN"));
+  test.do(() => expect(dropdownMenuFn().parentElement.classList.contains("tobago-page-menuStore")).toBeFalse());
+  test.start();
+});
+
+it("Dropdown: Simple Ajax", function (done) {
+  const dropdownButtonFn = elementByIdFn("page:mainForm:dropdown::command");
+  const dropdownMenuFn = querySelectorFn(".dropdown-menu[name='page:mainForm:dropdown']");
+  const entryFn = elementByIdFn("page:mainForm:simpleAjaxEntry");
+  const oldCounterValues = getCounterValues();
+
+  const test = new JasmineTestTool(done);
+  test.event("click", dropdownButtonFn, () => dropdownMenuFn().parentElement.classList.contains("tobago-page-menuStore"))
+  test.do(() => expect(dropdownMenuFn().parentElement.tagName).not.toEqual("TOBAGO-DROPDOWN"));
+  test.do(() => expect(dropdownMenuFn().parentElement.classList.contains("tobago-page-menuStore")).toBeTrue());
+
+  test.event("click", entryFn, () => getCounterValues().ajaxListener1 > oldCounterValues.ajaxListener1)
+  test.do(() => expect(getCounterValues().buttonAction).toBe(oldCounterValues.buttonAction));
+  test.do(() => expect(getCounterValues().buttonActionListener).toBe(oldCounterValues.buttonActionListener));
+  test.do(() => expect(getCounterValues().action1).toBe(oldCounterValues.action1));
+  test.do(() => expect(getCounterValues().actionListener1).toBe(oldCounterValues.actionListener1));
+  test.do(() => expect(getCounterValues().ajaxListener1).toBe(oldCounterValues.ajaxListener1 + 1));
+  test.do(() => expect(getCounterValues().action2).toBe(oldCounterValues.action2));
+  test.do(() => expect(getCounterValues().actionListener2).toBe(oldCounterValues.actionListener2));
+  test.do(() => expect(getCounterValues().ajaxListener2).toBe(oldCounterValues.ajaxListener2));
+  test.do(() => expect(getCounterValues().action3).toBe(oldCounterValues.action3));
+  test.do(() => expect(getCounterValues().actionListener3).toBe(oldCounterValues.actionListener3));
+  test.do(() => expect(getCounterValues().ajaxListener3).toBe(oldCounterValues.ajaxListener3));
+  test.do(() => expect(dropdownMenuFn().parentElement.tagName).toEqual("TOBAGO-DROPDOWN"));
+  test.do(() => expect(dropdownMenuFn().parentElement.classList.contains("tobago-page-menuStore")).toBeFalse());
+  test.start();
+});
+
+it("Dropdown: Simple EventAjax", function (done) {
+  const dropdownButtonFn = elementByIdFn("page:mainForm:dropdown::command");
+  const dropdownMenuFn = querySelectorFn(".dropdown-menu[name='page:mainForm:dropdown']");
+  const entryFn = elementByIdFn("page:mainForm:simpleEventAjaxEntry");
+  const oldCounterValues = getCounterValues();
+
+  const test = new JasmineTestTool(done);
+  test.event("click", dropdownButtonFn, () => dropdownMenuFn().parentElement.classList.contains("tobago-page-menuStore"))
+  test.do(() => expect(dropdownMenuFn().parentElement.tagName).not.toEqual("TOBAGO-DROPDOWN"));
+  test.do(() => expect(dropdownMenuFn().parentElement.classList.contains("tobago-page-menuStore")).toBeTrue());
+
+  test.event("click", entryFn, () => getCounterValues().ajaxListener1 > oldCounterValues.ajaxListener1)
+  test.do(() => expect(getCounterValues().buttonAction).toBe(oldCounterValues.buttonAction));
+  test.do(() => expect(getCounterValues().buttonActionListener).toBe(oldCounterValues.buttonActionListener));
+  test.do(() => expect(getCounterValues().action1).toBe(oldCounterValues.action1));
+  test.do(() => expect(getCounterValues().actionListener1).toBe(oldCounterValues.actionListener1));
+  test.do(() => expect(getCounterValues().ajaxListener1).toBe(oldCounterValues.ajaxListener1 + 1));
+  test.do(() => expect(getCounterValues().action2).toBe(oldCounterValues.action2));
+  test.do(() => expect(getCounterValues().actionListener2).toBe(oldCounterValues.actionListener2));
+  test.do(() => expect(getCounterValues().ajaxListener2).toBe(oldCounterValues.ajaxListener2));
+  test.do(() => expect(getCounterValues().action3).toBe(oldCounterValues.action3));
+  test.do(() => expect(getCounterValues().actionListener3).toBe(oldCounterValues.actionListener3));
+  test.do(() => expect(getCounterValues().ajaxListener3).toBe(oldCounterValues.ajaxListener3));
+  test.start();
+});
+
 it("Advanced Button: Option 1", function (done) {
   const optionId = 0; //Event 1 + no Ajax enabled
   const buttonFn = elementByIdFn("page:mainForm:advancedButton");
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.xhtml
index c7bcfe3984..b499da0eb3 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/6500-behavior/Behavior.xhtml
@@ -79,7 +79,21 @@
           <f:ajax render="counter operationTestBox" listener="#{behaviorTestController.countAjaxListener1}"/>
         </tc:event>
       </tc:button>
-      <p/>
+
+      <tc:button id="dropdown" label="Dropdown" omit="true">
+        <tc:link id="simpleEventEntry" label="Simple Event">
+          <tc:event action="#{behaviorTestController.countAction1}"
+                    actionListener="#{behaviorTestController.countActionListener1}"/>
+        </tc:link>
+        <tc:link id="simpleAjaxEntry" label="Simple Ajax">
+          <f:ajax render="counter operationTestBox" listener="#{behaviorTestController.countAjaxListener1}"/>
+        </tc:link>
+        <tc:link id="simpleEventAjaxEntry" label="Simple EventAjax">
+          <tc:event>
+            <f:ajax render="counter operationTestBox" listener="#{behaviorTestController.countAjaxListener1}"/>
+          </tc:event>
+        </tc:link>
+      </tc:button>
     </tc:section>
 
     <tc:section label="Advanced">
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 cb4fa4faa3..9ac582ed5e 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
@@ -23,6 +23,7 @@ import {Overlay} from "./tobago-overlay";
 import {OverlayType} from "./tobago-overlay-type";
 
 class Behavior extends HTMLElement {
+  private eventListener: EventListenerOrEventListenerObject;
 
   constructor() {
     super();
@@ -38,11 +39,13 @@ class Behavior extends HTMLElement {
         break;
       default: {
         const eventElement = this.eventElement;
+        this.eventListener = this.callback.bind(this);
+
         if (eventElement) {
-          eventElement.addEventListener(this.event, this.callback.bind(this));
+          eventElement.addEventListener(this.event, this.eventListener);
         } else {
           // if the clientId doesn't exists in DOM, it's probably the id of tobago-behavior custom element
-          this.parentElement.addEventListener(this.event, this.callback.bind(this));
+          this.parentElement.addEventListener(this.event, this.eventListener);
           // todo: not sure if this warning can be removed;
           console.warn("Can't find an element for the event. Use parentElement instead.", this);
         }
@@ -50,6 +53,15 @@ class Behavior extends HTMLElement {
     }
   }
 
+  disconnectedCallback(): void {
+    const eventElement = this.eventElement;
+    if (eventElement) {
+      eventElement.removeEventListener(this.event, this.eventListener);
+    } else {
+      this.parentElement.removeEventListener(this.event, this.eventListener);
+    }
+  }
+
   callback(event?: Event): void {
 
     if (this.confirmation) {


[myfaces-tobago] 02/02: build(theme): rebuild after fixing dropdown menu ajax

Posted by hn...@apache.org.
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

commit e2f590c4315e17f3d0fc4cd19e5c2ac5a224612d
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri Mar 17 18:10:41 2023 +0100

    build(theme): rebuild after fixing dropdown menu ajax
---
 tobago-theme/tobago-theme-standard/src/main/js/tobago.js     | 2 +-
 tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
index 0fec60b3ba..47c095f22d 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
@@ -4,7 +4,7 @@
       * Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
       * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
       */
-const Be="transitionend",Me=e=>{let t=e.getAttribute("data-bs-target");if(!t||"#"===t){let s=e.getAttribute("href");if(!s||!s.includes("#")&&!s.startsWith("."))return null;s.includes("#")&&!s.startsWith("#")&&(s=`#${s.split("#")[1]}`),t=s&&"#"!==s?s.trim():null}return t},Pe=e=>{const t=Me(e);return t&&document.querySelector(t)?t:null},$e=e=>{const t=Me(e);return t?document.querySelector(t):null},He=e=>{e.dispatchEvent(new Event(Be))},qe=e=>!(!e||"object"!=typeof e)&&(void 0!==e.jquery&&( [...]
+const Be="transitionend",Me=e=>{let t=e.getAttribute("data-bs-target");if(!t||"#"===t){let s=e.getAttribute("href");if(!s||!s.includes("#")&&!s.startsWith("."))return null;s.includes("#")&&!s.startsWith("#")&&(s=`#${s.split("#")[1]}`),t=s&&"#"!==s?s.trim():null}return t},Pe=e=>{const t=Me(e);return t&&document.querySelector(t)?t:null},$e=e=>{const t=Me(e);return t?document.querySelector(t):null},He=e=>{e.dispatchEvent(new Event(Be))},qe=e=>!(!e||"object"!=typeof e)&&(void 0!==e.jquery&&( [...]
 /**
      * @license
      * Copyright 2017 Google LLC
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
index 11acb4b492..369eff7235 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
@@ -1 +1 @@
-{"version":3,"file":"tobago.js","sources":["../ts/tobago-css.ts","../ts/tobago-bar.ts","../../../../node_modules/@popperjs/core/lib/enums.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getNodeName.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getWindow.js","../../../../node_modules/@popperjs/core/lib/dom-utils/instanceOf.js","../../../../node_modules/@popperjs/core/lib/modifiers/applyStyles.js","../../../../node_modules/@popperjs/core/lib/utils/getBasePlacement.j [...]
\ No newline at end of file
+{"version":3,"file":"tobago.js","sources":["../ts/tobago-css.ts","../ts/tobago-bar.ts","../../../../node_modules/@popperjs/core/lib/enums.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getNodeName.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getWindow.js","../../../../node_modules/@popperjs/core/lib/dom-utils/instanceOf.js","../../../../node_modules/@popperjs/core/lib/modifiers/applyStyles.js","../../../../node_modules/@popperjs/core/lib/utils/getBasePlacement.j [...]
\ No newline at end of file