Mecha CMS

Mecha CMS blog and documentation.

Toggle TOC Header

Updated: Sunday, 07 August 2016

Transform your table of content title into a toggle link.

Table of Content

Toggle Toc Plugin

Add this snippet to your functions.php file of your active shield:

Weapon::add('SHIPMENT_REGION_BOTTOM', function() {
    echo '<script>!function(){for(var e,n=document.querySelectorAll(".toc-header"),t=0,r=n.length;r>t;++t)e=document.createElement("a"),e.href="#toggle",e.style.color="inherit",e.onclick=function(){return this.parentNode.nextSibling.classList.toggle("hidden"),!1},e.innerHTML=n[t].innerHTML,n[t].innerHTML="",n[t].appendChild(e)}();</script>';
});

Original Output

<script>
(function() {
    var toc_h = document.querySelectorAll('.toc-header'), a;
    for (var i = 0, len = toc_h.length; i < len; ++i) {
        a = document.createElement('a');
        a.href = '#toggle';
        a.style.color = 'inherit';
        a.onclick = function() {
            this.parentNode.nextSibling.classList.toggle('hidden');
            return false;
        };
        a.innerHTML = toc_h[i].innerHTML;
        toc_h[i].innerHTML = "";
        toc_h[i].appendChild(a);
    }
})();
</script>

Related: broken

Donation and Email Subscription