Start a new discussion

To start a new discussion please visit the discussions section of the GitHub home page of the project.

Discussions on GitHub

You can also search our old self-hosted forums for any useful information below but please note that posting new content here is not possible any more.

showOnClick doesn't hide submenu when clicked again

Home Forums Latest release 1.1.x showOnClick doesn't hide submenu when clicked again

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #8324
    dameer
    Participant

    hi,
    was wondering how come

    showOnClick: true

    option doesn’t allow closing the submenu when the same menu item is clicked second time? clicking elsewhere, however, does. am I missing some other setting?

    #8326
    admin
    Keymaster

    Hi, actually you are not missing anything. It’s currently really working like that by default. I will most probably change this in the next release. In the meantime, you could use the following tweak via the API to achieve what you need:

    // SmartMenus jQuery - a second click on a main menu item when "showOnClick: true" should hide the sub menu
    $('#main-menu').on('click.smapi', function(e, item) {
    	if (e.namespace == 'smapi') {
    		var obj = $(this).data('smartmenus');
    		if (!obj.isCollapsible() && obj.opts.showOnClick) {
    			var $sub = $(item).dataSM('sub'),
    				firstLevelSub = $sub ? $sub.dataSM('level') == 2 : false;
    			if (firstLevelSub && $sub.is(':visible')) {
    				obj.menuHide($sub);
    				obj.clickActivated = false;
    				return false;
    			}
    		}
    	}
    });

    Cheers!

    Edit: Just add this code after your SmartMenus init code.

    #8327
    dameer
    Participant

    Oho! Now the things work much better 😀 The only problem is the fact that the above code is OK for the level-1 sub-menu. In case there’s a sub-menu item which opens level-2 sub-menu, the second click will shut down all sub-menus been opened.

    Thanks for a great work and all of your efforts!

    #8328
    dameer
    Participant

    OK, got it resolved by replacing the line:

    firstLevelSub = $sub ? $sub.dataSM('level') == 2 : false;

    …with just:

    firstLevelSub = $sub ? $sub.dataSM('level') >= 2 : false;

    Cheers!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘1.1.x’ is closed to new topics and replies.