03/08/2009 Development / java script

MacMenu = function(container)
{
UL = $('<ul>');
this.setItem = function(refMenu, subMenu, titulo, href){
if(subMenu == ''){
LI = $('<li>');
LI.append(LI.text(titulo));
UL.append(LI);
_UL = $('<ul>').attr("id", refMenu);
LI.append(_UL);
return false;
}
_LI = $('<li>');
_LI.append(_LI.text(titulo));
_UL.append(_LI);
}
$("#"+container).append(UL);}
$(document).ready(function(){
$('#menu li').hover(function() { $('ul', this).css('display', 'block'); },function() { $('ul', this).css('display', 'none'); });
});

// Pra usar
var menu = new MacMenu('menu');
menu.setItem('root1','','Menu','link');
menu.setItem('root1.1','root1','Sub1','link');
menu.setItem('root1.2','root1','Sub2','link');
menu.setItem('root1.3','root1','Sub3','link');
menu.setItem('root2','','Menu2','link');
menu.setItem('root2.1','root2','Sub1','link');
menu.setItem('root2.2','root2','Sub1.1','link');
menu.setItem('root2.3','root3','Sub3','link');
menu.setItem('root3','','Menu3','link');
menu.setItem('root3.1','root3','Sub1','link');
menu.setItem('root3.2','root3','Sub2','link');
menu.setItem('root3.3','root3','Sub3','link');


// CSS
#menu ul{
list-style:none;
margin: 0px;
padding: 0;
display: block;
}

#menu li{
background: #99cc66;
border-bottom: 1px solid white;
color: white;
padding: 0px;
width: 150px;
display: block;
text-align: right;
font-family: Arial;
font-size: 11px;
float: left
}

#menu li ul{
text-decoration: none;
color: white;
display: none;
padding: 0px;
}