Resurrect js of switcher directive.

This commit is contained in:
Victor Feyens 2021-02-04 18:10:54 +01:00
parent f35018494e
commit bf63a4a447
3 changed files with 45 additions and 0 deletions

View File

@ -1,3 +1,5 @@
# TODO VFE licensing ?
import collections
import io
import itertools

View File

@ -1,3 +1,5 @@
import os.path
from docutils import nodes
from docutils.parsers.rst import Directive
@ -8,6 +10,15 @@ def setup(app):
app.add_directive('switcher', SwitcherDirective)
app.add_directive('case', CaseDirective)
app.connect('env-updated', add_statics)
def add_statics(app, env):
app.add_js_file('js/switcher.js')
env.config.html_static_path.append(statics())
statics = lambda *p: os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'static', *p)
class SwitcherDirective(Directive):
has_content = True

View File

@ -0,0 +1,32 @@
(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);
const tabs = switcher.querySelectorAll('.tabs > div');
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));
});
});
});
});
})();