documentation/extensions/switcher/static/js/switcher.js

37 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2021-02-05 00:10:54 +07:00
(function ($) {
// TODO EDI custom css for content-switcher logic
// can be placed as css inside the extension ideally
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('.content-switcher').forEach(switcher => {
const links = switcher.querySelectorAll('ul li');
const linksArray = Array.from(links);
2021-02-19 16:47:12 +07:00
const tabs = switcher.querySelectorAll('.tab-content > div');
2021-02-05 00:10:54 +07:00
2021-02-19 16:47:12 +07:00
tabs.forEach(tab => {
tab.classList.add('tab-pane');
2021-02-19 17:39:43 +07:00
});
2021-02-05 00:10:54 +07:00
function select(index) {
links.forEach(link => {
link.classList.remove('active');
});
tabs.forEach(tab => {
tab.classList.remove('active');
});
links[index].classList.add('active');
tabs[index].classList.add('active');
}
select(0);
links.forEach(link => {
link.addEventListener('click', ev => {
// const clickedLink = ev.target.closest('ul li');
select(linksArray.indexOf(link));
});
});
});
});
})();