Re: Dynamic submenu width

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

#1716
admin
Keymaster

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.

Register

You will be emailed a link to set your password.

Login

Lost password?