You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2019/09/25 15:12:53 UTC

[myfaces-tobago] branch master updated: custom element: tobago-page

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5b37904  custom element: tobago-page
5b37904 is described below

commit 5b379040b76b8fbd178df5443f2aa0e750b082ec
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Wed Sep 25 12:59:43 2019 +0200

    custom element: tobago-page
    
    issue: TOBAGO-1633: TS refactoring
---
 .../internal/renderkit/renderer/PageRenderer.java  |  7 +-
 .../tobago/renderkit/html/HtmlElements.java        |  1 +
 tobago-core/src/main/resources/scss/_tobago.scss   |  5 ++
 .../src/main/npm/js/tobago-myfaces.js              |  6 +-
 .../src/main/npm/ts/tobago-command.ts              | 41 +-----------
 .../src/main/npm/ts/tobago-core.ts                 |  5 +-
 .../src/main/npm/ts/tobago-focus.ts                |  3 +-
 .../src/main/npm/ts/tobago-jsf.ts                  |  4 +-
 .../src/main/npm/ts/tobago-overlay.ts              |  3 +-
 .../src/main/npm/ts/tobago-page.ts                 | 75 ++++++++++++++++++++++
 .../src/main/npm/ts/tobago-sheet.ts                |  3 +-
 .../src/main/npm/ts/tobago-split-layout.ts         |  7 +-
 .../src/main/npm/ts/tobago-utils.ts                | 15 -----
 13 files changed, 105 insertions(+), 70 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java
index bbb39aa..73eaf64 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java
@@ -234,12 +234,11 @@ public class PageRenderer extends RendererBase {
       writer.writeClassAttribute(spread);
     }
 
-    writer.startElement(HtmlElements.DIV);
+    writer.startElement(HtmlElements.TOBAGO_PAGE);
 
     writer.writeClassAttribute(
-        TobagoClass.PAGE,
-        TobagoClass.PAGE.createMarkup(portlet ? Markup.PORTLET.add(page.getMarkup()) : page.getMarkup()),
         BootstrapClass.CONTAINER_FLUID,
+        TobagoClass.PAGE.createMarkup(portlet ? Markup.PORTLET.add(page.getMarkup()) : page.getMarkup()),
         spread,
         page.getCustomClass());
     writer.writeIdAttribute(clientId);
@@ -341,7 +340,7 @@ public class PageRenderer extends RendererBase {
     writer.writeText(ResourceUtils.getString(facesContext, "page.noscript"));
     writer.endElement(HtmlElements.DIV);
     writer.endElement(HtmlElements.NOSCRIPT);
-    writer.endElement(HtmlElements.DIV);
+    writer.endElement(HtmlElements.TOBAGO_PAGE);
 
     final List<UIComponent> bodyResources = viewRoot.getComponentResources(facesContext, BODY_TARGET);
     for (final UIComponent bodyResource : bodyResources) {
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java
index 9e6e660..f12e99f 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java
@@ -137,6 +137,7 @@ public enum HtmlElements {
   TOBAGO_FILE("tobago-file"),
   TOBAGO_LABEL("tobago-label"),
   TOBAGO_IN("tobago-in"),
+  TOBAGO_PAGE("tobago-page"),
   TOBAGO_PANEL("tobago-panel"),
   TOBAGO_POPUP("tobago-popup"),
   TOBAGO_SPLIT_LAYOUT("tobago-split-layout"),
diff --git a/tobago-core/src/main/resources/scss/_tobago.scss b/tobago-core/src/main/resources/scss/_tobago.scss
index 08d89b4..21cc683 100644
--- a/tobago-core/src/main/resources/scss/_tobago.scss
+++ b/tobago-core/src/main/resources/scss/_tobago.scss
@@ -667,7 +667,12 @@ span.tobago-out:empty:before {
 
 /* page ----------------------------------------------------------- */
 
+// todo: remove
 .tobago-page {
+}
+
+tobago-page {
+  display: block;
   padding-top: $page-padding-top;
   padding-bottom: 1rem;
 }
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/js/tobago-myfaces.js b/tobago-theme/tobago-theme-standard/src/main/npm/js/tobago-myfaces.js
index d9eddc0..127896e 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/js/tobago-myfaces.js
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/js/tobago-myfaces.js
@@ -5991,13 +5991,13 @@ _MF_SINGLTN(_PFX_XHR + "_AjaxResponse", _MF_OBJECT, /** @lends myfaces._impl.xhr
 
 // begin TOBAGO-JSF-JS
 // XXX hack
-                                    if (node.id === document.getElementsByClassName("tobago-page")[0].id) {
+                                    if (node.id === document.getElementsByTagName("tobago-page")[0].id) {
                                         // newDoc = document.open("text/html", "replace");
                                         // newDoc.write(cDataBlock);
                                         // newDoc.close();
                                         //change only the body, because change the head doesn't work with CSP
-                                        var newPage = jQuery(cDataBlock).filter(".tobago-page");
-                                        jQuery(".tobago-page").replaceWith(newPage);
+                                        var newPage = jQuery(cDataBlock).filter("tobago-page");
+                                        jQuery("tobago-page").replaceWith(newPage);
                                         // XXX remove jQuery
                                         resultNode = document.documentElement;
                                     } else {
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-command.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-command.ts
index 409b182..7e7f9db 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-command.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-command.ts
@@ -15,11 +15,11 @@
  * limitations under the License.
  */
 
-import {Listener, Phase} from "./tobago-listener";
+import {Listener} from "./tobago-listener";
 import {Overlay} from "./tobago-overlay";
-import {DomUtils, Tobago4Utils} from "./tobago-utils";
 import {Collapse} from "./tobago-popup";
 import {Setup} from "./tobago-core";
+import {Page} from "./tobago-page";
 
 class Behavior extends HTMLElement {
 
@@ -223,7 +223,7 @@ export class CommandHelper {
             sourceHidden.disabled = true;
             sourceHidden.value = "";
           } catch (e) {
-            Overlay.destroy(DomUtils.page().id);
+            Overlay.destroy(Page.page().id);
             CommandHelper.isSubmit = false;
             alert('Submit failed: ' + e); // XXX localization, better error handling
           }
@@ -246,39 +246,6 @@ export class CommandHelper {
     }, true);
   };
 
-  static initEnter(element: HTMLElement) {
-    for (const page of DomUtils.selfOrQuerySelectorAll(element, ".tobago-page")) {
-      page.addEventListener("keypress", function (event: KeyboardEvent) {
-        let code = event.which; // XXX deprecated
-        if (code === 0) {
-          code = event.keyCode;
-        }
-        if (code === 13) {
-          let target = event.target as HTMLElement;
-          if (target.tagName === "A" || target.tagName === "BUTTON") {
-            return;
-          }
-          if (target.tagName === "TEXTAREA") {
-            if (!event.metaKey && !event.ctrlKey) {
-              return;
-            }
-          }
-          const name = target.getAttribute("name");
-          let id = name ? name : target.id;
-          while (id != null) {
-            const command = document.querySelector("[data-tobago-default='" + id + "']");
-            if (command) {
-              command.dispatchEvent(new MouseEvent("click"));
-              break;
-            }
-            id = Tobago4Utils.getNamingContainerId(id);
-          }
-          return false;
-        }
-      });
-    }
-  }
-
   static onSubmit = function (listenerOptions) {
     Listener.executeBeforeSubmit();
     /*
@@ -310,8 +277,6 @@ export class CommandHelper {
 
 }
 
-Listener.register(CommandHelper.initEnter, Phase.DOCUMENT_READY);
-
 class Transport {
   static requests = [];
   static currentActionId = null;
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts
index bf5953c..0322e54 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts
@@ -19,6 +19,7 @@ import {Listener} from "./tobago-listener";
 import {Overlay} from "./tobago-overlay";
 import {DomUtils} from "./tobago-utils";
 import {CommandHelper} from "./tobago-command";
+import {Page} from "./tobago-page";
 
 /**
  * @deprecated since 5.0.0
@@ -52,7 +53,7 @@ export class Setup {
 
   static onBeforeUnload = function () {
     if (Setup.transition) {
-      new Overlay(DomUtils.page());
+      new Overlay(Page.page());
     }
     Setup.transition = Setup.oldTransition;
   };
@@ -64,7 +65,7 @@ export class Setup {
     console.info('on onload');
     if (CommandHelper.isSubmit) {
       if (Setup.transition) {
-        new Overlay(DomUtils.page());
+        new Overlay(Page.page());
       }
       Setup.transition = Setup.oldTransition;
     } else {
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts
index f6c19d5..006a8aa 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts
@@ -17,11 +17,12 @@
 
 import {DomUtils} from "./tobago-utils";
 import {Listener, Phase} from "./tobago-listener";
+import {Page} from "./tobago-page";
 
 export class Focus {
 
   private static getHidden(): HTMLInputElement {
-    return document.getElementById(DomUtils.page().id + DomUtils.SUB_COMPONENT_SEP + "lastFocusId") as HTMLInputElement;
+    return document.getElementById(Page.page().id + DomUtils.SUB_COMPONENT_SEP + "lastFocusId") as HTMLInputElement;
   }
 
   static setLastFocusId(id: string): void {
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts
index 1eb6b25..5629749 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts
@@ -74,8 +74,8 @@ class Jsf {
               Listener.executeAfterUpdate(document.getElementById(id));
             } else if (Jsf.isBody(id)) {
               console.debug("[tobago-jsf] updating body");
-              // there should be only one element with this class
-              Listener.executeAfterUpdate(document.querySelector(".tobago-page") as HTMLElement);
+              // there should be only one element with this tag name
+              Listener.executeAfterUpdate(document.querySelector("tobago-page") as HTMLElement);
             }
           }
         });
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-overlay.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-overlay.ts
index be309d2..19b1f0d 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-overlay.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-overlay.ts
@@ -21,6 +21,7 @@
 
 import {DomUtils} from "./tobago-utils";
 import {Config} from "./tobago-config";
+import {Page} from "./tobago-page";
 
 // XXX issue: if a ajax call is scheduled on the same element, the animation arrow will stacking and not desapearing.
 // XXX issue: "error" is not implemented correctly
@@ -99,7 +100,7 @@ export class Overlay {
     wait.append(image);
     wait.style.display = ""; //XXX ?
 
-    this.overlay.style.backgroundColor = DomUtils.page().style.backgroundColor;
+    this.overlay.style.backgroundColor = Page.page().style.backgroundColor;
     this.overlay.style.left = left;
     this.overlay.style.top = top;
     setTimeout(() => { // to play the CSS transition
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-page.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-page.ts
new file mode 100644
index 0000000..b7b595a
--- /dev/null
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-page.ts
@@ -0,0 +1,75 @@
+/*
+ * 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 {Tobago4Utils} from "./tobago-utils";
+
+export class Page extends HTMLElement {
+
+  /**
+   * The Tobago root element
+   */
+  static page(): HTMLElement {
+    const pages = document.getElementsByTagName("tobago-page");
+    if (pages.length > 0) {
+      if (pages.length >= 2) {
+        console.warn("Found more than one tobago page!");
+      }
+      return pages.item(0) as HTMLElement;
+    }
+    console.warn("Found no tobago page!");
+    return null;
+  }
+
+  constructor() {
+    super();
+  }
+
+  connectedCallback() {
+    this.addEventListener("keypress", function (event: KeyboardEvent) {
+      let code = event.which; // XXX deprecated
+      if (code === 0) {
+        code = event.keyCode;
+      }
+      if (code === 13) {
+        let target = event.target as HTMLElement;
+        if (target.tagName === "A" || target.tagName === "BUTTON") {
+          return;
+        }
+        if (target.tagName === "TEXTAREA") {
+          if (!event.metaKey && !event.ctrlKey) {
+            return;
+          }
+        }
+        const name = target.getAttribute("name");
+        let id = name ? name : target.id;
+        while (id != null) {
+          const command = document.querySelector("[data-tobago-default='" + id + "']");
+          if (command) {
+            command.dispatchEvent(new MouseEvent("click"));
+            break;
+          }
+          id = Tobago4Utils.getNamingContainerId(id);
+        }
+        return false;
+      }
+    });
+  }
+}
+
+document.addEventListener("DOMContentLoaded", function (event) {
+  window.customElements.define('tobago-page', Page);
+});
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts
index 2ed1b61..99a524a 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts
@@ -18,6 +18,7 @@
 import {Listener, Phase} from "./tobago-listener";
 import {DomUtils} from "./tobago-utils";
 import {CommandHelper} from "./tobago-command";
+import {Page} from "./tobago-page";
 
 class Sheet {
 
@@ -257,7 +258,7 @@ class Sheet {
 
   mousedown(event: MouseEvent) {
 
-    DomUtils.page().dataset["SheetMousedownData"] = this.id;
+    Page.page().dataset["SheetMousedownData"] = this.id;
 
     // begin resizing
     console.debug("down");
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts
index a18e9b0..f6ad67e 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts
@@ -16,6 +16,7 @@
  */
 
 import {DomUtils} from "./tobago-utils";
+import {Page} from "./tobago-page";
 
 class SplitLayout extends HTMLElement {
 
@@ -128,16 +129,16 @@ class SplitLayoutMousedown {
       horizontal: horizontal,
       splitterIndex: this.indexOfSplitter(splitter, horizontal)
     };
-    DomUtils.page().dataset["SplitLayoutMousedownData"] = JSON.stringify(data);
+    Page.page().dataset["SplitLayoutMousedownData"] = JSON.stringify(data);
     return new SplitLayoutMousedown(data);
   }
 
   static load() {
-    return new SplitLayoutMousedown(DomUtils.page().dataset["SplitLayoutMousedownData"]);
+    return new SplitLayoutMousedown(Page.page().dataset["SplitLayoutMousedownData"]);
   }
 
   static remove() {
-    DomUtils.page().dataset["SplitLayoutMousedownData"] = null;
+    Page.page().dataset["SplitLayoutMousedownData"] = null;
   }
 
   private static indexOfSplitter(splitter: HTMLElement, horizontal: boolean): number {
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts
index 15081e9..d3dd795 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts
@@ -28,21 +28,6 @@ export class DomUtils {
   static readonly SUB_COMPONENT_SEP = '::';
 
   /**
-   * The Tobago root element
-   */
-  static page(): HTMLElement {
-    const pages = document.getElementsByClassName("tobago-page");
-    if (pages.length > 0) {
-      if (pages.length >= 2) {
-        console.warn("Found more than one tobago page!");
-      }
-      return pages.item(0) as HTMLElement;
-    }
-    console.warn("Found no tobago page!");
-    return null;
-  }
-
-  /**
    * Find all elements (and also self) which have the class "className".
    * @param element Starting element in DOM to collect.
    * @param className Class of elements to find.