git ssb

2+

cel / scuttlebot.io



Tree: b24a8c824494555ff39be898c3fde5541e7e8a92

Files: b24a8c824494555ff39be898c3fde5541e7e8a92 / 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