Permalink
Browse files

feat(tabs): script to enable tab toggling

  • Loading branch information...
tomheller committed Sep 15, 2016
1 parent a7500dd commit d6451a94bd0a52047c7fa07f238080c4be734558
Showing with 22 additions and 0 deletions.
  1. +1 −0 src/main.js
  2. +21 −0 src/tabs/tabs.js
View
@@ -2,3 +2,4 @@ require('./js-common-components/toggler');
require('./js-common-components/closest');
require('./expandable/expandable');
require('./inputfield/inputfield');
require('./tabs/tabs');
View
@@ -0,0 +1,21 @@
import $ from '../js-common-components/dollar';
require('../js-common-components/closest');
const clickTab = (ev) => {
const target = ev.target;
const tabContainer = target.closest('.tabs');
const tabs = tabContainer.querySelectorAll('.tab');
Array.prototype.forEach.call(tabs, (t) => t.classList.remove('is-active'));
target.classList.add('is-active');
};
const init = () => {
$('button.tab').forEach(el => {
if (!el.getAttribute('data-initialized')) {
el.addEventListener('click', (ev) => clickTab(ev));
el.setAttribute('data-initialized', true);
}
});
};
init();

0 comments on commit d6451a9

Please sign in to comment.