diff --git a/Makefile b/Makefile index aa8def898..9544a1607 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ clean: $(RM_CMD) extensions/odoo_theme/static/style.css @echo "Cleaning finished." -edi: SPHINXOPTS += -A collapse_menu=True +#edi: SPHINXOPTS += -A collapse_menu=True # If needed, comment rather than setting False edi: VERSIONS += 12.0,13.0,14.0 edi: CANONICAL_VERSION += 14.0 edi: LANGUAGES += en,fr,es diff --git a/extensions/odoo_theme/__init__.py b/extensions/odoo_theme/__init__.py index c9dc239b7..6b167c589 100644 --- a/extensions/odoo_theme/__init__.py +++ b/extensions/odoo_theme/__init__.py @@ -14,6 +14,7 @@ def setup(app): # If not, remove update_meta method app.connect('html-page-context', update_meta) + app.add_js_file('js/utils.js') # Keep in first position app.add_js_file('js/layout.js') app.add_js_file('js/menu.js') app.add_js_file('js/page_toc.js') diff --git a/extensions/odoo_theme/layout_templates/menu.html b/extensions/odoo_theme/layout_templates/menu.html index 7f231861f..29a7f214c 100644 --- a/extensions/odoo_theme/layout_templates/menu.html +++ b/extensions/odoo_theme/layout_templates/menu.html @@ -5,5 +5,8 @@ title_only: Whether menu items for content pages (without toctree) should be hidden includehidden: Whether menu items of pages inside a hidden toctree should be rendered #} -{{ toctree(collapse=collapse_menu, titles_only=True, includehidden=True)}} -{# TODO replace `collapse_menu` by `True` and remove Makefile entry 'light' #} \ No newline at end of file +{# + `collapse_menu` is passed directly to Jinja with sphinx-build's option `-A collapse_menu=True`. + It it evaluated as a string, so what we're really evaluating here is `collapse_menu != None`. +#} +{{ toctree(collapse=collapse_menu, titles_only=True, includehidden=True)}} \ No newline at end of file diff --git a/extensions/odoo_theme/static/js/menu.js b/extensions/odoo_theme/static/js/menu.js index b92f3f0ce..ca6253a15 100644 --- a/extensions/odoo_theme/static/js/menu.js +++ b/extensions/odoo_theme/static/js/menu.js @@ -1,19 +1,20 @@ (function ($) { document.addEventListener('DOMContentLoaded', () => { - const navigationMenu = document.getElementById('o_main_toctree'); + this.navigationMenu = document.getElementById('o_main_toctree'); + + // Allow to automatically collapse and expand TOC entries + _prepareAccordion(this.navigationMenu); // Add a class with the name of the file to each corresponding menu item - _flagMenuItemsWithFileName(navigationMenu); + _flagMenuItemsWithFileName(); }); /** * Add the name of the file as class of the corresponding menu item. - * - * @param {HTMLElement} navigationMenu - The navigation menu containing the global TOC */ - const _flagMenuItemsWithFileName = (navigationMenu) => { - navigationMenu.querySelectorAll('li').forEach(menuItem => { + const _flagMenuItemsWithFileName = () => { + this.navigationMenu.querySelectorAll('li').forEach(menuItem => { let href = menuItem.querySelector('a').href; if (href === '#') { // Selected nodes don't have their file name in the href href = window.location.href; // Get it from the current window location diff --git a/extensions/odoo_theme/static/js/page_toc.js b/extensions/odoo_theme/static/js/page_toc.js index f660061c2..49e2e8d81 100644 --- a/extensions/odoo_theme/static/js/page_toc.js +++ b/extensions/odoo_theme/static/js/page_toc.js @@ -16,7 +16,7 @@ _flagFirstHeadingRef(); // Allow to automatically collapse and expand TOC entries - _prepareAccordion(); + _prepareAccordion(this.pageToc); // Allow to respectively highlight and expand the TOC entries and their related TOC // entry list whose section is focused. @@ -115,48 +115,4 @@ */ const _hidePageToc = () => this.pageToc.style.visibility = 'hidden'; - /** - * Update the page TOC entries and heading references to allow collapsing them. - * - * The typical structure of a TOC menu is a follows: - *
- * - * Since a