node-menunav-min.js revision dcc27ab1cda56d7ad286e36c57f451db77894301
YUI.add("node-menunav",function(D){var j=D.UA,q=D.later,AG=D.ClassNameManager.getClassName,Q="menu",G="menuitem",AC="hidden",R="parentNode",U="children",u="offsetHeight",x="offsetWidth",AI="px",e="id",I=".",E="handledMouseOut",o="handledMouseOver",Z="active",AE="label",b="a",t="mousedown",AJ="keydown",w="click",P="",T="first-of-type",AK="role",M="presentation",y="descendants",g="UI",r="activeDescendant",AH=">.yui-menu-content>ul>li>a",N=">.yui-menu-content>ul>li>.yui-menu-label>a:first-child",s="autoSubmenuDisplay",S="mouseOutHideDelay",i=AG(Q),AA=AG(Q,AC),X=AG(Q,"horizontal"),AD=AG(Q,AE),h=AG(Q,AE,Z),W=AG(Q,AE,(Q+"visible")),J=AG(G),A=AG(G,Z),f=I+i,AB=(I+AG(Q,"toggle"));var K=function(AN){var AP=AN.previous(),AM,AO,AL,Y;if(!AP){AM=AN.get(R);AL=AM.get(R).get(U);if(AL.size()>1){Y=AM.previous();if(Y){AO=Y.get(U);}else{AO=AL.item(AL.size()-1).get(U);}}else{AO=AM.get(U);}AP=AO.item(AO.size()-1);}return AP;};var a=function(AN){var AP=AN.next(),AM,AO,AL,Y;if(!AP){AM=AN.get(R);AL=AM.get(R).get(U);if(AL.size()>1){Y=AM.next();if(Y){AO=Y.get(U);}else{AO=AL.item(0).get(U);}}else{AO=AN.get(R).get(U);}AP=AO.item(0);}return AP;};var F=function(Y){var AL=false;if(Y){AL=Y.get("nodeName").toLowerCase()===b;}return AL;};var O=function(Y){return Y.hasClass(J);};var p=function(Y){return Y.hasClass(AD);};var n=function(Y){return Y.hasClass(X);};var k=function(Y){return Y.hasClass(W);};var m=function(Y){return F(Y)?Y:Y.query(b);};var v=function(AM,AL,Y){var AN;if(AM){if(AM.hasClass(AL)){AN=AM;}if(!AN&&Y){AN=AM.ancestor((I+AL));}}return AN;};var L=function(Y){return Y.ancestor(f);};var V=function(AL,Y){return v(AL,i,Y);};var z=function(AL,Y){var AM;if(AL){AM=v(AL,J,Y);}return AM;};var l=function(AL,Y){var AM;if(AL){if(Y){AM=v(AL,AD,Y);}else{AM=v(AL,AD)||AL.query((I+AD));}}return AM;};var B=function(AL,Y){var AM;if(AL){AM=z(AL,Y)||l(AL,Y);}return AM;};var C=function(Y){return B(Y.query("li"));};var d=function(Y){return O(Y)?A:h;};var c=function(Y,AL){return Y&&!Y[o]&&(Y===AL||Y.contains(AL));};var H=function(AL,Y){return AL&&!AL[E]&&(AL!==Y&&!AL.contains(Y));};var AF=function(){AF.superclass.constructor.apply(this,arguments);};AF.NAME="NodeMenuNav";AF.NS="menuNav";AF.SHIM_TEMPLATE_TITLE="Menu Stacking Shim";AF.SHIM_TEMPLATE='<iframe frameborder="0" tabindex="-1" class="'+AG("shim")+'" title="'+AF.SHIM_TEMPLATE_TITLE+'" src="javascript:false;"></iframe>';AF.ATTRS={useARIA:{value:true,writeOnce:true,setter:function(AO){var AL=this.get("host"),AP,Y,AN,AM;if(AO){AL.set(AK,Q);AL.queryAll("ul,li").set(AK,M);AL.queryAll((I+AG(G,"content"))).set(AK,G);AL.queryAll((I+AD)).each(function(AQ){AP=AQ;Y=AQ.query(AB);if(Y){Y.set(AK,M);AP=Y.previous();}AP.set(AK,G);AP.set("aria-haspopup",true);AN=AQ.next();AN.set(AK,Q);AP=AN.previous();Y=AP.query(AB);if(Y){AP=Y;}AM=D.stamp(AP);if(!AP.get(e)){AP.set(e,AM);}AN.set("aria-labelledby",AM);AN.set("aria-hidden",true);});}}},autoSubmenuDisplay:{value:true,writeOnce:true},submenuShowDelay:{value:250,writeOnce:true},submenuHideDelay:{value:250,writeOnce:true},mouseOutHideDelay:{value:750,writeOnce:true}};D.extend(AF,D.Plugin.Base,{_rootMenu:null,_activeItem:null,_activeMenu:null,_hasFocus:false,_blockMouseEvent:false,_currentMouseX:0,_movingToSubmenu:false,_showSubmenuTimer:null,_hideSubmenuTimer:null,_hideAllSubmenusTimer:null,_firstItem:null,_isRoot:function(Y){return this._rootMenu.compareTo(Y);},_getTopmostSubmenu:function(AN){var AM=this,Y=L(AN),AL;if(!Y){AL=AN;}else{if(AM._isRoot(Y)){AL=AN;}else{AL=AM._getTopmostSubmenu(Y);}}return AL;},_clearActiveItem:function(){var AL=this,Y=AL._activeItem;if(Y){Y.removeClass(d(Y));}AL._activeItem=null;},_setActiveItem:function(AL){var Y=this;if(AL){Y._clearActiveItem();AL.addClass(d(AL));Y._activeItem=AL;}},_focusItem:function(AM){var AL=this,Y,AN;if(AM&&AL._hasFocus){Y=L(AM);AN=m(AM);if(AL._activeMenu!==Y){AL._activeMenu=Y;AL._initFocusManager();}AL._focusManager.focus(AN);}},_showMenu:function(AN){var Y=L(AN),AM=AN.get(R),AL=AM.getXY();if(n(Y)){AL[1]=AL[1]+AM.get(u);}else{AL[0]=AL[0]+AM.get(x);}AN.setXY(AL);if(j.ie<8){if(j.ie===6&&!AN.hasIFrameShim){AN.appendChild(D.Node.create(AF.SHIM_TEMPLATE));AN.hasIFrameShim=true;}AN.setStyles({height:P,width:P});AN.setStyles({height:(AN.get(u)+AI),width:(AN.get(x)+AI)});}AN.previous().addClass(W);AN.removeClass(AA);},_hideMenu:function(AN,AL){var AM=this,AO=AN.previous(),Y;AO.removeClass(W);if(AL){AM._setActiveItem(AO);AM._focusItem(AO);}Y=AN.query((I+A));if(Y){Y.removeClass(A);}AN.setStyles({left:P,top:P});AN.addClass(AA);},_hideAllSubmenus:function(AL){var Y=this;AL.queryAll(f).each(D.bind(function(AM){Y._hideMenu(AM);},Y));},_cancelShowSubmenuTimer:function(){var AL=this,Y=AL._showSubmenuTimer;if(Y){Y.cancel();AL._showSubmenuTimer=null;}},_cancelHideSubmenuTimer:function(){var Y=this,AL=Y._hideSubmenuTimer;if(AL){AL.cancel();Y._hideSubmenuTimer=null;}},_onActiveDescendantChange:function(AL,Y){if(AL.src===g){if(Y._activeMenu&&!Y._movingToSubmenu){Y._hideAllSubmenus(Y._activeMenu);}}},_afterActiveDescendantChange:function(AL,Y){var AM;if(AL.src===g){AM=this.get(y).item(AL.newVal);Y._setActiveItem(AM);}},_afterHasFocusChange:function(AN,AM){var AL=this.get(y).item(this.get(r)),Y;AM._hasFocus=AN.newVal;if(AN.newVal){Y=B(AL,true);if(Y){AM._setActiveItem(Y);}}else{AM._clearActiveItem();AM._cancelShowSubmenuTimer();AM._hideAllSubmenus(AM._rootMenu);AM._activeMenu=AM._rootMenu;AM._initFocusManager();this.set(r,0);}},_initFocusManager:function(){var AN=this,AP=AN._rootMenu,AL=AN._activeMenu||AP,AO=AN._isRoot(AL)?P:("#"+AL.get("id")),Y=AN._focusManager,AM,AQ,AR;if(n(AL)){AQ=AO+AH+","+AO+N;AM={next:"down:39",previous:"down:37"};}else{AQ=AO+AH;AM={next:"down:40",previous:"down:38"};}if(!Y){AP.plug(D.Plugin.NodeFocusManager,{descendants:AQ,keys:AM,circular:true});Y=AP.focusManager;AR="#"+AP.get("id")+" .yui-menu a,"+AB;AP.queryAll(AR).set("tabIndex",-1);Y.on("activeDescendantChange",this._onActiveDescendantChange,Y,this);Y.after("activeDescendantChange",this._afterActiveDescendantChange,Y,this);Y.after("hasFocusChange",this._afterHasFocusChange,Y,this);
AN._focusManager=Y;}else{Y.set(r,-1);Y.set(y,AQ);Y.set("keys",AM);}},_onMenuMouseOver:function(AN,AM){var AL=this,Y=AL._hideAllSubmenusTimer;if(Y){Y.cancel();AL._hideAllSubmenusTimer=null;}AL._cancelHideSubmenuTimer();if(AL._activeMenu!==AN){AL._activeMenu=AN;if(AL._hasFocus){AL._initFocusManager();}}if(AL._movingToSubmenu&&n(AN)){AL._movingToSubmenu=false;}},_hideAndFocusLabel:function(){var AM=this,AL=AM._activeMenu,Y;AM._hideAllSubmenus(AM._rootMenu);if(AL){Y=AM._getTopmostSubmenu(AL);AM._focusItem(Y.previous());}},_onMenuMouseOut:function(AR,AP){var AO=this,AM=AO._activeMenu,AQ=AP.relatedTarget,Y=AO._activeItem,AN,AL;if(AM&&!AM.contains(AQ)){AN=L(AM);if(AN&&!AN.contains(AQ)){if(AO.get(S)>0){AO._cancelShowSubmenuTimer();AO._hideAllSubmenusTimer=q(AO.get(S),AO,AO._hideAndFocusLabel);}}else{if(Y){AL=L(Y);if(!AO._isRoot(AL)){AO._focusItem(AL.previous());}}}}},_onMenuLabelMouseOver:function(AO,AQ){var AP=this,AN=AP._activeMenu,Y=AP._isRoot(AN),AM=(AP.get(s)&&Y||!Y),AL;AP._setActiveItem(AO);AP._focusItem(AO);if(AM&&!AP._movingToSubmenu){AP._cancelHideSubmenuTimer();AP._cancelShowSubmenuTimer();if(!k(AO)){AL=AO.next();if(AL){AP._hideAllSubmenus(AN);AP._showSubmenuTimer=q(AP.get("submenuShowDelay"),AP,AP._showMenu,AL);}}}},_onMenuLabelMouseOut:function(AN,AP){var AO=this,Y=AO._isRoot(AO._activeMenu),AM=(AO.get(s)&&Y||!Y),AQ=AP.relatedTarget,AL=AN.next();AO._clearActiveItem();if(AM){if(AO._movingToSubmenu&&!AO._showSubmenuTimer&&AL){AO._hideSubmenuTimer=q(AO.get("submenuHideDelay"),AO,AO._hideMenu,AL);}else{if(!AO._movingToSubmenu&&AL&&!AL.contains(AQ)&&AQ!==AL){AO._cancelShowSubmenuTimer();AO._hideMenu(AL);}}}},_onMenuItemMouseOver:function(AN,AP){var AO=this,AM=AO._activeMenu,Y=AO._isRoot(AM),AL=(AO.get(s)&&Y||!Y);AO._setActiveItem(AN);AO._focusItem(AN);if(AL&&!AO._movingToSubmenu){AO._hideAllSubmenus(AM);}},_onMenuItemMouseOut:function(Y,AL){this._clearActiveItem();},_onVerticalMenuKeyDown:function(Y){var AL=this,AP=AL._activeMenu,AU=AL._rootMenu,AM=Y.target,AO=false,AT=Y.keyCode,AR,AN,AQ,AS;switch(AT){case 37:AN=L(AP);if(AN&&n(AN)){AL._hideMenu(AP);AQ=K(AP.get(R));AS=B(AQ);if(AS){if(p(AS)){AR=AS.next();if(AR){AL._showMenu(AR);AL._focusItem(C(AR));AL._setActiveItem(C(AR));}else{AL._focusItem(AS);AL._setActiveItem(AS);}}else{AL._focusItem(AS);AL._setActiveItem(AS);}}}else{if(!AL._isRoot(AP)){AL._hideMenu(AP,true);}}AO=true;break;case 39:if(p(AM)){AR=AM.next();if(AR){AL._showMenu(AR);AL._focusItem(C(AR));AL._setActiveItem(C(AR));}}else{if(n(AU)){AR=AL._getTopmostSubmenu(AP);AQ=a(AR.get(R));AS=B(AQ);AL._hideAllSubmenus(AU);if(AS){if(p(AS)){AR=AS.next();if(AR){AL._showMenu(AR);AL._focusItem(C(AR));AL._setActiveItem(C(AR));}else{AL._focusItem(AS);AL._setActiveItem(AS);}}else{AL._focusItem(AS);AL._setActiveItem(AS);}}}}AO=true;break;}if(AO){Y.preventDefault();}},_onHorizontalMenuKeyDown:function(AQ){var AP=this,AN=AP._activeMenu,AL=AQ.target,Y=B(AL,true),AO=false,AR=AQ.keyCode,AM;if(AR===40){AP._hideAllSubmenus(AN);if(p(Y)){AM=Y.next();if(AM){AP._showMenu(AM);AP._focusItem(C(AM));AP._setActiveItem(C(AM));}AO=true;}}if(AO){AQ.preventDefault();}},_onMouseMove:function(AL){var Y=this;q(10,Y,function(){Y._currentMouseX=AL.pageX;});},_onMouseOver:function(AO){var AN=this,AL,Y,AQ,AM,AP;if(AN._blockMouseEvent){AN._blockMouseEvent=false;}else{AL=AO.target;Y=V(AL,true);AQ=l(AL,true);AP=z(AL,true);if(c(Y,AL)){AN._onMenuMouseOver(Y,AO);Y[o]=true;Y[E]=false;AM=L(Y);if(AM){AM[E]=true;AM[o]=false;}}if(c(AQ,AL)){AN._onMenuLabelMouseOver(AQ,AO);AQ[o]=true;AQ[E]=false;}if(c(AP,AL)){AN._onMenuItemMouseOver(AP,AO);AP[o]=true;AP[E]=false;}}},_onMouseOut:function(AL){var AM=this,AO=AM._activeMenu,AT=false,AN,AP,AR,Y,AQ,AS;AM._movingToSubmenu=(AO&&!n(AO)&&((AL.pageX-5)>AM._currentMouseX));AN=AL.target;AP=AL.relatedTarget;AR=V(AN,true);Y=l(AN,true);AS=z(AN,true);if(H(Y,AP)){AM._onMenuLabelMouseOut(Y,AL);Y[E]=true;Y[o]=false;}if(H(AS,AP)){AM._onMenuItemMouseOut(AS,AL);AS[E]=true;AS[o]=false;}if(Y){AQ=Y.next();if(AQ&&(AP===AQ||AQ.contains(AP))){AT=true;}}if(H(AR,AP)||AT){AM._onMenuMouseOut(AR,AL);AR[E]=true;AR[o]=false;}},_toggleSubmenuDisplay:function(AM){var AN=this,AO=AM.target,AL=l(AO,true),Y=AM.type,AS,AR,AQ,AT,AU,AP;if(AL){AS=F(AO)?AO:AO.ancestor(F);if(AS){AQ=AS.getAttribute("href",2);AT=AQ.indexOf("#");AU=AQ.length;if(AT===0&&AU>1){AP=AQ.substr(1,AU);AR=AL.next();if(AR&&(AR.get(e)===AP)){if(Y===t||(Y===AJ&&AM.keyCode===13)){AM.preventDefault();if(D.UA.webkit){AM.stopImmediatePropagation();}AN._hasFocus=true;if(k(AL)){AN._hideMenu(AR);AN._setActiveItem(AL);AN._focusItem(AL);}else{AN._hideAllSubmenus(AN._rootMenu);AN._showMenu(AR);AN._focusItem(C(AR));AN._setActiveItem(C(AR));}}if(Y===w){AM.preventDefault();}}}}}},_onKeyPress:function(Y){switch(Y.keyCode){case 37:case 38:case 39:case 40:Y.preventDefault();break;}},_onKeyDown:function(AP){var AO=this,Y=AO._activeItem,AL=AP.target,AN=L(AL),AM;if(AN){AO._activeMenu=AN;if(n(AN)){AO._onHorizontalMenuKeyDown(AP);}else{AO._onVerticalMenuKeyDown(AP);}if(AP.keyCode===27){if(!AO._isRoot(AN)){AO._hideMenu(AN,true);AP.stopPropagation();AO._blockMouseEvent=j.gecko?true:false;}else{if(Y){if(p(Y)&&k(Y)){AM=Y.next();if(AM){AO._hideMenu(AM);}}else{AO._focusManager.blur();}}}}}},_onDocMouseDown:function(AN){var AM=this,AL=AM._rootMenu,Y=AN.target;if(!AL.compareTo(Y)&&!AL.contains(Y)){AM._hideAllSubmenus(AL);}},initializer:function(AL){var AM=this,AN=this.get("host"),Y;if(AN){AM._rootMenu=AN;AN.queryAll("ul:first-child").addClass(T);AN.queryAll(f).addClass(AA);AN.on("mouseover",AM._onMouseOver,AM);AN.on("mouseout",AM._onMouseOut,AM);AN.on("mousemove",AM._onMouseMove,AM);AN.on(t,AM._toggleSubmenuDisplay,AM);AN.on(AJ,AM._toggleSubmenuDisplay,AM);AN.on(w,AM._toggleSubmenuDisplay,AM);AN.on("keypress",AM._onKeyPress,AM);AN.on(AJ,AM._onKeyDown,AM);Y=AN.get("ownerDocument");Y.on(t,AM._onDocMouseDown,AM);AM._initFocusManager();}},destructor:function(){}});D.namespace("Plugin");D.Plugin.NodeMenuNav=AF;},"@VERSION@",{requires:["node","classnamemanager","node-focusmanager"]});