//** smooth navigational menu- by dynamic drive dhtml code library: http://www.dynamicdrive.com //** script download/ instructions page: http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/ //** menu created: nov 12, 2008 //** dec 12th, 08" (v1.01): fixed shadow issue when multiple lis within the same ul (level) contain sub menus: http://www.dynamicdrive.com/forums/showthread.php?t=39177&highlight=smooth //** feb 11th, 09" (v1.02): the currently active main menu item (li a) now gets a css class of ".selected", including sub menu items. //** may 1st, 09" (v1.3): //** 1) now supports vertical (side bar) menu mode- set "orientation" to 'v' //** 2) in ie6, shadows are now always disabled //** july 27th, 09" (v1.31): fixed bug so shadows can be disabled if desired. //** feb 2nd, 10" (v1.4): adds ability to specify delay before sub menus appear and disappear, respectively. see showhidedelay variable below //** dec 17th, 10" (v1.5): updated menu shadow to use css3 box shadows when the browser is ff3.5+, ie9+, opera9.5+, or safari3+/chrome. only .js file changed. var ddsmoothmenu={ //specify full url to down and right arrow images (23 is padding-right added to top level lis with drop downs): arrowimages: {down:['downarrowclass', menuimg_path+'images/down.gif', 0], right:['rightarrowclass', menuimg_path+'images/right.gif']}, transition: {overtime:300, outtime:300}, //duration of slide in/ out animation, in milliseconds shadow: {enable:false, offsetx:4, offsety:4}, //enable shadow? showhidedelay: {showdelay: 100, hidedelay: 200}, //set delay in milliseconds before sub menus appear and disappear, respectively ///////stop configuring beyond here/////////////////////////// detectwebkit: navigator.useragent.tolowercase().indexof("applewebkit")!=-1, //detect webkit browsers (safari, chrome etc) detectie6: document.all && !window.xmlhttprequest, css3support: window.msperformance || (!document.all && document.queryselector), //detect browsers that support css3 box shadows (ie9+ or ff3.5+, safari3+, chrome etc) getajaxmenu:function($, setting){ //function to fetch external page containing the panel divs var $menucontainer=$('#'+setting.contentsource[0]) //reference empty div on page that will hold menu $menucontainer.html("loading menu...") $.ajax({ url: setting.contentsource[1], //path to external menu file async: true, error:function(ajaxrequest){ $menucontainer.html('error fetching content. server response: '+ajaxrequest.responsetext) }, success:function(content){ $menucontainer.html(content) ddsmoothmenu.buildmenu($, setting) } }) }, buildmenu:function($, setting){ var smoothmenu=ddsmoothmenu var $mainmenu=$("#"+setting.mainmenuid+">ul") //reference main menu ul $mainmenu.parent().get(0).classname=setting.classname || "ddsmoothmenu" var $headers=$mainmenu.find("ul").parent() $headers.hover( function(e){ $(this).children('a:eq(0)').addclass('selected') }, function(e){ $(this).children('a:eq(0)').removeclass('selected') } ) $headers.each(function(i){ //loop through each li header var $curobj=$(this).css({zindex: 100-i}) //reference current li header var $subul=$(this).find('ul:eq(0)').css({display:'block'}) $subul.data('timers', {}) this._dimensions={w:this.offsetwidth, h:this.offsetheight, subulw:$subul.outerwidth(), subulh:$subul.outerheight()} this.istopheader=$curobj.parents("ul").length==1? true : false //is top level header? $subul.css({top:this.istopheader && setting.orientation!='v'? this._dimensions.h+5+"px" : 0}) $curobj.children("a:eq(0)").css(this.istopheader? {paddingright: smoothmenu.arrowimages.down[2]} : {}).append( //add arrow images //$curobj.find("span:eq(0)").css(this.istopheader? {paddingright: smoothmenu.arrowimages.down[2]} : {}).append( //add arrow images '' ) if (smoothmenu.shadow.enable && !smoothmenu.css3support){ //if shadows enabled and browser doesn't support css3 box shadows this._shadowoffset={x:(this.istopheader?$subul.offset().left+smoothmenu.shadow.offsetx : this._dimensions.w), y:(this.istopheader? $subul.offset().top+smoothmenu.shadow.offsety : $curobj.position().top)} //store this shadow's offsets if (this.istopheader) $parentshadow=$(document.body) else{ var $parentli=$curobj.parents("li:eq(0)") $parentshadow=$parentli.get(0).$shadow } this.$shadow=$('
').prependto($parentshadow).css({left:this._shadowoffset.x+'px', top:this._shadowoffset.y+'px'}) //insert shadow div and set it to parent node for the next shadow div } $curobj.hover( function(e){ var $targetul=$subul //reference ul to reveal var header=$curobj.get(0) //reference header li as dom object cleartimeout($targetul.data('timers').hidetimer) $targetul.data('timers').showtimer=settimeout(function(){ header._offsets={left:$curobj.offset().left, top:$curobj.offset().top} var menuleft=header.istopheader && setting.orientation!='v'? 0 : header._dimensions.w menuleft=(header._offsets.left+menuleft+header._dimensions.subulw>$(window).width())? (header.istopheader && setting.orientation!='v'? -header._dimensions.subulw+header._dimensions.w : -header._dimensions.w) : menuleft //calculate this sub menu's offsets from its parent if ($targetul.queue().length<=1){ //if 1 or less queued animations $targetul.css({left:menuleft+"px", width:header._dimensions.subulw+'px'}).animate({height:'show',opacity:'show'}, ddsmoothmenu.transition.overtime) if (smoothmenu.shadow.enable && !smoothmenu.css3support){ var shadowleft=header.istopheader? $targetul.offset().left+ddsmoothmenu.shadow.offsetx : menuleft var shadowtop=header.istopheader?$targetul.offset().top+smoothmenu.shadow.offsety : header._shadowoffset.y if (!header.istopheader && ddsmoothmenu.detectwebkit){ //in webkit browsers, restore shadow's opacity to full header.$shadow.css({opacity:1}) } header.$shadow.css({overflow:'', width:header._dimensions.subulw+'px', left:shadowleft+'px', top:shadowtop+'px'}).animate({height:header._dimensions.subulh+'px'}, ddsmoothmenu.transition.overtime) } } }, ddsmoothmenu.showhidedelay.showdelay) }, function(e){ var $targetul=$subul var header=$curobj.get(0) cleartimeout($targetul.data('timers').showtimer) $targetul.data('timers').hidetimer=settimeout(function(){ $targetul.animate({height:'hide', opacity:'hide'}, ddsmoothmenu.transition.outtime) if (smoothmenu.shadow.enable && !smoothmenu.css3support){ if (ddsmoothmenu.detectwebkit){ //in webkit browsers, set first child shadow's opacity to 0, as "overflow:hidden" doesn't work in them header.$shadow.children('div:eq(0)').css({opacity:0}) } header.$shadow.css({overflow:'hidden'}).animate({height:0}, ddsmoothmenu.transition.outtime) } }, ddsmoothmenu.showhidedelay.hidedelay) } ) //end hover }) //end $headers.each() if (smoothmenu.shadow.enable && smoothmenu.css3support){ //if shadows enabled and browser supports css3 shadows var $toplevelul=$('#'+setting.mainmenuid+' ul li ul') var css3shadow=parseint(smoothmenu.shadow.offsetx)+"px "+parseint(smoothmenu.shadow.offsety)+"px 5px #aaa" //construct css3 box-shadow value var shadowprop=["boxshadow", "mozboxshadow", "webkitboxshadow", "msboxshadow"] //possible vendor specific css3 shadow properties for (var i=0; i