From c50e05530ee0ca34f4429318055b6dc8da662a79 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Pasquier Date: Tue, 29 Oct 2019 15:38:33 +0100 Subject: [PATCH] fix: js recursive parent selector for admin --- src/scripts/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/scripts/index.js b/src/scripts/index.js index 0e786f7..2648789 100644 --- a/src/scripts/index.js +++ b/src/scripts/index.js @@ -1,3 +1,13 @@ +function querySelectorParentChild(el, selector) { + while(el !== document.body) { + if(el.querySelector(selector)) { + break; + } + el = el.parentNode; + } + return el.querySelector(selector); +} + document.addEventListener('DOMContentLoaded', function (event) { const menuWrappers = Array.from(document.querySelectorAll('.menu-wrapper')); const rightMenus = Array.from(document.querySelectorAll('nav.jsRightMenu')); @@ -46,11 +56,10 @@ document.addEventListener('DOMContentLoaded', function (event) { for(sibForm of document.querySelectorAll('[set-user-id-select]')) { sibForm.addEventListener('populate', () => { - document.querySelectorAll('sib-form[submit-button^="Join"]').forEach(el=>el.style.display = 'none'); - if(document.querySelectorAll('sib-ac-checker:not([hidden]) > sib-delete[data-label^="Leave"]').length == 0) { - document.querySelectorAll('sib-form[submit-button^="Join"]').forEach(el=>el.style.display = 'inline-block'); - } // BUG: Populate event trigger before the view is fully loaded! - https://git.happy-dev.fr/startinblox/framework/sib-core/issues/521 + document.querySelectorAll('sib-ac-checker:not([hidden]) > sib-delete[data-label^="Leave"]').forEach((el)=>{ + querySelectorParentChild(el, 'sib-form[submit-button^="Join"]').style.display = "none"; + }); for(select of sibForm.querySelectorAll('select[name="'+sibForm.getAttribute('set-user-id-select')+'"]')) { for(option of select.options) { option.selected = (option.getAttribute('value') == '{"@id": "'+user['@id']+'"}');