Last active
August 28, 2020 17:40
-
-
Save nicdford/e3ef9931376d4848b3a19ee76b935137 to your computer and use it in GitHub Desktop.
JS to convert Make Page Builder sections into Accordion Items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const accordion_items = document.querySelectorAll('.wsu-js-accordion-item'); | |
accordion_items.forEach(item => { | |
// Set initial state | |
const child_divs = Array.from(item.children); | |
child_divs.forEach(element => { | |
if (element.classList.contains('column') && !element.classList.contains('toggle-visible')) { | |
element.classList.add('toggle-visible'); | |
} | |
}); | |
// Control toggle state | |
item.firstElementChild.addEventListener('click', function (e) { | |
e.preventDefault(); | |
if (!item.classList.contains('toggle-is-open')) { | |
item.classList.add('toggle-is-open'); | |
} else { | |
item.classList.remove('toggle-is-open'); | |
} | |
const child_divs = Array.from(item.children); | |
child_divs.forEach(element => { | |
if (element.classList.contains('column') && !element.classList.contains('toggle-visible')) { | |
element.classList.add('toggle-visible'); | |
} else { | |
element.classList.remove('toggle-visible'); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment