function init_menu( container, context )
{
context = context || document.body;
$( container, context ).each(
function ()
{
var opts = jQuery.attrOptions( this , "dropmenu" );
new Menu( this, opts );
}
);
}
function docs_menu()
{
var a = "Dynamic cascading menu item. Notes: ULs and LIs margin values are set to 0. LIs get display: block.";
var e = [
['
',
"Vertical menu"],
['',
"Horizontal menu"]
];
var c = [];
var o =
[[ "width", 130, "Width of menu elements" ]
,[ "orientation", 'down', "If the first menus should go down instead of right [down,right]" ]
,[ "timeout", 200, "Milliseconds until the menu disappears after mouseout" ]
];
return { 'examples': e, 'about': a, 'opts': o, 'classes': c };
}
function opts_menu( o )
{
return apply_options( docs_menu().opts, o );
}
function Menu( container, opts )
{
opts = opts_menu( opts );
this.container = container;
this.opts = opts;
this.zindex = 10;
this.timeout_lis = [];
$( container ).css("margin-top","0px");
var lis = $( "li" , container );
var self = this;
lis.each(
function ()
{
self.li( this );
}
);
}
Menu.prototype.li_show = function ( li, liuls )
{
for ( var i = 0; i < this.timeout_lis.length; i++ )
{
this.li_hide_now( this.timeout_lis[i] );
}
this.timeout_lis = [];
li.timeout_hide && clearTimeout( li.timeout_hide );
$( "> ul > li", li ).css({
"display": "block",
"margin": "0px"
});
$( li ).addClass( 'menu_selected' );
if ( !li.positioned )
{
var siz = jQuery.getSize( li );
if ( li.parentNode.style.position == "absolute" )
{
var l = siz.w;
var t = 0;
}
else
{
var pos = jQuery.getPosition( li, true );
if ( this.opts.orientation == 'down' )
{
var l = pos.x;
var t = pos.y + siz.h;
}
else
{
var w = this.opts.width || siz.w;
var l = pos.x + w;
var t = pos.y;
}
}
liuls.css({
"display": "block",
"margin": "0px",
"position": "absolute",
"width" : this.opts.width + "px",
"left": l + "px",
"top": t + "px",
"z-index": (this.zindex += 10)
});
li.positioned = true;
}
liuls.css( "display", "block" );
}
Menu.prototype.li_hide_now = function ( li )
{
$( li ).removeClass( "menu_selected" );
$( "> ul" , li ).hide();
}
Menu.prototype.li_hide = function ( li )
{
$( li ).removeClass( "menu_selected" );
this.timeout_lis.push( li );
var self = this;
li.timeout_hide = setTimeout( function ()
{
self.li_hide_now( li );
},
this.opts.timeout
);
}
Menu.prototype.li = function ( li )
{
var liuls = $( "> ul" , li );
liuls.css("display","none");
var self = this;
$( li ).hover(
function ()
{
self.li_show( this, liuls );
},
function ()
{
self.li_hide( this );
}
);
}