diff --git a/generator/_assets/js/custom.js b/generator/_assets/js/custom.js index 96e4beeba..5e4f9a02d 100755 --- a/generator/_assets/js/custom.js +++ b/generator/_assets/js/custom.js @@ -235,7 +235,6 @@ var buildBreadcrumbs = function (items) { ''+ lastItem.name +' ' : ''; } -buildBreadcrumbs(clickedMenuHistory); document.querySelector('.menu-back').onclick = function () { if (clickedMenuHistory.length != 1) { @@ -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 a = currentMenuItem.querySelector('a'); + // if selected menu item is a parent we show children on mobile menu + if (a && currentMenuItem.classList.contains('parent')){ + menuHistory.unshift({href: a.getAttribute('href'), name: a.innerText}) + } + let 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 a = closest.querySelector('a'); + if (a){ + menuHistory.unshift({href: a.getAttribute('href'), name: a.innerText}) + } } + closest = closest.closest('ul').closest('li'); } + clickedMenuHistory = [...clickedMenuHistory, ...menuHistory] } +buildBreadcrumbs(clickedMenuHistory); if (window.innerWidth > 1023) { document.querySelectorAll('.mainMenu li.parent > i').forEach(function (element) { @@ -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) {