Skip to content

Commit

Permalink
fix: conditins for show and hide queryElements
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed May 12, 2024
1 parent 715f353 commit 0e51eba
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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', {
Expand Down

0 comments on commit 0e51eba

Please sign in to comment.