diff --git a/extensions/patchqueue/__init__.py b/extensions/patchqueue/__init__.py index f79990652..5dda58851 100644 --- a/extensions/patchqueue/__init__.py +++ b/extensions/patchqueue/__init__.py @@ -1,3 +1,5 @@ +# TODO VFE licensing ? + import collections import io import itertools diff --git a/extensions/switcher/__init__.py b/extensions/switcher/__init__.py index d1220b5ce..1ac17f0f1 100644 --- a/extensions/switcher/__init__.py +++ b/extensions/switcher/__init__.py @@ -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 diff --git a/extensions/switcher/static/js/switcher.js b/extensions/switcher/static/js/switcher.js new file mode 100644 index 000000000..ceaf17786 --- /dev/null +++ b/extensions/switcher/static/js/switcher.js @@ -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)); + }); + }); + }); + }); + +})();