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.

Re: Dynamic submenu width

Home Forums Older releases 0.9.x Dynamic submenu width Re: Dynamic submenu width


It’s not completely clear how exactly you would like it to function from your question so I’ve done what I suspect you need. The following mod will make sure your first level sub menus get the width of their respective parent menu item:

$('#main-menu').bind('beforeshow.smapi', function(e, menu) {
	var $menu = $(menu),
		obj = $(this).data('smartmenus');
	// save default subMenusMinWidth and subMenusMaxWidth options
	if (typeof obj.opts._subMenusMinWidth == 'undefined') {
		obj.opts._subMenusMinWidth = obj.opts.subMenusMinWidth;
		obj.opts._subMenusMaxWidth = obj.opts.subMenusMaxWidth;
	// if this is a first level sub menu
	if ($menu.dataSM('level') == 2) {
		$menu.css('width', obj.getWidth($menu.dataSM('parent-a')));
		// unset subMenusMinWidth and subMenusMaxWidth options so that the script doesn't override our custom width for this sub
		obj.opts.subMenusMinWidth = '';
		obj.opts.subMenusMaxWidth = '';
	} else {
		// restore subMenusMinWidth and subMenusMaxWidth options for deeper sub menu levels
		obj.opts.subMenusMinWidth = obj.opts._subMenusMinWidth;
		obj.opts.subMenusMaxWidth = obj.opts._subMenusMaxWidth;

For 2+ level sub menus, the subMenusMinWidth and subMenusMaxWidth options will be respected like normally.