Menu ignores query parameter
Posted: 23 Mar 2023, 00:27
I have an application where some menu entries (second level sub menu) only differ in the query parameter of the URL.
For example:
Link 1: http://localhost/my-application/list.xhtml
Link 2: http://localhost/my-application/list.xhtml?type=opened
Link 3: http://localhost/my-application/list.xhtml?type=closed
With the default layout.js all three menu entries are highlighted as active. I added a workaround for this, which was now overwritten when I upgraded to version 5.1.0. So now I added my workaround again. Can you add a proper fix for this so that I do not always need to apply my workaround?
This is the part of my layout.js that fixes it for two levels:
For example:
Link 1: http://localhost/my-application/list.xhtml
Link 2: http://localhost/my-application/list.xhtml?type=opened
Link 3: http://localhost/my-application/list.xhtml?type=closed
With the default layout.js all three menu entries are highlighted as active. I added a workaround for this, which was now overwritten when I upgraded to version 5.1.0. So now I added my workaround again. Can you add a proper fix for this so that I do not always need to apply my workaround?
This is the part of my layout.js that fixes it for two levels:
Code: Select all
restoreMenuState: function() {
var $this = this;
if (!this.isSlim() && !this.wrapper.hasClass('menu-layout-horizontal')) {
var linkList = this.menu.find('a[href^="' + this.cfg.pathname + '"]');
if (linkList.length) {
let urlParams = window.location.search;
linkList.each(function(_i, linkItem) {
let setActive = true;
let link = $(linkItem);
let href = link.attr('href');
if (href.includes('?')) {
let hrefParams = href.substring(href.lastIndexOf('?'));
if (urlParams !== hrefParams) {
setActive = false;
}
}
if (setActive) {
let menuitem = link.closest('li');
menuitem.addClass('active-menuitem');
let parentmenu = menuitem.parent('ul');
if (parentmenu.length) {
parentmenu.slideDown();
parentmenu.parent('li').addClass('active-menuitem');
// auto-active also for second level menu (s4p)
let grandParentMenu = parentmenu.parent('li').parent('ul');
if (grandParentMenu.length) {
grandParentMenu.slideDown();
grandParentMenu.parent('li').addClass('active-menuitem');
}
}
setTimeout(function() {
$this.restoreScrollState(menuitem);
}, 100)
}
});
}
}
var inlineProfileCookie = $.cookie('avalon_inlineprofile_expanded');
if (inlineProfileCookie) {
this.profileMenu.show().prev('.profile').addClass('profile-expanded');
}
},