Resurrect js of switcher directive.
This commit is contained in:
parent
f35018494e
commit
bf63a4a447
@ -1,3 +1,5 @@
|
|||||||
|
# TODO VFE licensing ?
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import io
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import os.path
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.parsers.rst import Directive
|
from docutils.parsers.rst import Directive
|
||||||
|
|
||||||
@ -8,6 +10,15 @@ def setup(app):
|
|||||||
app.add_directive('switcher', SwitcherDirective)
|
app.add_directive('switcher', SwitcherDirective)
|
||||||
app.add_directive('case', CaseDirective)
|
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):
|
class SwitcherDirective(Directive):
|
||||||
has_content = True
|
has_content = True
|
||||||
|
32
extensions/switcher/static/js/switcher.js
Normal file
32
extensions/switcher/static/js/switcher.js
Normal 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));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user