git ssb

2+

cel / scuttlebot.io



Tree: c83445d9bbe38b0be91be64d4cba8164efb72630

Files: c83445d9bbe38b0be91be64d4cba8164efb72630 / tmpl / js / code-examples.js

827 bytesRaw
1window.addEventListener('load', function () {
2 Array.prototype.forEach.call(document.querySelectorAll('.code-examples'), setupCodeExample)
3})
4
5function setupCodeExample (codeExamples) {
6 // select the current code example
7 selectTab(codeExamples, 1)
8 // attach click handlers
9 Array.prototype.forEach.call(codeExamples.querySelectorAll('.tab'), function (tab, n) {
10 tab.addEventListener('click', selectTab.bind(null, codeExamples, (n+1)))
11 })
12}
13
14function selectTab (el, n) {
15 // deselect current
16 try { el.querySelector('pre.current').classList.remove('current') } catch (e) {}
17 try { el.querySelector('.tab.current').classList.remove('current') } catch (e) {}
18 // select new
19 el.querySelector('pre:nth-child('+n+')').classList.add('current')
20 el.querySelector('.tab:nth-child('+n+')').classList.add('current')
21}

Built with git-ssb-web