Skip to content

Commit

Permalink
fix: docs navigation doesn't show user's location
Browse files Browse the repository at this point in the history
Ticket: ENT-10267
Changelog: None
Signed-off-by: Mikita Pilinka <[email protected]>
  • Loading branch information
mineralsfree committed Dec 1, 2023
1 parent 1209bed commit f4c2ae9
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions generator/_assets/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ var buildBreadcrumbs = function (items) {
'<a href="'+ lastItem.href +'">'+ lastItem.name +' <i class="bi bi-box-arrow-up-right"></i></a>' :
'';
}
buildBreadcrumbs(clickedMenuHistory);

document.querySelector('.menu-back').onclick = function () {
if (clickedMenuHistory.length != 1) {
Expand All @@ -249,18 +248,34 @@ document.querySelector('.menu-back').onclick = function () {
var urlPaths = document.location.pathname.split('/');
var url = urlPaths[urlPaths.length - 1]; // get last url part
var currentMenuItem = document.querySelector('.left-menu li[data-url="'+ url +'"]');


if (currentMenuItem != null) {
currentMenuItem.className += ' opened current';
const menuHistory = [];
const currentLink = currentMenuItem.querySelector('a');
// if selected menu item is a parent we show children on mobile menu
if (currentLink && currentMenuItem.classList.contains('parent')){
menuHistory.unshift({href: currentLink.getAttribute('href'), name: currentLink.innerText});
}
var closest = currentMenuItem.closest('ul').closest('li');

if (window.innerWidth > 1023) { // if the window width more than 1023 then treat the menu as desktop one
var closest = currentMenuItem.closest('ul').closest('li');
while (true) {
if (!closest) break;
while (true) {
if (!closest) break;
if (window.innerWidth > 1023) { // if the window width more than 1023 then treat the menu as desktop one
closest.classList.add('opened');
closest = closest.closest('ul').closest('li');
} else {
// Restore history from html
const link = closest.querySelector('a');
if (link){
menuHistory.unshift({href: link.getAttribute('href'), name: link.innerText});
}
}
closest = closest.closest('ul').closest('li');
}
clickedMenuHistory = clickedMenuHistory.concat(menuHistory);
}
buildBreadcrumbs(clickedMenuHistory);

if (window.innerWidth > 1023) {
document.querySelectorAll('.mainMenu li.parent > i').forEach(function (element) {
Expand All @@ -269,6 +284,10 @@ if (window.innerWidth > 1023) {
element.closest('li.parent').classList.toggle('opened');
}
});
} else {
// Small screen
const lastHistoryElement = clickedMenuHistory[clickedMenuHistory.length - 1];
renderNestedMenu(lastHistoryElement.href);
}

function fillVersionWrapperSelect(url) {
Expand Down

0 comments on commit f4c2ae9

Please sign in to comment.