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/07/25 14:40:35 UTC

[myfaces-tobago] 02/02: fix exception (AJAX)

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

commit ea8bd65c6f34cd8272f35f1137abf82d3c38ebf5
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Thu Jul 25 16:40:15 2019 +0200

    fix exception (AJAX)
---
 .../src/main/npm/ts/tobago-header-footer.ts        | 52 ++++++++++++----------
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-header-footer.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-header-footer.ts
index 66f0b91..94c2ac7 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-header-footer.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-header-footer.ts
@@ -25,37 +25,41 @@ class HeaderFooter {
     // fixing fixed header/footer: content should not scroll behind the footer
 
     const body = DomUtils.selfOrQuerySelectorAll(element, "body")[0];
-    const headers = DomUtils.selfOrQuerySelectorAll(element, ".fixed-top");
-    const footers = DomUtils.selfOrQuerySelectorAll(element, ".fixed-bottom");
 
-    setMargins(body, headers, footers);
+    if (body) {
+      const headers = DomUtils.selfOrQuerySelectorAll(element, ".fixed-top");
+      const footers = DomUtils.selfOrQuerySelectorAll(element, ".fixed-bottom");
 
-    let lastMaxHeaderHeight = 0;
-    let lastMaxFooterHeight = 0;
+      HeaderFooter.setMargins(body, headers, footers);
 
-    window.addEventListener("resize", function (): void {
-      const maxHeaderHeight: number = HeaderFooter.getMaxHeaderHeight(headers);
-      const maxFooterHeight: number = HeaderFooter.getMaxFooterHeight(footers);
+      let lastMaxHeaderHeight = 0;
+      let lastMaxFooterHeight = 0;
 
-      if (maxHeaderHeight !== lastMaxHeaderHeight
-          || maxFooterHeight !== lastMaxFooterHeight) {
-        setMargins(body, headers, footers);
+      // todo: check possible memory leak: use of DOM elements in event listener!
+      window.addEventListener("resize", function (): void {
+        const maxHeaderHeight: number = HeaderFooter.getMaxHeaderHeight(headers);
+        const maxFooterHeight: number = HeaderFooter.getMaxFooterHeight(footers);
 
-        lastMaxHeaderHeight = maxHeaderHeight;
-        lastMaxFooterHeight = maxFooterHeight;
-      }
-    });
+        if (maxHeaderHeight !== lastMaxHeaderHeight
+            || maxFooterHeight !== lastMaxFooterHeight) {
+          HeaderFooter.setMargins(body, headers, footers);
+
+          lastMaxHeaderHeight = maxHeaderHeight;
+          lastMaxFooterHeight = maxFooterHeight;
+        }
+      });
+    }
+  };
 
-    function setMargins(body: HTMLElement, headers: HTMLElement[], footers: HTMLElement[]): void {
-      const maxHeaderHeight = HeaderFooter.getMaxHeaderHeight(headers);
-      const maxFooterHeight = HeaderFooter.getMaxFooterHeight(footers);
+  static setMargins =  function (body: HTMLElement, headers: HTMLElement[], footers: HTMLElement[]): void {
+    const maxHeaderHeight = HeaderFooter.getMaxHeaderHeight(headers);
+    const maxFooterHeight = HeaderFooter.getMaxFooterHeight(footers);
 
-      if (maxHeaderHeight > 0) {
-        body.style.marginTop = maxHeaderHeight + "px";
-      }
-      if (maxFooterHeight > 0) {
-        body.style.marginBottom = maxFooterHeight + "px";
-      }
+    if (maxHeaderHeight > 0) {
+      body.style.marginTop = maxHeaderHeight + "px";
+    }
+    if (maxFooterHeight > 0) {
+      body.style.marginBottom = maxFooterHeight + "px";
     }
   };