git ssb

2+

cel / scuttlebot.io



Tree: c83445d9bbe38b0be91be64d4cba8164efb72630

Files: c83445d9bbe38b0be91be64d4cba8164efb72630 / tmpl / js / table-of-contents.js

785 bytesRaw
1window.addEventListener('load', function () {
2 setupTOC(document.querySelector('.table-of-contents'))
3})
4
5function setupTOC (toc) {
6 // attach click handlers
7 toc.querySelector('a').addEventListener('click', function (e) {
8 e.preventDefault()
9 e.stopPropagation()
10 toc.classList.add('expanded')
11 })
12 document.body.addEventListener('click', function () {
13 toc.classList.remove('expanded')
14 })
15}
16
17function selectTab (el, n) {
18 // deselect current
19 try { el.querySelector('pre.current').classList.remove('current') } catch (e) {}
20 try { el.querySelector('.tab.current').classList.remove('current') } catch (e) {}
21 // select new
22 el.querySelector('pre:nth-child('+n+')').classList.add('current')
23 el.querySelector('.tab:nth-child('+n+')').classList.add('current')
24}

Built with git-ssb-web