Skip to content

Commit

Permalink
linted js
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoensing committed Jan 30, 2024
1 parent 879f29c commit 75a0253
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/accordion.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
document.addEventListener('DOMContentLoaded', () => {
const buttons = document.querySelectorAll('button.simpletoc-collapsible');
document.addEventListener( 'DOMContentLoaded', () => {
const buttons = document.querySelectorAll( 'button.simpletoc-collapsible' );

buttons.forEach(button => {
button.addEventListener('click', () => {
button.classList.toggle('active');
const content = button.parentElement.nextElementSibling;
const isCollapsed = !content.style.maxHeight || content.style.maxHeight === '0px';
buttons.forEach( ( button ) => {
button.addEventListener( 'click', () => {
button.classList.toggle( 'active' );
const content = button.parentElement.nextElementSibling;
const isCollapsed =
! content.style.maxHeight || content.style.maxHeight === '0px';

button.setAttribute('aria-expanded', isCollapsed ? 'true' : 'false');
content.style.maxHeight = isCollapsed ? `${content.scrollHeight}px` : '0px';
});
});
});
button.setAttribute(
'aria-expanded',
isCollapsed ? 'true' : 'false'
);
content.style.maxHeight = isCollapsed
? `${ content.scrollHeight }px`
: '0px';
} );
} );
} );

0 comments on commit 75a0253

Please sign in to comment.