Skip to content

Commit

Permalink
review fixes pt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
bozatko committed Dec 11, 2024
1 parent e2cef75 commit 2324b86
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/bundle/Resources/public/js/scripts/core/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
let toggleAllTimeout;
const MULTI_COLLAPSE_BTN_TAG = 'data-multi-collapse-btn-id';
const COLLAPSE_SECTION_BODY_TAG = 'data-multi-collapse-body';
const MULTI_COLLAPSE_ELEMENT_SELECTOR = '.ibexa-multicollapse--item';
const toggleAllBtns = doc.querySelectorAll(`[${MULTI_COLLAPSE_BTN_TAG}]`);
const multiCollapsBodies = doc.querySelectorAll(`[${COLLAPSE_SECTION_BODY_TAG}]`);

Expand Down Expand Up @@ -37,7 +36,7 @@
}
};
const toggleMultiCollapseIfNeeded = (multiCollapseNode, toggleBtn, tabllLength) => {
const allElements = multiCollapseNode.querySelectorAll(MULTI_COLLAPSE_ELEMENT_SELECTOR);
const allElements = multiCollapseNode.querySelectorAll('.ibexa-multicollapse--item');

if (tabllLength === allElements.length || tabllLength === 0) {
toggleMultiCollapseButton(toggleBtn, tabllLength === 0);
Expand All @@ -56,7 +55,7 @@
const isElementCollapsed = collapseNode.classList.contains('ibexa-collapse--collapsed');

if (expandAction === isElementCollapsed) {
bootstrap.Collapse.getOrCreateInstance(collapseNode.querySelector(MULTI_COLLAPSE_ELEMENT_SELECTOR)).toggle();
bootstrap.Collapse.getOrCreateInstance(collapseNode.querySelector('.ibexa-multicollapse--item')).toggle();

if (!expandAction) {
const uniqueName = collapseNode.querySelector('.ibexa-collapse__toggle-btn').getAttribute('data-bs-target');
Expand All @@ -73,7 +72,7 @@
collapseNode.classList.toggle('ibexa-collapse--collapsed', isCollapsed);
collapseNode.dataset.collapsed = isCollapsed;

if (toggleAllBtns && toggleAllBtns.length > 0) {
if (toggleAllBtns.length > 0) {
const multicollapseNode = collapseNode.closest(`[${COLLAPSE_SECTION_BODY_TAG}]`);

if (!!multicollapseNode) {
Expand Down Expand Up @@ -131,12 +130,12 @@
});
});

if (toggleAllBtns) {
if (toggleAllBtns.length > 0) {
toggleAllBtns.forEach((btn) => {
btn.addEventListener('click', (event) => {
event.stopPropagation();

const collapseAll = btn?.querySelector('.ibexa-multi-collapse__toggler-collapse');
const collapseAll = btn.querySelector('.ibexa-multi-collapse__toggler-collapse');
const collapseSelector = btn.getAttribute(MULTI_COLLAPSE_BTN_TAG);
if (!!collapseSelector) {
const multiCollapseNode = Array.from(multiCollapsBodies).find(
Expand Down

0 comments on commit 2324b86

Please sign in to comment.