/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:33
*/
KISSY.add("menu/base",function(e,d,c,b){function a(){this.set("highlightedItem",null)}var f=d.KeyCodes,h=c.Container.extend({_uiSetHighlightedItem:function(a,f){var b=f&&f.prevVal;b&&b.set("highlighted",!1);a&&a.set("highlighted",!0);this.set("activeItem",a)},handleBlur:function(a){h.superclass.handleBlur.call(this,a);this.set("highlightedItem",null)},_getNextEnabledHighlighted:function(a,f){var b=this.get("children"),e=b.length,d=a;do{var c=b[a];if(!c.get("disabled")&&!1!==c.get("visible"))return b[a];
a=(a+f+e)%e}while(a!=d)},handleKeydown:function(a){if(this.handleKeyEventInternal(a))return a.halt(),!0},handleKeyEventInternal:function(a){var b=this.get("highlightedItem");if(b&&b.handleKeydown(a))return!0;var d=this.get("children"),c=d.length;if(0!==c){switch(a.keyCode){case f.ESC:return;case f.HOME:this.set("highlightedItem",this._getNextEnabledHighlighted(0,1));break;case f.END:this.set("highlightedItem",this._getNextEnabledHighlighted(c-1,-1));break;case f.UP:b?(a=e.indexOf(b,d),c=(a-1+c)%c):
c-=1;this.set("highlightedItem",this._getNextEnabledHighlighted(c,-1));break;case f.DOWN:b?(a=e.indexOf(b,d),c=(a+1+c)%c):c=0;this.set("highlightedItem",this._getNextEnabledHighlighted(c,1));break;default:return}return!0}},bindUI:function(){this.on("hide",a,this)},containsElement:function(a){if(!1===this.get("visible")||!this.get("view"))return!1;if(this.get("view").containsElement(a))return!0;for(var b=this.get("children"),f=0,c=b.length;f<c;f++){var e=b[f];if("function"==typeof e.containsElement&&
e.containsElement(a))return!0}return!1}},{ATTRS:{visibleMode:{value:"display"},highlightedItem:{},activeItem:{view:1},xrender:{value:b}}},{xclass:"menu",priority:10});return h},{requires:["event","component","./menuRender","./submenu"]});
KISSY.add("menu/filtermenu",function(e,d,c){var b=d.extend({bindUI:function(){this.get("view").get("filterInput").on("keyup",this.handleFilterEvent,this)},handleMouseEnter:function(){b.superclass.handleMouseEnter.apply(this,arguments);this.getKeyEventTarget()[0].select()},handleFilterEvent:function(){var a=this.get("view").get("filterInput"),b=this.get("highlightedItem");this.set("filterStr",a.val());(!b||!b.get("visible"))&&this.set("highlightedItem",this._getNextEnabledHighlighted(0,1))},_uiSetFilterStr:function(a){this.filterItems(a)},
filterItems:function(a){var b=this.get("view"),c=b.get("labelEl"),b=b.get("filterInput");c[a?"hide":"show"]();if(this.get("allowMultiple")){var c=[],d;d=a.match(/(.+)[,\uff0c]\s*([^\uff0c,]*)/);var g=[];d&&(g=d[1].split(/[,\uff0c]/));/[,\uff0c]$/.test(a)?(c=[],d&&(c=g,d=g[g.length-1],(g=(g=this.get("highlightedItem"))&&g.get("content"))&&-1<g.indexOf(d)&&d&&(c[c.length-1]=g),b.val(c.join(",")+",")),a=""):(d&&(a=d[2]||""),c=g);this.get("enteredItems").length!=c.length&&this.set("enteredItems",c)}var b=
this.get("children"),j=a&&RegExp(a.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1").replace(/\x08/g,"\\x08"),"ig");e.each(b,function(b){var c=b.get("content");a?-1<c.indexOf(a)?(b.set("visible",!0),b.get("el").html(c.replace(j,function(a){return"<span class='ks-menuitem-hit'>"+a+"</span>"}))):b.set("visible",!1):(b.get("el").html(c),b.set("visible",!0))})},decorateInternal:function(a){this.set("el",a);this.decorateChildren(a.one(".ks-menu-content"))},reset:function(){var a=this.get("view");this.set("filterStr",
"");this.set("enteredItems",[]);(a=a&&a.get("filterInput"))&&a.val("")},destructor:function(){var a=this.get("view");(a=a&&a.get("filterInput"))&&a.detach()}},{ATTRS:{allowTextSelection:{value:!0},label:{view:1},filterStr:{},enteredItems:{value:[]},allowMultiple:{value:!1},xrender:{value:c}}},{xclass:"filter-menu",priority:20});return b},{requires:["./base","./filtermenuRender"]});
KISSY.add("menu/filtermenuRender",function(e,d,c){var b=d.all;return c.extend({getContentElement:function(){return this.get("menuContent")},getKeyEventTarget:function(){return this.get("filterInput")},createDom:function(){var a=c.prototype.getContentElement.call(this),f=this.get("filterWrap");f||this.set("filterWrap",f=b("<div class='ks-menu-filter'/>").appendTo(a,void 0));this.get("labelEl")||this.set("labelEl",b("<div class='ks-menu-filter-label'/>").appendTo(f,void 0));this.get("filterInput")||
this.set("filterInput",b("<input autocomplete='off'/>").appendTo(f,void 0));this.get("menuContent")||this.set("menuContent",b("<div class='ks-menu-content'/>").appendTo(a,void 0))},_uiSetLabel:function(a){this.get("labelEl").html(a)}},{ATTRS:{label:{}},HTML_PARSER:{labelEl:function(a){return a.one(".ks-menu-filter").one(".ks-menu-filter-label")},filterWrap:function(a){return a.one(".ks-menu-filter")},menuContent:function(a){return a.one(".ks-menu-content")},filterInput:function(a){return a.one(".ks-menu-filter").one("input")}}})},
{requires:["node","./menuRender"]});KISSY.add("menu",function(e,d,c,b,a,f,h,i,g,j,k){d.Render=c;d.Item=b;b.Render=a;d.SubMenu=f;f.Render=h;d.Separator=i;d.PopupMenu=g;g.Render=j;d.FilterMenu=k;return d},{requires:"menu/base,menu/menuRender,menu/menuitem,menu/menuitemRender,menu/submenu,menu/submenuRender,menu/separator,menu/popupmenu,menu/popupmenuRender,menu/filtermenu".split(",")});
KISSY.add("menu/menuRender",function(e,d,c){return c.Render.extend({renderUI:function(){var b=this.get("el");b.attr("role","menu").attr("aria-haspopup",!0);b.attr("id")||b.attr("id",e.guid("ks-menu"))},_uiSetActiveItem:function(b){var a=this.get("el");b?(b=b.get("el").attr("id"),a.attr("aria-activedescendant",b)):a.attr("aria-activedescendant","")},containsElement:function(b){var a=this.get("el");return a[0]===b||a.contains(b)}},{ATTRS:{activeItem:{}}})},{requires:["ua","component"]});
KISSY.add("menu/menuitem",function(e,d,c){var b=e.all,a=d.Controller.extend({bindUI:function(){this.publish("click",{bubbles:1})},handleMouseEnter:function(b){if(a.superclass.handleMouseEnter.call(this,b))return!0;this.get("parent").set("highlightedItem",this)},handleMouseLeave:function(b){if(a.superclass.handleMouseLeave.call(this,b))return!0;this.get("parent").set("highlightedItem",null)},performActionInternal:function(){this.get("selectable")&&this.set("selected",!0);this.get("checkable")&&this.set("checked",
!this.get("checked"));this.fire("click");return!0},_uiSetHighlighted:function(a){if(a){var a=this.get("el"),c=a.parent(function(a){return"visible"!=b(a).css("overflow")},this.get("parent").get("el").parent());c&&a.scrollIntoView(c,void 0,void 0,!0)}},containsElement:function(a){return this.get("view")&&this.get("view").containsElement(a)}},{ATTRS:{focusable:{value:!1},visibleMode:{value:"display"},handleMouseEvents:{value:!1},selectable:{view:1},checkable:{view:1},value:{},checked:{view:1},selected:{view:1},
xrender:{value:c}}},{xclass:"menuitem",priority:10});return a},{requires:["component","./menuitemRender"]});
KISSY.add("menu/menuitemRender",function(e,d,c){return c.Render.extend({_uiSetChecked:function(b){var a=this.get("el"),c=this.getComponentCssClassWithState("-checked");a[b?"addClass":"removeClass"](c)},_uiSetSelected:function(b){var a=this.get("el"),c=this.getComponentCssClassWithState("-selected");a[b?"addClass":"removeClass"](c)},_uiSetSelectable:function(b){this.get("el").attr("role",b?"menuitemradio":"menuitem")},_uiSetCheckable:function(b){if(b){var a=this.get("el"),c=a.one(".ks-menuitem-checkbox");
c||(c=(new d("<div class='ks-menuitem-checkbox'/>")).prependTo(a),c.unselectable())}this.get("el").attr("role",b?"menuitemcheckbox":"menuitem")},containsElement:function(b){var a=this.get("el");return a&&(a[0]==b||a.contains(b))}},{ATTRS:{elAttrs:{valueFn:function(){return{role:"menuitem",id:e.guid("ks-menuitem")}}},selected:{},checked:{}},HTML_PARSER:{selectable:function(b){var a=this.getCssClassWithPrefix("menuitem-selectable");return b.hasClass(a)},checkable:function(b){var a=this.getCssClassWithPrefix("menuitem-checkable");
return b.hasClass(a)}}})},{requires:["node","component"]});
KISSY.add("menu/popupmenu",function(e,d,c,b){var e=d.UIBase,a=c.extend([e.ContentBox,e.Position,e.Align],{handleMouseLeave:function(){this.get("autoHideOnMouseLeave")&&this.get("parent").hideParentMenusBuffer()},handleBlur:function(){a.superclass.handleBlur.apply(this,arguments);this.hide()}},{ATTRS:{focusable:{value:!1},visibleMode:{value:"visibility"},autoHideOnMouseLeave:{},xrender:{value:b}}},{xclass:"popupmenu",priority:20});return a},{requires:["component","./base","./popupmenuRender"]});
KISSY.add("menu/popupmenuRender",function(e,d,c,b){e=c.UIBase;return b.extend([e.ContentBox.Render,e.Position.Render,6===d.ie?e.Shim.Render:null])},{requires:["ua","component","./menuRender"]});KISSY.add("menu/separator",function(e,d,c){return c.extend({},{},{xclass:"menuseparator",priority:20})},{requires:["component","separator"]});
KISSY.add("menu/submenu",function(e,d,c,b,a){function f(a,b){var d=a.get("menu");if(d&&d.xclass)if(b)d=c.create(d,a),a.__set("menu",d);else return null;return d}function h(a){var b=f(this),a=a.target,c=this.get("parent");this.get("el");c.containsElement(a)||(b&&b.hide(),this.get("parent").set("highlightedItem",null))}function i(){var a=f(this,1);if(a){this.bindSubMenu();var b=e.clone(a.get("align"));b.node=this.get("el");b.points=b.points||["tr","tl"];a.set("align",b);a.show();this.get("el").attr("aria-haspopup",
a.get("el").attr("id"))}}function g(){var a=f(this);a&&a.hide()}function j(a){a.newVal&&(this.clearSubMenuTimers(),this.get("parent").set("highlightedItem",this))}function k(){var a=f(this);a&&a.hide()}var m=d.KeyCodes,n=e.Env.host.document,l=b.extend([c.DecorateChild],{bindSubMenu:function(){var a=this,b=a.get("menu"),c=a.get("parent");c&&(c.on("hide",k,a),c.__bindDocClickToHide||(d.on(n,"click",h,a),c.__bindDocClickToHide=1,b.__bindDocClickToHide=1),b.on("afterActiveItemChange",function(a){c.set("activeItem",
a.newVal)}),b.on("afterHighlightedItemChange",function(b){b.newVal&&a.set("highlighted",true)}),a.bindSubMenu=e.noop);b.on("beforeHighlightedItemChange",j,a)},handleMouseEnter:function(a){if(l.superclass.handleMouseEnter.call(this,a))return!0;this.clearSubMenuTimers();this.showTimer_=e.later(i,1E3*this.get("menuDelay"),!1,this)},_uiSetHighlighted:function(a){a||(this.dismissTimer_=e.later(g,1E3*this.get("menuDelay"),!1,this))},clearSubMenuTimers:function(){var a;if(a=this.dismissTimer_)a.cancel(),
this.dismissTimer_=null;if(a=this.showTimer_)a.cancel(),this.showTimer_=null},performActionInternal:function(){this.clearSubMenuTimers();i.call(this);l.superclass.performActionInternal.apply(this,arguments)},handleKeydown:function(a){var b=f(this),c=b&&b.get("visible"),e=a.keyCode;if(c){if(!b.handleKeydown(a))if(e==m.LEFT)g.call(this),this.get("parent").set("activeItem",this);else return}else if(e==m.RIGHT){if(i.call(this),b=f(this))a=b.get("children"),a[0]&&b.set("highlightedItem",a[0])}else{if(a.keyCode==
d.KeyCodes.ENTER)return this.performActionInternal(a);return}return!0},hideParentMenusBuffer:function(){var a=this,b=a.get("parent");a.dismissTimer_=e.later(function(){for(var c=a,d=a.get("menu");d.get("autoHideOnMouseLeave");){c.set("highlighted",!1);if(b.get("highlightedItem")!=c)break;c=b.get("parent");if(!c)break;b=c.get("parent");d=c.get("menu")}},1E3*a.get("menuDelay"),!1,a)},containsElement:function(a){var b=f(this);return b&&b.containsElement(a)},decorateChildrenInternal:function(a,b){b.css("visibility",
"hidden");e.one(b[0].ownerDocument.body).prepend(b);this.__set("menu",new a({srcNode:b,prefixCls:this.get("prefixCls")}))},destructor:function(){var a=this.get("parent"),b=f(this);this.clearSubMenuTimers();b&&b.__bindDocClickToHide&&(b.__bindDocClickToHide=0,d.remove(n,"click",h,this));a&&a.detach("hide",k,this);b&&b.destroy&&b.destroy()}},{ATTRS:{menuDelay:{value:0.15},menu:{setter:function(a){a instanceof c.Controller&&a.__set("parent",this)}},decorateChildCls:{valueFn:function(){return this.get("prefixCls")+
"popupmenu"}},xrender:{value:a}}},{xclass:"submenu",priority:20});return l},{requires:["event","component","./menuitem","./submenuRender"]});KISSY.add("menu/submenuRender",function(e,d){return d.extend({createDom:function(){this.get("el").attr("aria-haspopup","true").append('<span class="ks-submenu-arrow">\u25ba</span>')}},{ATTRS:{arrowEl:{},contentElCls:{value:"ks-menuitem-content"},contentEl:{valueFn:function(){return e.all('<span class="ks-menuitem-content"></span>')}}}})},{requires:["./menuitemRender"]});
