jQuery Plugin: Single Drop Down Menu

March 24, 2009 | Demo | Docs | Download
Introduction

Single-ddm applies mouseover/mouseouts to a preformatted list, as well as a timer to stall the closing of a list. Metadata support is included, so each main list can have it's own special features without multiple function calls.

Basic Usage

While no parameters are required, it's recomended you add some mouse over CSS classes to the parent and child MO like so:

$(function(){
	$('#ddmenu').singleDropMenu({parentMO: 'ddmenu-hover', childMO: 'ddchildhover'})
});

which will give you the following affect:




Source
/*!
 * Single Drop Down Menu 1.2
 * September 26, 2009
 * Corey Hart @ http://www.codenothing.com
 */
;(function($, undefined){
	// bgiframe is needed to fix z-index problem for IE6 users.
	$.fn.bgiframe = $.fn.bgiframe ? $.fn.bgiframe : $.fn.bgIframe ? $.fn.bgIframe : function(){
		// For applications that don't have bgiframe plugin installed, create a useless 
		// function that doesn't break the chain
		return this;
	};

 	// Drop Menu Plugin
	$.fn.singleDropMenu = function(options){
		return this.each(function(){
			// Default Settings
			var $obj = $(this), timer, menu,
				settings = $.extend({
					timer: 500,
					parentMO: undefined,
					childMO: undefined,
					show: 'show',
					hide: 'hide'
				}, options||{}, $.metadata ? $obj.metadata() : {});
	
			// Run Menu
			$obj.children('li').bind('mouseover.single-ddm', function(){
				// Clear any open menus
				if (menu && menu.data('single-ddm-i') != $(this).data('single-ddm-i'))
					closemenu();
				else
					menu =false;
				
				// Open nested list
				$(this).children('a').addClass(settings.parentMO).siblings('ul')[settings.show]();
			}).bind('mouseout.single-ddm', function(){
				// Prevent auto close
				menu = $(this);
				timer = setTimeout(closemenu, settings.timer);
			}).each(function(i){
				// Attach indexs to each menu
				$(this).data('single-ddm-i', i);
			}).children('ul').bgiframe();

			// Dropped Menu Highlighting
			$('li > ul > li', $obj).bind('mouseover.single-ddm', function(){
				$('a', this).addClass(settings.childMO);
			}).bind('mouseout.single-ddm', function(){
				$('a', this).removeClass(settings.childMO);
			});
	
			// Closes any open menus when mouse click occurs anywhere else on the page
			$(document).click(closemenu);
	
			// Function to close set menu
			function closemenu(){
				if (menu && timer){
					menu.children('a').removeClass(settings.parentMO).siblings('ul')[settings.hide]();
					clearTimeout(timer);
					menu = false;
				}
			}
		});
	};
})(jQuery);

Download

Latest: single-ddm-1.2.zip
Released: September 26, 2009
-Added namespacing to events
-Allowed for personalized show/hide functions

Past Release's:
August 22, 2009: single-ddm-1.1.zip
March 24, 2009: single-ddm-1.0.2.zip