MenuItem

Locked
peve
Posts: 4
Joined: 21 May 2015, 22:01

01 Sep 2017, 14:30

Hi,

Is there a way to control what <p:menuitem> is selected, appart from clicking on it?
When a item is selected i see there are 2 classes added to my <a href> "active-menu" and "active-menu-restore added" but is there some attribute I can add to my <p:menuitem> to make it selected?

Code: Select all

<pr:menu>
		<p:submenu id="rm_errand_tl" label="Ärende" icon="fa fa-briefcase">
			<p:menuitem id="rm_errand_overview" value="Översikt"   icon="fa fa-list"       outcome="/errand-list" />
			<p:menuitem id="rm_errand_new"      value="Skapa nytt" icon="fa icon-file-add" outcome="/errand-create" />
		</p:submenu>

		<p:menuitem id="rm_address"         		value="Adress"     	icon="fa icon-mail"      		outcome="/address"	rendered="#{menuView.isErrandSelected}" />
		<p:menuitem id="rm_general_meeting" 	value="Övrigt" 	icon="fa fa-newspaper-o" 	outcome="/nan" 		rendered="#{menuView.isErrandSelected}" />
</pr:menu>

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

13 Sep 2017, 08:59

When a item is selected i see there are 2 classes added to my <a href> "active-menu" and "active-menu-restore added" but is there some attribute I can add to my <p:menuitem> to make it selected?
- Unfortunately, no. We use $.cookie for menu stateful feature. You can add item that you want to make active into cookie using addMenuitem method. Please see in layout.js;

Code: Select all

...

removeMenuitem: function(id) {        
        this.expandedMenuitems = $.grep(this.expandedMenuitems, function(value) {
            return value !== id;
        });
    },
    
    addMenuitem: function(id) {
        if($.inArray(id, this.expandedMenuitems) === -1) {
            this.expandedMenuitems.push(id);
        }
    },
    
    saveMenuState: function() {
        $.cookie('ronin_expandeditems', this.expandedMenuitems.join(','), {path:'/'});
    },
    
    clearMenuState: function() {
        $.removeCookie('ronin_expandeditems', {path:'/'});
    },
    
    restoreMenuState: function() {
        var menucookie = $.cookie('ronin_expandeditems');
        if(menucookie) {
            this.expandedMenuitems = menucookie.split(',');
            for(var i = 0; i < this.expandedMenuitems.length; i++) {
                var id = this.expandedMenuitems[i];
                if(id) {
                    var menuitem = $("#" + this.expandedMenuitems[i].replace(/:/g,"\\:"));
                    menuitem.addClass('active-menu-parent');
                    menuitem.children('a,ul').addClass('active-menu active-menu-restore');
                }             
            }
        }
    }

Locked

Return to “Ronin”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest