
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>
27 lines
1.0 KiB
JavaScript
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}`);
|
|
});
|
|
};
|
|
|
|
})();
|