PageSourceSearch

https://nmsuk.org/templates/nmsuk/js/ddsmoothmenu.js

js nmsuk.org collected 2026-10-07 13:17:32 UTC 6,482 bytes, 133 lines download raw bytes

1//** Smooth Navigational Menu- By Dynamic Drive DHTML code library: http://www.dynamicdrive.com
2//** Script Download/ instructions page: http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/
3//** Menu created: Nov 12, 2008
4
5//** 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
6
7//** Feb 11th, 09" (v1.02): The currently active main menu item (LI A) now gets a CSS class of ".selected", including sub menu items.
8
9var ddsmoothmenu={
10
11//Specify full URL to down and right arrow images (23 is padding-right added to top level LIs with drop downs):
12arrowimages: {down:['downarrowclass', 'images/spacer.gif', 0], right:['rightarrowclass', 'abh_dropmenu/right.gif']},
13
14transition: {overtime:250, outtime:250}, //duration of slide in/ out animation, in milliseconds
15shadow: {enabled:false, offsetx:5, offsety:5},
16
17///////Stop configuring beyond here///////////////////////////
18
19detectwebkit: navigator.userAgent.toLowerCase().indexOf("applewebkit")!=-1, //detect WebKit browsers (Safari, Chrome etc)
20
21getajaxmenu:function($, setting){ //function to fetch external page containing the panel DIVs
22	var $menucontainer=$('#'+setting.contentsource[0]) //reference empty div on page that will hold menu
23	$menucontainer.html("Loading Menu...")
24	$.ajax({
25		url: setting.contentsource[1], //path to external menu file
26		async: true,
27		error:function(ajaxrequest){
28			$menucontainer.html('Error fetching content. Server Response: '+ajaxrequest.responseText)
29		},
30		success:function(content){
31			$menucontainer.html(content)
32			ddsmoothmenu.buildmenu($, setting)
33		}
34	})
35},
36
37buildshadow:function($, $subul){
38	
39},
40
41buildmenu:function($, setting){
42	var smoothmenu=ddsmoothmenu
43	var $mainmenu=$("#"+setting.mainmenuid+">ul") //reference main menu UL
44	var $headers=$mainmenu.find("ul").parent()
45	$headers.hover(
46		function(e){
47			$(this).children('a:eq(0)').addClass('selected')
48		},
49		function(e){
50			$(this).children('a:eq(0)').removeClass('selected')
51		}
52	)
53	$headers.each(function(i){
54		var $curobj=$(this).css({zIndex: 40-i}) //reference current LI header
55		var $subul=$(this).find('ul:eq(0)').css({display:'block'})
56		this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
57		this.istopheader=$curobj.parents("ul").length==1? true : false //is top level header?
58		$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
59		$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: smoothmenu.arrowimages.down[2]} : {}).append( //add arrow images
60			'<img src="'+ (this.istopheader? smoothmenu.arrowimages.down[1] : smoothmenu.arrowimages.right[1])
61			+'" class="' + (this.istopheader? smoothmenu.arrowimages.down[0] : smoothmenu.arrowimages.right[0])
62			+ '" style="border:0;" />'
63		)
64		if (smoothmenu.shadow.enabled){
65			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
66			if (this.istopheader)
67				$parentshadow=$(document.body)
68			else{
69				var $parentLi=$curobj.parents("li:eq(0)")
70				$parentshadow=$parentLi.get(0).$shadow
71			}
72			this.$shadow=$('<div class="ddshadow'+(this.istopheader? ' toplevelshadow' : '')+'"></div>').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
73		}
74		$curobj.hover(
75			function(e){
76				var $targetul=$(this).children("ul:eq(0)")
77				this._offsets={left:$(this).offset().left, top:$(this).offset().top}
78				var menuleft=this.istopheader? 0 : this._dimensions.w
79				menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft //calculate this sub menu's offsets from its parent
80				if ($targetul.queue().length<=1){ //if 1 or less queued animations
81					$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).animate({height:'show',opacity:'show'}
81, ddsmoothmenu.transition.overtime)
82					if (smoothmenu.shadow.enabled){
83						var shadowleft=this.istopheader? $targetul.offset().left+ddsmoothmenu.shadow.offsetx : menuleft
84						var shadowtop=this.istopheader?$targetul.offset().top+smoothmenu.shadow.offsety : this._shadowoffset.y
85						if (!this.istopheader && ddsmoothmenu.detectwebkit){ //in WebKit browsers, restore shadow's opacity to full
86							this.$shadow.css({opacity:1})
87						}
88						this.$shadow.css({overflow:'', width:this._dimensions.subulw+'px', left:shadowleft+'px', top:shadowtop+'px'}).animate({height:this._dimensions.subulh+'px'}, ddsmoothmenu.transition.overtime)
89					}
90				}
91			},
92			function(e){
93				var $targetul=$(this).children("ul:eq(0)")
94				$targetul.animate({height:'hide', opacity:'hide'}, ddsmoothmenu.transition.outtime)
95				if (smoothmenu.shadow.enabled){
96					if (ddsmoothmenu.detectwebkit){ //in WebKit browsers, set first child shadow's opacity to 0, as "overflow:hidden" doesn't work in them
97						this.$shadow.children('div:eq(0)').css({opacity:0})
98					}
99					this.$shadow.css({overflow:'hidden'}).animate({height:0}, ddsmoothmenu.transition.outtime)
100				}
101			}
102		) //end hover
103	}) //end $headers.each()
104	$mainmenu.find("ul").css({display:'none', visibility:'visible'})
105},
106
107init:function(setting){
108	if (typeof setting.customtheme=="object" && setting.customtheme.length==2){
109		var mainmenuid='#'+setting.mainmenuid
110		document.write('<style type="text/css">\n'
111			+mainmenuid+', '+mainmenuid+' ul li a {background:'+setting.customtheme[0]+';}\n'
112			+mainmenuid+' ul li a:hover {background:'+setting.customtheme[1]+';}\n'
113		+'</style>')
114	}
115	jQuery(document).ready(function($){ //override default menu colors (default/hover) with custom set?
116		if (typeof setting.contentsource=="object"){ //if external ajax menu
117			ddsmoothmenu.getajaxmenu($, setting)
118		}
119		else{ //else if markup menu
120			ddsmoothmenu.buildmenu($, setting)
121		}
122	})
123}
124
125} //end ddsmoothmenu variable
126
127//Initialize Menu instance(s):
128
129ddsmoothmenu.init({
130	mainmenuid: "smoothmenu1", //menu DIV id
131	//customtheme: ["#1c5a80", "#18374a"], //override default menu CSS background values? Uncomment: ["normal_background", "hover_background"]
132	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
133})

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.