//** 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. var menu={ //specify full url to down and right arrow images (23 is padding-right added to top level lis with drop downs): arrowimages: {down:['downarrowclass', 'down.gif', 23], right:['rightarrowclass', 'right.gif']}, transition: {overtime:300, outtime:300}, //duration of slide in/ out animation, in milliseconds shadow: {enable:false, offsetx:0, offsety:0}, ///////stop configuring beyond here/////////////////////////// detectwebkit: navigator.useragent.tolowercase().indexof("applewebkit")!=-1, //detect webkit browsers (safari, chrome etc) detectie6: document.all && !window.xmlhttprequest, 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) menu.buildmenu($, setting) } }) }, buildmenu:function($, setting){ var smoothmenu=menu var $mainmenu=$("#"+setting.mainmenuid+">ul") //reference main menu ul $mainmenu.parent().get(0).classname=setting.classname || "menu" 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'}) 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+"px" : 0}) /* $curobj.children("a:eq(0)").css(this.istopheader? {paddingright: smoothmenu.arrowimages.down[2]} : {}).append( //add arrow images '' ) */ if (smoothmenu.shadow.enable){ 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=$(this).children("ul:eq(0)") this._offsets={left:$(this).offset().left, top:$(this).offset().top} var menuleft=this.istopheader && setting.orientation!='v'? 0 : this._dimensions.w menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader && setting.orientation!='v'? -this._dimensions.subulw+this._dimensions.w : -this._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:this._dimensions.subulw+'px'}).animate({height:'show',opacity:'show'}, menu.transition.overtime) if (smoothmenu.shadow.enable){ var shadowleft=this.istopheader? $targetul.offset().left+menu.shadow.offsetx : menuleft var shadowtop=this.istopheader?$targetul.offset().top+smoothmenu.shadow.offsety : this._shadowoffset.y if (!this.istopheader && menu.detectwebkit){ //in webkit browsers, restore shadow's opacity to full this.$shadow.css({opacity:1}) } this.$shadow.css({overflow:'', width:this._dimensions.subulw+'px', left:shadowleft+'px', top:shadowtop+'px'}).animate({height:this._dimensions.subulh+'px'}, menu.transition.overtime) } } }, function(e){ var $targetul=$(this).children("ul:eq(0)") $targetul.animate({height:'hide', opacity:'hide'}, menu.transition.outtime) if (smoothmenu.shadow.enable){ if (menu.detectwebkit){ //in webkit browsers, set first child shadow's opacity to 0, as "overflow:hidden" doesn't work in them this.$shadow.children('div:eq(0)').css({opacity:0}) } this.$shadow.css({overflow:'hidden'}).animate({height:0}, menu.transition.outtime) } } ) //end hover }) //end $headers.each() $mainmenu.find("ul").css({display:'none', visibility:'visible'}) }, init:function(setting){ if (typeof setting.customtheme=="object" && setting.customtheme.length==2){ //override default menu colors (default/hover) with custom set? var mainmenuid='#'+setting.mainmenuid var mainselector=(setting.orientation=="v")? mainmenuid : mainmenuid+', '+mainmenuid document.write('') } this.shadow.enable=(document.all && !window.xmlhttprequest)? false : this.shadow.enable //in ie6, always disable shadow jquery(document).ready(function($){ //ajax menu? if (typeof setting.contentsource=="object"){ //if external ajax menu menu.getajaxmenu($, setting) } else{ //else if markup menu menu.buildmenu($, setting) } }) } } //end menu variable //initialize menu instance(s):