/* * @Class: DropDownMenu * * @Description: A dropdown navigation menu with sliding animation. * * @Usage: var dd = new DropDownMenu(list of dropdown elements, overall parent element with CSS class parameters); * * @Methods: no public methods * */ DropDownMenu = (!detectBrowser.modernBrowser())?function(){}:Class.create(); DropDownMenu.prototype = (!detectBrowser.modernBrowser())?{}:{ dropDownDisabledCheck: function(){ if(window['dropDownMenusDisabled']==true){ this.springloaderDelay = 1; this.downDelay = 1; this.upDelay = 1; this.hoverOutDelay = 1; } else { this.downDelay = 570; this.upDelay = 450; this.springloaderDelay = 200; this.hoverOutDelay = 250; } }, initialize: function(droppers,dropcontainer){ // TODO make these parametric from dropcontainer's CSS class this.downDelay = 570; this.upDelay = 450; this.springloaderDelay = 200; this.hoverOutDelay = 250; this.dropDownDisabledCheck(); // classname can be something like "dropper [otherstyle otherstyle otherstyle] INT INT INT .." this.dropperWidths = droppers.map(function(item){ return item.classNames().toString().split(" ").select(function(token){ return parseInt(token) > -1; })[0]; }); // calculate horizontal offset locations of each dropdown this.dropperOffsets = this.dropperWidths.inject([0],function(acc,item){ acc.push(acc[acc.length - 1] + parseInt(item)); return acc; }); // fetch header height from the container's CSS class names var headerHeight = dropcontainer.classNames().toString().split(" ").select(function(token){ return parseInt(token) > -1; })[0]; this.iframesEnabled = false; this.droppers = droppers; this.dropperiFrames = []; this.hoverStates = []; this.states = []; this.visibilityInitialized = []; // there exists a "next action" for every given dropdown. This way we can queue the next state // that a dropdown wants to go to if a dropdown is too busy animating while we interrupt it // with another target state. this.nextAction = []; // next actions are baskets in which a waiting action can drop in a closure to be executed after the current action for(var i=0;i 0; if(hasItems && this.iframesEnabled){ var zfixIFrame = new Element("iframe",{ 'id':'floatMessageIFrame', 'src':'javascr'+'ipt:\'\'' }); zfixIFrame.frameBorder=0; zfixIFrame.setStyle({ 'backgroundColor':'#2e2e2e', // #2e2e2e 'zIndex':795, 'position':'absolute' // 'height':'0px' }); var ul = $(lis[0].parentNode); ul.setStyle({ 'zIndex':805 }); zfixIFrame = dropper.appendChild(zfixIFrame); this.dropperiFrames[i] = zfixIFrame; // console.debug(this.dropperiFrames[i]); } // // Make two re-useable, cloneable handlers that fire when the mouse leaves or enters // either the dropper or the heading for each dropdown menu. // var mouseout = (function(dropdownDiv,dropperIndex,dropperHasItems){ return function(ev){ this.hoverStates[dropperIndex] = "out"; setTimeout(function(){ // if still hovering outside... go ahead and slide back up if(this.hoverStates[dropperIndex]=="out"){ if(this.states[dropperIndex]=="open"){ this.applyHoverClasses(dropdownDiv,"over","out"); // wrapper div this.applyHoverClasses(dropdownDiv.previous(),"over","out"); // heading this.doSlideUp(dropdownDiv,dropperIndex,dropperHasItems); } else if (this.states[dropperIndex]=="closing"){ // reject mouse-out, already closing } else { // reject mouse-out, but queue up the next action // fill nextAction basket with a close action this.nextAction[dropperIndex] = function(){ if(this.hoverStates[dropperIndex]=='out' && this.states[dropperIndex]=="open"){ this.applyHoverClasses(dropdownDiv,"over","out"); // wrapper div this.applyHoverClasses(dropdownDiv.previous(),"over","out"); // heading this.doSlideUp(dropdownDiv,dropperIndex,dropperHasItems); } }.bind(this); } } else if (this.hoverStates[dropperIndex]=="in"){ // reject a mouse-out, we're still hovering. } }.bind(this),this.hoverOutDelay); }.bind(this); }.bind(this))(dropper,i,hasItems); var mouseover = (function(dropdownDiv,dropperIndex,dropperHasItems){ var dropperHasBeenInitialized = false; return function(ev){ if(!dropperHasBeenInitialized){ // // Set styles and calculate dropper heights on-demand // dropdownDiv.getElementsBySelector("ul").each(function(item){ item.setStyle({'position':'absolute'}); }); if(dropperHasItems){ var lis = dropdownDiv.getElementsBySelector("li"); var totalHeight = 0; for(var l=0;l