git ssb

2+

cel / scuttlebot.io



Tree: 9c65ae548c83ca8fafeec171a0a0bc7ebf386a11

Files: 9c65ae548c83ca8fafeec171a0a0bc7ebf386a11 / 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