2021-03-19 20:40:48 +07:00
|
|
|
/* global _prepareAccordion */ //see utils.js
|
2021-01-29 01:05:48 +07:00
|
|
|
(function ($) {
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2021-02-19 20:01:26 +07:00
|
|
|
this.navigationMenu = document.getElementById('o_main_toctree');
|
|
|
|
|
|
|
|
// Allow to automatically collapse and expand TOC entries
|
|
|
|
_prepareAccordion(this.navigationMenu);
|
2021-01-29 01:05:48 +07:00
|
|
|
|
2021-02-19 22:50:46 +07:00
|
|
|
// Allow to respectively highlight and expand the TOC entries and their related TOC
|
|
|
|
// entry list whose page is displayed.
|
|
|
|
_flagActiveTocEntriesAndLists();
|
2021-03-19 20:40:48 +07:00
|
|
|
|
|
|
|
// Show hidden menu when the css classes have been properly specified
|
|
|
|
this.navigationMenu.removeAttribute('hidden');
|
2021-01-29 01:05:48 +07:00
|
|
|
});
|
|
|
|
|
2021-02-19 22:50:46 +07:00
|
|
|
/**
|
|
|
|
* Add the relevant classes on the TOC entries (and lists) whose page is displayed.
|
|
|
|
*
|
2021-02-20 00:48:49 +07:00
|
|
|
* TOC entries (<li> elements) that are on the path of the displayed page receive the
|
|
|
|
* `o_active_toc_entry` class, and their related (parent) TOC entry list (<ul> elements) receive
|
2021-02-26 17:06:05 +07:00
|
|
|
* the `show` (Bootstrap) class.
|
|
|
|
* Also, the deepest TOC entry receives the `o_deepest_active_toc_entry` class, and its child
|
|
|
|
* TOC entry list receives the `show` class.
|
2021-02-19 22:50:46 +07:00
|
|
|
*/
|
|
|
|
const _flagActiveTocEntriesAndLists = () => {
|
2021-02-20 00:48:49 +07:00
|
|
|
let deepestTocEntry = undefined;
|
2021-02-19 22:50:46 +07:00
|
|
|
this.navigationMenu.querySelectorAll('.current').forEach(element => {
|
2021-02-20 00:48:49 +07:00
|
|
|
if (element.tagName === 'UL') {
|
2021-02-19 22:50:46 +07:00
|
|
|
// Expand all related <ul>
|
|
|
|
element.classList.add('show');
|
2021-02-20 00:48:49 +07:00
|
|
|
} else if (element.tagName === 'LI') {
|
|
|
|
// Highlight all <li> in the active hierarchy
|
|
|
|
element.classList.add('o_active_toc_entry');
|
|
|
|
deepestTocEntry = element;
|
2021-02-19 22:50:46 +07:00
|
|
|
}
|
|
|
|
})
|
2021-02-20 00:48:49 +07:00
|
|
|
if (deepestTocEntry) {
|
|
|
|
const childTocEntryList = deepestTocEntry.querySelector('ul');
|
|
|
|
if (childTocEntryList) {
|
|
|
|
childTocEntryList.classList.add('show');
|
2021-02-26 17:19:52 +07:00
|
|
|
} else { // If the toc entry is not a TOC, add the class to its closest ancestor entry
|
|
|
|
deepestTocEntry = deepestTocEntry.parentElement.parentElement;
|
2021-02-20 00:48:49 +07:00
|
|
|
}
|
2021-02-26 17:19:52 +07:00
|
|
|
deepestTocEntry.classList.add('o_deepest_active_toc_entry');
|
2021-02-20 00:48:49 +07:00
|
|
|
}
|
2021-02-19 22:50:46 +07:00
|
|
|
};
|
|
|
|
|
2021-03-09 00:21:03 +07:00
|
|
|
/**
|
|
|
|
* Mobile: Toggle open/close sidebar on click of nav button (&& on swipe left to right?).
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* `o_active_toc_entry` class, and their related (parent) TOC entry list (<ul> elements) receive
|
|
|
|
* the `show` (Bootstrap) class.
|
|
|
|
* Also, the deepest TOC entry receives the `o_deepest_active_toc_entry` class, and its child
|
|
|
|
* Sidebar receives the `o-mobile-show` class.
|
|
|
|
*/
|
|
|
|
|
2021-01-29 01:05:48 +07:00
|
|
|
})();
|