documentation/extensions/odoo_theme/static/js/menu.js
Antoine Vandevenne (anv) ebc3e70d0f [APOCALYPSE] Merge all documentations and add a new homemade theme
Co-authored-by: Victor Feyens (vfe) <vfe@odoo.com>
Co-authored-by: Elisabeth Dickinson (edi) <edi@odoo.com>
Co-authored-by: Antoine Vandevenne (anv) <anv@odoo.com>
2021-01-28 19:05:48 +01:00

27 lines
1.0 KiB
JavaScript

(function ($) {
document.addEventListener('DOMContentLoaded', () => {
const navigationMenu = document.getElementById('o_main_toctree');
// Add a class with the name of the file to each corresponding menu item
_flagMenuItemsWithFileName(navigationMenu);
});
/**
* 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 => {
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
}
const fileName = href.substring(href.lastIndexOf('/') + 1, href.lastIndexOf('.html'));
menuItem.classList.add(`o_menu_${fileName}`);
});
};
})();