{
+ /* Wrap header nodes text content inside separate element */
+ pel.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach( el => {
+ var target = document.createElement("div");
+ target.classList.add('inner');
+ nextUntil( el, 'ul' ).forEach( next => { next.parentNode.insertBefore(target, next); /*next.parentNode.removeChild(next);*/ target.appendChild(next); });
+ });
+ /* Main Initialization */
+ pel.querySelectorAll("ul h1,h2,h3,h4,h5,h6").forEach( el => { el.classList.remove('toc-header'); });
+ if ( pel.querySelector("ul") ) pel.querySelector("ul").classList.add('faccordion');
+ pel.querySelectorAll("ul ul").forEach( el => { el.classList.add('inner'); });
+ pel.querySelectorAll("ul h1,h2,h3,h4,h5,h6").forEach( el => { el.classList.add('toggle', 'show'); });
+ pel.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach( header => { Array.prototype.slice.call(header.parentNode.children).forEach( child => { if ( child.parentNode.querySelectorAll("div .inner").length ) { header.classList.add('collapsed'); } else { header.classList.add('single'); } }); });
+ });
+
+ /* Main */
+ document.querySelectorAll('.toggle').forEach( toggle => { toggle.onclick = function(e) {
+
+ e.preventDefault();
+
+ if ( is( toggle.nextElementSibling, 'div.inner' ) ) {
+ toggleExpandIcon( toggle );
+
+ let allNext = nextAll( toggle, ':not(div)' );
+ if ( allNext[0] && allNext[0].classList.contains('show') ) {
+ hideElement( allNext[0] );
+ /*allNext.forEach( next => { hideElement(next); } ); */
+ toggle.parentNode.querySelectorAll('.toggle.show.expanded').forEach( childToggle => { let childAllNext = nextAll( childToggle, ':not(div)' ); toggleExpandIcon( childToggle ); toggleElementVisibility( childToggle.nextElementSibling ); toggleElementVisibility( childAllNext[0] ); } );
+ toggleElementVisibility( toggle.nextElementSibling );
+ } else {
+ siblings(toggle.closest('li'), 'li').forEach( sibling => {
+ sibling.querySelectorAll('.inner').forEach( inner => { hideElement(inner); } );
+ sibling.querySelectorAll('.toggle').forEach( inToggle => { if ( inToggle.classList.contains('expanded') ) { toggleExpandIcon( inToggle ); } } );
+ } );
+ toggleElementVisibility( toggle.nextElementSibling );
+ toggleElementVisibility( allNext[0] );
+ }
+ } else {
+ if ( toggle.nextElementSibling.classList.contains('show') ) {
+ hideElement( toggle.nextElementSibling );
+ } else {
+ toggleElementVisibility( toggle.nextElementSibling );
+ }
+ }
+
+ }});
+
+}
+
+
+
+
+function jsSleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
+
+async function sleep(wait) { await jsSleep(wait); }
+
+
+function isDescendant(parent, child) { var node = child.parentNode; while (node != null) { if (node == parent) { return true; } node = node.parentNode; } return false; }
\ No newline at end of file