Ultima 3.0.0 -> Highlight menu programmatically

Forum rules
Please note that response time for technical support is within 3-5 business days.
Post Reply
spadovan
Posts: 178
Joined: 05 Jun 2013, 12:04

13 Aug 2021, 11:09

Using Ultima 2.1.1 i was able to highlight menu item programmatically
I mean highlight a specific menu item when i enter directly an url to my application.
I was using this code (suggested from aragorn) which no longer works with Ultima 3.0.0 and PF X:

Code: Select all

$(document).ready(function () {
	var $this = PF('sidebar-menu');
	if ($this) {
		var pathname = window.location.pathname;
		$this.expandedMenuitems = [];
		$this.clearMenuState();
		if (pathname.indexOf('.xhtml') > 0) {
			var activeLink = $this.menulinks.filter('[href^="' + pathname + '"]');
			var item = activeLink.parent('li');
			var menuId = item.attr('id');
			if (jQuery.inArray(menuId, $this.expandedMenuitems) !== 0) {
				$this.addMenuitem(menuId);
				addParentItems($this, item);
			}
		}
		trackmenu();
	}
});
function addParentItems($this, item) {
	if (item && item.length) {
		var parent = item.parents('li:first');
		$this.addMenuitem(parent.attr('id'));
		if (!parent.parent('ul').hasClass('ultima-menu')) {
			addParentItems($this, parent);
		} else {
			return;
		}
	}
	return;
}

Could you please suggest a fix ?

Thanks
Primefaces 12.0.2, Wildfly 24.0.1, JDK 11

siris
Posts: 322
Joined: 29 Jul 2019, 13:57

16 Aug 2021, 07:13

Hi,

Could you please write what error you are getting in the browser console? This way I will be able to fix your code.

Best Regards,

spadovan
Posts: 178
Joined: 05 Jun 2013, 12:04

16 Aug 2021, 07:52

Hi,

i have no javascript error, but the menu item doens't get activated.
thanks a lot
Primefaces 12.0.2, Wildfly 24.0.1, JDK 11

siris
Posts: 322
Joined: 29 Jul 2019, 13:57

16 Aug 2021, 09:04

Hi,

Please use this new code :)

Code: Select all

$(function() {
    var $this = PF('me');
    $this.clearLayoutState();
    var link = $this.menu.find('a[href^="' + $this.cfg.pathname + '"]');
    if (link.length && !$this.isHorizontal && !$this.isSlim) {
        var menuitem = link.closest('li');
        menuitem.addClass('active-menuitem');
        menuitem.parents('li').add(this).each(function() {
            $(this).addClass('active-menuitem');
            var submenu = $(this).children('ul');
            if(submenu.length) {
                submenu.show();
            }
        });
    }
});
Best Regards,

spadovan
Posts: 178
Joined: 05 Jun 2013, 12:04

16 Aug 2021, 09:24

Thanks Siris, it works perfectly !
I only had to remove "&& !$this.isHorizontal && !$this.isSlim" from the code.
Primefaces 12.0.2, Wildfly 24.0.1, JDK 11

siris
Posts: 322
Joined: 29 Jul 2019, 13:57

16 Aug 2021, 09:46

You are welcome!

Best Regards,

Post Reply

Return to “Ultima - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests