Re: Changing the Collapse Behavior of Submenus in Bootstrap

Home Forums Older releases 0.9.x Changing the Collapse Behavior of Submenus in Bootstrap Re: Changing the Collapse Behavior of Submenus in Bootstrap

#1815
admin
Keymaster

Hi,

If you are using the Bootstrap add-on (which I guess is the case), you will need to modify the “jquery.smartmenus.bootstrap.js” file. Just find the following:

// click the parent item to toggle the sub menus (and reset deeper levels and other branches on click)
'click.smapi': function(e, item) {
	var obj = $(this).data('smartmenus');
	if (obj.isCollapsible()) {
		var $item = $(item),
			$sub = $item.parent().dataSM('sub');
		if ($sub && $sub.dataSM('shown-before') && $sub.is(':visible')) {
			obj.itemActivate($item);
			obj.menuHide($sub);
			return false;
		}
	}
}

and replace it with the following:

// click the parent item to toggle the sub menus
'click.smapi': function(e, item) {
	var obj = $(this).data('smartmenus');
	if (obj.isCollapsible()) {
		window._lastClickedItem = item;
		var $sub = $(item).parent().dataSM('sub');
		if ($sub && $sub.dataSM('shown-before') && $sub.is(':visible')) {
			obj.menuHide($sub);
			return false;
		}
	}
},
'beforehide.smapi': function(e, menu) {
	if (window._lastClickedItem && window._lastClickedItem != $(menu).dataSM('parent-a')[0]) {
		return false;
	}
}

This will make sure sub menus are only toggled when their parent item is clicked (i.e. the menu will not function like an accordion any more).

Please let me know if you still have any questions.

Cheers!

Register

You will be emailed a link to set your password.

Login

Lost password?