1//** All Levels Navigational Menu- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com 2//** Script Download/ instructions page: http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/ 3//** Usage Terms: http://www.dynamicdrive.com/notice.htm 4 5//** Current version: 2.2 See changelog.txt for details 6 7if (typeof dd_domreadycheck=="undefined") //global variable to detect if DOM is ready 8 var dd_domreadycheck=false 9 10var ddlevelsmenu={ 11 12enableshim: true, //enable IFRAME shim to prevent drop down menus from being hidden below SELECT or FLASH elements? (tip: disable if not in use, for efficiency) 13 14arrowpointers:{ 15 downarrow: ["images/arrow-down.gif", 11,7], //[path_to_down_arrow, arrowwidth, arrowheight] 16 rightarrow: ["images/arrow-right.gif", 12,12], //[path_to_right_arrow, arrowwidth, arrowheight] 17 showarrow: {toplevel: true, sublevel: true} //Show arrow images on top level items and sub level items, respectively? 18}, 19hideinterval: 200, //delay in milliseconds before entire menu disappears onmouseout. 20effects: {enableswipe: true, enablefade: true, duration: 200}, 21httpsiframesrc: "blank.htm", //If menu is run on a secure (https) page, the IFRAME shim feature used by the script should point to an *blank* page *within* the secure area to prevent an IE security prompt. Specify full URL to that page on your server (leave as is if not applicable). 22 23///No need to edit beyond here//////////////////// 24 25topmenuids: [], //array containing ids of all the primary menus on the page 26topitems: {}, //object array containing all top menu item links 27subuls: {}, //object array containing all ULs 28lastactivesubul: {}, //object object containing info for last mouse out menu item's UL 29topitemsindex: -1, 30ulindex: -1, 31hidetimers: {}, //object array timer 32shimadded: false, 33nonFF: !/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent), //detect non FF browsers 34getoffset:function(what, offsettype){ 35 return (what.offsetParent)? what[offsettype]+this.getoffset(what.offsetParent, offsettype) : what[offsettype] 36}, 37 38getoffsetof:function(el){ 39 el._offsets={left:this.getoffset(el, "offsetLeft"), top:this.getoffset(el, "offsetTop")} 40}, 41 42getwindowsize:function(){ 43 this.docwidth=window.innerWidth? window.innerWidth-10 : this.standardbody.clientWidth-10 44 this.docheight=window.innerHeight? window.innerHeight-15 : this.standardbody.clientHeight-18 45}, 46 47gettopitemsdimensions:function(){ 48 for (var m=0; m<this.topmenuids.length; m++){ 49 var topmenuid=this.topmenuids[m] 50 for (var i=0; i<this.topitems[topmenuid].length; i++){ 51 var header=this.topitems[topmenuid][i] 52 var submenu=document.getElementById(header.getAttribute('rel')) 53 header._dimensions={w:header.offsetWidth, h:header.offsetHeight, submenuw:submenu.offsetWidth, submenuh:submenu.offsetHeight} 54 } 55 } 56}, 57 58isContained:function(m, e){ 59 var e=window.event || e 60 var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement) 61 while (c && c!=m)try {c=c.parentNode} catch(e){c=m} 62 if (c==m) 63 return true 64 else 65 return false 66}, 67 68addpointer:function(target, imgclass, imginfo, BeforeorAfter){ 69 var pointer=document.createElement("img") 70 pointer.src=imginfo[0] 71 pointer.style.width=imginfo[1]+"px" 72 pointer.style.height=imginfo[2]+"px" 73 if(imgclass=="rightarrowpointer"){ 74 pointer.style.left=target.offsetWidth-imginfo[2]-2+"px" 75 } 76 pointer.className=imgclass 77 var target_firstEl=target.childNodes[target.firstChild.nodeType!=1? 1 : 0] //see if the first child element within A is a SPAN (found in sliding doors technique) 78 if (target_firstEl && target_firstEl.tagName=="SPAN"){ 79 target=target_firstEl //arrow should be added inside this SPAN instead if found 80 } 81 if (BeforeorAfter=="before") 82 target.insertBefore(pointer, target.firstChild) 83 else 84 target.appendChild(pointer) 85}, 86 87css:function(el, targetclass, action){ 88 var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig") 89 if (action=="check") 90 return needle.test(el.className) 91 else if (action=="remove") 92 el.className=el.className.replace(needle, "") 93 else if (action=="add" && !needle.test(el.className)) 94 el.className+=" "+targetclass 95}, 96 97addshimmy:function(target){ 98 var shim=(!window.opera)? document.createElement("iframe") : document.createElement("div") //Opera 9.24 doesnt seem to supp
98ort transparent IFRAMEs 99 shim.className="ddiframeshim" 100 shim.setAttribute("src", location.protocol=="https:"? this.httpsiframesrc : "about:blank") 101 shim.setAttribute("frameborder", "0") 102 target.appendChild(shim) 103 try{ 104 shim.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)' 105 } 106 catch(e){} 107 return shim 108}, 109 110positionshim:function(header, submenu, dir, scrollX, scrollY){ 111 if (header._istoplevel){ 112 var scrollY=window.pageYOffset? window.pageYOffset : this.standardbody.scrollTop 113 var topgap=header._offsets.top-scrollY 114 var bottomgap=scrollY+this.docheight-header._offsets.top-header._dimensions.h 115 if (topgap>0){ 116 this.shimmy.topshim.style.left=scrollX+"px" 117 this.shimmy.topshim.style.top=scrollY+"px" 118 this.shimmy.topshim.style.width="99%" 119 this.shimmy.topshim.style.height=topgap+"px" //distance from top window edge to top of menu item 120 } 121 if (bottomgap>0){ 122 this.shimmy.bottomshim.style.left=scrollX+"px" 123 this.shimmy.bottomshim.style.top=header._offsets.top + header._dimensions.h +"px" 124 this.shimmy.bottomshim.style.width="99%" 125 this.shimmy.bottomshim.style.height=bottomgap+"px" //distance from bottom of menu item to bottom window edge 126 } 127 } 128}, 129 130hideshim:function(){ 131 this.shimmy.topshim.style.width=this.shimmy.bottomshim.style.width=0 132 this.shimmy.topshim.style.height=this.shimmy.bottomshim.style.height=0 133}, 134 135 136buildmenu:function(mainmenuid, header, submenu, submenupos, istoplevel, dir){ 137 header._master=mainmenuid //Indicate which top menu this header is associated with 138 header._pos=submenupos //Indicate pos of sub menu this header is associated with 139 header._istoplevel=istoplevel 140 if (istoplevel){ 141 this.addEvent(header, function(e){ 142 ddlevelsmenu.hidemenu(ddlevelsmenu.subuls[this._master][parseInt(this._pos)]) 143 }, "click") 144 } 145 this.subuls[mainmenuid][submenupos]=submenu 146 header._dimensions={w:header.offsetWidth, h:header.offsetHeight, submenuw:submenu.offsetWidth, submenuh:submenu.offsetHeight} 147 this.getoffsetof(header) 148 submenu.style.left=0 149 submenu.style.top=0 150 submenu.style.visibility="hidden" 151 this.addEvent(header, function(e){ //mouseover event 152 if (!ddlevelsmenu.isContained(this, e)){ 153 var submenu=ddlevelsmenu.subuls[this._master][parseInt(this._pos)] 154 if (this._istoplevel){ 155 ddlevelsmenu.css(this, "selected", "add") 156 clearTimeout(ddlevelsmenu.hidetimers[this._master][this._pos]) 157 } 158 ddlevelsmenu.getoffsetof(header) 159 var scrollX=window.pageXOffset? window.pageXOffset : ddlevelsmenu.standardbody.scrollLeft 160 var scrollY=window.pageYOffset? window.pageYOffset : ddlevelsmenu.standardbody.scrollTop 161 var submenurightedge=this._offsets.left + this._dimensions.submenuw + (this._istoplevel && dir=="topbar"? 0 : this._dimensions.w) 162 var submenubottomedge=this._offsets.top + this._dimensions.submenuh 163 //Sub menu starting left position 164 var menuleft=(this._istoplevel? this._offsets.left + (dir=="sidebar"? this._dimensions.w : 0) : this._dimensions.w) 165 if (submenurightedge-scrollX>ddlevelsmenu.docwidth){ 166 menuleft+= -this._dimensions.submenuw + (this._istoplevel && dir=="topbar" ? this._dimensions.w : -this._dimensions.w) 167 } 168 submenu.style.left=menuleft+"px" 169 //Sub menu starting top position 170 var menutop=(this._istoplevel? this._offsets.top + (dir=="sidebar"? 0 : this._dimensions.h) : this.offsetTop) 171 if (submenubottomedge-scrollY>ddlevelsmenu.docheight){ //no room downwards? 172 if (this._dimensions.submenuh<this._offsets.top+(dir=="sidebar"? this._dimensions.h : 0)-scrollY){ //move up? 173 menutop+= - this._dimensions.submenuh + (this._istoplevel && dir=="topbar"? -this._dimensions.h : this._dimensions.h) 174 } 175 else{ //top of window edge 176 menutop+= -(this._offsets.top-scrollY) + (this._istoplevel && dir=="topbar"? -this._dimensions.h : 0) 177 } 178 } 179 submenu.style.top=menutop+"px" 180 if (ddlevelsmenu.enableshim && (ddlevelsmenu.effects.enableswipe==false || ddlevelsmenu.nonFF)){ //apply shim immediately only if animation is turned off, or if on, in non FF2.x browsers 181 ddlevelsmenu.positionshim(header, submenu, dir, scrollX, scrollY) 182 } 183 else{ 184 submenu.FFscrollInfo={x:scrollX, y:scrollY} 185 } 186 ddlevelsmenu.showmenu(header, submenu, dir) 187 } 188 }, "mouseover") 189 this.addEvent(header, function(e){ //mouseout event 190 var submenu=ddlevelsmenu.subuls[this._master][parseInt(this._pos)] 191 if (this._istoplevel){ 192 if (!ddlevelsmenu.isContained(this, e) && !ddlevelsmenu.isContained(submenu, e)) //hide drop down ul if mouse moves out of menu bar item but not into drop down ul itself 193 ddlevelsmenu.hidemenu(submenu) 194 } 195 else if (!this._istoplevel && !ddlevelsmenu.isContained(this, e)){ 196 ddlevelsmenu.hidemenu(submenu) 197 } 198 199 }, "mouseout") 200}, 201 202setopacity:function(el, value){ 203 el.style.opacity=value
204 if (typeof el.style.opacity!="string"){ //if it's not a string (ie: number instead), it means property not supported 205 el.style.MozOpacity=value 206 if (el.filters){ 207 el.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity="+ value*100 +")" 208 } 209 } 210}, 211 212showmenu:function(header, submenu, dir){ 213 if (this.effects.enableswipe || this.effects.enablefade){ 214 if (this.effects.enableswipe){ 215 var endpoint=(header._istoplevel && dir=="topbar")? header._dimensions.submenuh : header._dimensions.submenuw 216 submenu.style.width=submenu.style.height=0 217 submenu.style.overflow="hidden" 218 } 219 if (this.effects.enablefade){ 220 this.setopacity(submenu, 0) //set opacity to 0 so menu appears hidden initially 221 } 222 submenu._curanimatedegree=0 223 submenu.style.visibility="visible" 224 clearInterval(submenu._animatetimer) 225 submenu._starttime=new Date().getTime() //get time just before animation is run 226 submenu._animatetimer=setInterval(function(){ddlevelsmenu.revealmenu(header, submenu, endpoint, dir)}, 10) 227 } 228 else{ 229 submenu.style.visibility="visible" 230 } 231}, 232 233revealmenu:function(header, submenu, endpoint, dir){ 234 var elapsed=new Date().getTime()-submenu._starttime //get time animation has run 235 if (elapsed<this.effects.duration){ 236 if (this.effects.enableswipe){ 237 if (submenu._curanimatedegree==0){ //reset either width or height of sub menu to "auto" when animation begins 238 submenu.style[header._istoplevel && dir=="topbar"? "width" : "height"]="auto" 239 } 240 submenu.style[header._istoplevel && dir=="topbar"? "height" : "width"]=(submenu._curanimatedegree*endpoint)+"px" 241 } 242 if (this.effects.enablefade){ 243 this.setopacity(submenu, submenu._curanimatedegree) 244 } 245 } 246 else{ 247 clearInterval(submenu._animatetimer) 248 if (this.effects.enableswipe){ 249 submenu.style.width="auto" 250 submenu.style.height="auto" 251 submenu.style.overflow="visible" 252 } 253 if (this.effects.enablefade){ 254 this.setopacity(submenu, 1) 255 submenu.style.filter="" 256 } 257 if (this.enableshim && submenu.FFscrollInfo) //if this is FF browser (meaning shim hasn't been applied yet 258 this.positionshim(header, submenu, dir, submenu.FFscrollInfo.x, submenu.FFscrollInfo.y) 259 } 260 submenu._curanimatedegree=(1-Math.cos((elapsed/this.effects.duration)*Math.PI)) / 2 261}, 262 263hidemenu:function(submenu){ 264 if (typeof submenu._pos!="undefined"){ //if submenu is outermost UL drop down menu 265 this.css(this.topitems[submenu._master][parseInt(submenu._pos)], "selected", "remove") 266 if (this.enableshim) 267 this.hideshim() 268 } 269 clearInterval(submenu._animatetimer) 270 submenu.style.left=0 271 submenu.style.top="-1000px" 272 submenu.style.visibility="hidden" 273}, 274 275 276addEvent:function(target, functionref, tasktype) { 277 if (target.addEventListener) 278 target.addEventListener(tasktype, functionref, false); 279 else if (target.attachEvent) 280 target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)}); 281}, 282 283domready:function(functionref){ //based on code from the jQuery library 284 if (dd_domreadycheck){ 285 functionref() 286 return 287 } 288 // Mozilla, Opera and webkit nightlies currently support this event 289 if (document.addEventListener) { 290 // Use the handy event callback 291 document.addEventListener("DOMContentLoaded", function(){ 292 document.removeEventListener("DOMContentLoaded", arguments.callee, false ) 293 functionref(); 294 dd_domreadycheck=true 295 }, false ) 296 } 297 else if (document.attachEvent){ 298 // If IE and not an iframe 299 // continually check to see if the document is ready 300 if ( document.documentElement.doScroll && window == window.top) (function(){ 301 if (dd_domreadycheck){ 302 functionref() 303 return 304 } 305 try{ 306 // If IE is used, use the trick by Diego Perini 307 // http://javascript.nwbox.com/IEContentLoaded/ 308 document.documentElement.doScroll("left") 309 }catch(error){ 310 setTimeout( arguments.callee, 0) 311 return; 312 } 313 //and execute any waiting functions 314 functionref(); 315 dd_domreadycheck=true 316 })(); 317 } 318 if (document.attachEvent && parent.length>0) //account for page being in IFRAME, in which above doesn't fire in IE 319 this.addEvent(window, function(){functionref()}, "load"); 320}, 321 322 323init:function(mainmenuid, dir){ 324 this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body 325 this.topitemsindex=-1 326 this.ulindex=-1 327 this.topmenuids.push(mainmenuid) 328 this.topitems[mainmenuid]=[] //declare array on object 329 this.subuls[mainmenuid]=[] //declare array on object 330 this.hidetimers[mainmenuid]=[] //declare hide entire menu timer 331 if (this.enableshim && !this.shimadded){ 332 this.shimmy={} 333 this.shimmy.topshim=this.addshimmy(document.body) //create top iframe shim obj 334 this.shimmy.bottomshim=this.addshimmy(document.body) //create bottom iframe shim obj 335 this.shimadded=true 336 } 337 var menubar=document.getElementById(mainmenuid) 338 var alllinks=menubar.getElementsByTagName("a") 339 this.getwindowsize() 340 for (var i=0; i<alllinks.length; i++){ 341 if (alllinks[i].getAttribute('rel')){ 342 this.topitemsindex++ 343 this.ulindex++ 344 var menuitem=alllinks[i] 345 this.topitems[mainmenuid][this.topitemsindex]=menuitem //store ref to main menu links 346 var dropul=document.getElementById(menuitem.getAttribute('rel')) 347 document.body.appendChild(dropul) //move main ULs to end of document 348 dropul.style.zIndex=2000 //give drop down menus a high z-index 349 dropul._master=mainmenuid //Indicate which main menu this main UL is associated with 350 dropul._pos=this.topitemsindex //Indicate which main menu item this main UL is associated with 351 this.addEvent(dropul, function(){ddlevelsmenu.hidemenu(this)}, "click") 352 var arrowclass=(dir=="sidebar")? "rightarrowpointer" : "downarrowpointer" 353 var arrowpointer=(dir=="sidebar")? this.arrowpointers.rightarrow : this.arrowpointers.downarrow 354 if (this.arrowpointers.showarrow.toplevel) 355 this.addpointer(menuitem, arrowclass, arrowpointer, (dir=="sidebar")? "before" : "after") 356 this.buildmenu(mainmenuid, menuitem, dropul, this.ulindex, true, dir) //build top level menu 357 dropul.onmouseover=function(){ 358 clearTimeout(ddlevelsmenu.hidetimers[this._master][this._pos]) 359 } 360 this.addEvent(dropul, function(e){ //hide menu if mouse moves out of main UL element into open space 361 if (!ddlevelsmenu.isContained(this, e) && !ddlevelsmenu.isContained(ddlevelsmenu.topitems[this._master][parseInt(this._pos)], e)){ 362 var dropul=this 363 if (ddlevelsmenu.enableshim) 364 ddlevelsmenu.hideshim() 365 ddlevelsmenu.hidetimers[this._master][this._pos]=setTimeout(function(){ 366 ddlevelsmenu.hidemenu(dropul) 367 }, ddlevelsmenu.hideinterval) 368 } 369 }, "mouseout") 370 var subuls=dropul.getElementsByTagName("ul") 371 for (var c=0; c<subuls.length; c++){ 372 this.ulindex++ 373 var parentli=subuls[c].parentNode 374 if (this.arrowpointers.showarrow.sublevel) 375 this.addpointer(parentli.getElementsByTagName("a")[0], "rightarrowpointer", this.arrowpointers.rightarrow, "before") 376 this.buildmenu(mainmenuid, parentli, subuls[c], this.ulindex, false, dir) //build sub level menus 377 } 378 } 379 } //end for loop 380 this.addEvent(window, function(){ddlevelsmenu.getwindowsize(); ddlevelsmenu.gettopitemsdimensions()}, "resize") 381}, 382 383setup:function(mainmenuid, dir){ 384 this.domready(function(){ddlevelsmenu.init(mainmenuid, dir)}) 385} 386 387}
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.