myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject [myfaces-tobago] branch master updated: Don't use document.getElementById etc. (shadow DOM)
Date Fri, 23 Aug 2019 13:17:28 GMT
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 ea586b8  Don't use document.getElementById etc. (shadow DOM)
ea586b8 is described below

commit ea586b897c095cfa4a809d61f7c6b5f73ae5ec0b
Author: Udo Schnurpfeil <lofwyr@apache.org>
AuthorDate: Fri Aug 23 15:17:10 2019 +0200

    Don't use document.getElementById etc. (shadow DOM)
    
    issue: TOBAGO-1633: TS refactoring
---
 .../tobago-theme-standard/src/main/npm/ts/tobago-suggest.ts  | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-suggest.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-suggest.ts
index 06dab90..586194c 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-suggest.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-suggest.ts
@@ -29,7 +29,8 @@ class Suggest extends HTMLElement {
 
     return function findMatches(query, syncResults, asyncResults) {
 
-      let suggest = document.getElementById(input.dataset["tobagoSuggestFor"]) as Suggest;
+      const root = input.getRootNode() as ShadowRoot|Document;
+      let suggest = root.getElementById(input.dataset["tobagoSuggestFor"]) as Suggest;
 
       // todo: suggest.hiddenInput.value should contain the last query value
       if (suggest.hiddenInput.value !== query) {
@@ -153,7 +154,8 @@ class Suggest extends HTMLElement {
   }
 
   connectedCallback() {
-    const input = document.getElementById(this.for) as HTMLInputElement;
+    const root = this.getRootNode() as ShadowRoot|Document;
+    const input = root.getElementById(this.for) as HTMLInputElement;
     const $input = jQuery(input);
 
     if (this.update && input.classList.contains("tt-input")) { // already initialized:
so only update data
@@ -173,14 +175,14 @@ class Suggest extends HTMLElement {
         source = Suggest.fromClient(data2);
       }
 
-      let suggestPopup = document.getElementById(this.id + "::popup");
+      let suggestPopup = root.getElementById(this.id + "::popup");
       if (suggestPopup) {
         suggestPopup.parentElement.removeChild(suggestPopup);
       }
       suggestPopup = document.createElement("div");
       suggestPopup.id = this.id + "::popup";
       suggestPopup.classList.add("tt-menu", "tt-empty");
-      document.querySelector(".tobago-page-menuStore").appendChild(suggestPopup);
+      root.querySelector(".tobago-page-menuStore").appendChild(suggestPopup);
 
       const menu = this.localMenu ? null : suggestPopup;
 
@@ -208,7 +210,7 @@ class Suggest extends HTMLElement {
       // old with jQuery:
       $input.on('typeahead:open', function (event: JQuery.Event) {
         const input = this;
-        const suggestPopup = document.getElementById(input.dataset["tobagoSuggestFor"] +
"::popup");
+        const suggestPopup = root.getElementById(input.dataset["tobagoSuggestFor"] + "::popup");
         suggestPopup.style.top = DomUtils.offset(input).top + input.offsetHeight + "px";
         suggestPopup.style.left = DomUtils.offset(input).left + "px";
         suggestPopup.style.minWidth = input.offsetWidth + "px";


Mime
View raw message