PluginProbe
SimpleTOC – Table of Contents Block / 7.3.1
SimpleTOC – Table of Contents Block v7.3.1
7.3.1 7.2.0 7.3.0 7.1.1 7.1.0 7.0.10 7.0.9 7.0.8 7.0.7 7.0.6 7.0.4 7.0.5 5.0.21.1 5.0.22 5.0.23 5.0.24 5.0.25 5.0.25.1 5.0.27 5.0.28 5.0.29 5.0.3 5.0.30 5.0.31 5.0.32 All 160 releases
simpletoc / assets / accordion.js

accordion.js in SimpleTOC – Table of Contents Block 7.3.1, at assets/accordion.js

37 lines 989 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * SimpleTOC load function.
3 */
4 const simpletocLoad = function () {
5 const buttons = document.querySelectorAll( 'button.simpletoc-collapsible' );
6
7 buttons.forEach( ( button ) => {
8 button.addEventListener( 'click', () => {
9 button.classList.toggle( 'active' );
10 const content = button.parentElement.nextElementSibling;
11 const isCollapsed =
12 ! content.style.maxHeight || content.style.maxHeight === '0px';
13
14 button.setAttribute(
15 'aria-expanded',
16 isCollapsed ? 'true' : 'false'
17 );
18 content.style.maxHeight = isCollapsed
19 ? `${ content.scrollHeight }px`
20 : '0px';
21 } );
22 } );
23 };
24
25 // Allow others to call function if needed.
26 window.simpletocLoad = simpletocLoad;
27
28 // Check to see if the document is already loaded.
29 if ( document.readyState === 'complete' || document.readyState !== 'loading' ) {
30 simpletocLoad();
31 } else {
32 // Fallback event if the document is not loaded.
33 document.addEventListener( 'DOMContentLoaded', () => {
34 simpletocLoad();
35 } );
36 }
37