From 0e51eba4342cb167d22c2085aab59960e5639e38 Mon Sep 17 00:00:00 2001 From: frankpagan Date: Sun, 12 May 2024 12:21:28 -0500 Subject: [PATCH] fix: conditins for show and hide queryElements --- src/index.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/index.js b/src/index.js index 136c570..6c32de9 100644 --- a/src/index.js +++ b/src/index.js @@ -28,8 +28,7 @@ function initElement(el) { el.removeEventListener('change', selectShowHideEle); el.addEventListener("change", selectShowHideEle); - } - else { + } else { el.removeEventListener('change', selectShowHideEle); el.removeEventListener("click", clickShowHideEle); @@ -82,30 +81,31 @@ function clickShowHideEle(e) { el.removeAttribute('hidden'); } } - } - else { + } else { let updated_els = []; - for (let el of queryElements({ element: document, selector: show, type: 'selector' })) { - if (el.hasAttribute('hidden')) { - el.removeAttribute('hidden'); - updated_els.push(el); + if (show) + for (let el of queryElements({ element: document, selector: show, type: 'selector' })) { + if (el.hasAttribute('hidden')) { + el.removeAttribute('hidden'); + updated_els.push(el); + } } - } - for (let el of queryElements({ element: document, selector: hide, type: 'selector' })) { - let existEqual = false; - for (let uel of updated_els) { - if (el.isEqualNode(uel)) { - existEqual = true; - break; + if (hide) + for (let el of queryElements({ element: document, selector: hide, type: 'selector' })) { + let existEqual = false; + for (let uel of updated_els) { + if (el.isEqualNode(uel)) { + existEqual = true; + break; + } } - } - if (!existEqual) - el.setAttribute('hidden', '') - } + if (!existEqual) + el.setAttribute('hidden', '') + } } document.dispatchEvent(new CustomEvent('showHide', {