function createtoc (maxlevel) { // creates a TOC and puts it in a div with id="toc" & creates a self-link // every heading must be a child of a section which has an id // expect to find the id on the heading markup, NOT the section, and NO a around the heading text // works for h2 or h2+h3 (if maxlevel set to 3) // puts self links on h2, h3, AND h4 (but doesn't add h4 to the TOC) // calls setSectionRefs setFigRefs if (typeof maxlevel === 'boolean' && maxlevel === true) maxlevel = 3 var olNode, ololNode, selflink, h2Nodes, h3Nodes, h4Nodes, liNode, liliNode, aNode, aaNode var i, k, m var toc = document.getElementById('toc') var h2InnerHTML, h3InnerHTML olNode = toc.appendChild(document.createElement('ol')) h2Nodes = document.querySelectorAll('h2') for (i=0; i selflink = document.createElement('a') selflink.className = 'selflink' selflink.href = '#'+h2Nodes[i].parentNode.id h2Nodes[i].appendChild(selflink) liNode = document.createElement('li') aNode = document.createElement('a') aNode.href = '#'+h2Nodes[i].parentNode.id aNode.innerHTML = h2InnerHTML liNode.appendChild(aNode) liNode.className = 'toc1' if (maxlevel && maxlevel > 2) { // check for h3Nodes h3Nodes = h2Nodes[i].parentNode.querySelectorAll('h3') if (h3Nodes.length > 0) ololNode = olNode.appendChild(document.createElement('ol')) for (k=0; k // called by createtoc // local: figs figures counter i figrefs // make a list of figures with captions var figs = document.querySelectorAll('figure') var figures = {} var counter = 0 for (var i=0;i