documentation/extensions/odoo_theme/static/js/menu.js
Antoine Vandevenne (anv) 673777a48c add accordion logic to menu
2021-02-19 14:01:26 +01:00

28 lines
1.0 KiB
JavaScript

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