Skip to content

Instantly share code, notes, and snippets.

@nicdford
Last active August 28, 2020 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicdford/e3ef9931376d4848b3a19ee76b935137 to your computer and use it in GitHub Desktop.
Save nicdford/e3ef9931376d4848b3a19ee76b935137 to your computer and use it in GitHub Desktop.
JS to convert Make Page Builder sections into Accordion Items
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