/*
Copyright 2013, KISSY UI Library v1.31
MIT Licensed
build time: Jan 29 20:39
*/
KISSY.add("menu/base",function(e,c,a,g){function d(b){this.set("highlightedItem",null);b.stopPropagation()}var b=c.KeyCodes,f=a.Container.extend({_onSetHighlightedItem:function(b,d){var a=d&&d.prevVal;a&&a.set("highlighted",!1);b&&b.set("highlighted",!0);this.set("activeItem",b)},handleBlur:function(b){f.superclass.handleBlur.call(this,b);this.set("highlightedItem",null)},_getNextEnabledHighlighted:function(b,d){var a=this.get("children"),c=a.length,e=b;do{var f=a[b];if(!f.get("disabled")&&!1!==f.get("visible"))return a[b];
b=(b+d+c)%c}while(b!=e)},handleKeyEventInternal:function(d){var a=this.get("highlightedItem");if(a&&a.handleKeydown(d))return!0;var c=this.get("children"),f=c.length;if(0!==f){switch(d.keyCode){case b.ESC:return;case b.HOME:this.set("highlightedItem",this._getNextEnabledHighlighted(0,1));break;case b.END:this.set("highlightedItem",this._getNextEnabledHighlighted(f-1,-1));break;case b.UP:a?(d=e.indexOf(a,c),f=(d-1+f)%f):f-=1;this.set("highlightedItem",this._getNextEnabledHighlighted(f,-1));break;case b.DOWN:a?
(d=e.indexOf(a,c),f=(d+1+f)%f):f=0;this.set("highlightedItem",this._getNextEnabledHighlighted(f,1));break;default:return}return!0}},bindUI:function(){this.on("hide",d,this)},containsElement:function(b){if(!1===this.get("visible")||!this.get("view"))return!1;if(this.get("view").containsElement(b))return!0;for(var d=this.get("children"),a=0,f=d.length;a<f;a++){var c=d[a];if("function"==typeof c.containsElement&&c.containsElement(b))return!0}return!1}},{ATTRS:{highlightedItem:{},activeItem:{view:1},
xrender:{value:g},defaultChildXClass:{value:"menuitem"}}},{xclass:"menu",priority:10});return f},{requires:["event","component/base","./menu-render","./submenu"]});
KISSY.add("menu/filtermenu-render",function(e,c,a){var g=c.all;return a.extend({getContentElement:function(){return this.get("menuContent")},getKeyEventTarget:function(){return this.get("filterInput")},createDom:function(){var d=this.get("prefixCls"),b=a.prototype.getContentElement.call(this),f=this.get("filterWrap");f||this.set("filterWrap",f=g("<div class='"+d+"menu-filter'/>").appendTo(b,void 0));this.get("labelEl")||this.set("labelEl",g("<div class='"+d+"menu-filter-label'/>").appendTo(f,void 0));
this.get("filterInput")||this.set("filterInput",g("<input autocomplete='off'/>").appendTo(f,void 0));this.get("menuContent")||this.set("menuContent",g("<div class='"+d+"menu-content'/>").appendTo(b,void 0))},_onSetLabel:function(d){this.get("labelEl").html(d)}},{ATTRS:{label:{}},HTML_PARSER:{labelEl:function(d){return d.one("."+this.get("prefixCls")+"menu-filter").one("."+this.get("prefixCls")+"menu-filter-label")},filterWrap:function(d){return d.one("."+this.get("prefixCls")+"menu-filter")},menuContent:function(d){return d.one("."+
this.get("prefixCls")+"menu-content")},filterInput:function(d){return d.one("."+this.get("prefixCls")+"menu-filter").one("input")}}})},{requires:["node","./menu-render"]});
KISSY.add("menu/filtermenu",function(e,c,a,g){var d=a.extend([c.DecorateChild],{bindUI:function(){this.get("view").get("filterInput").on("keyup",this.handleFilterEvent,this)},handleMouseEnter:function(){d.superclass.handleMouseEnter.apply(this,arguments);this.getKeyEventTarget()[0].select()},handleFilterEvent:function(){var b=this.get("view").get("filterInput"),d=this.get("highlightedItem");this.set("filterStr",b.val());(!d||!d.get("visible"))&&this.set("highlightedItem",this._getNextEnabledHighlighted(0,
1))},_onSetFilterStr:function(b){this.filterItems(b)},filterItems:function(b){var d=this.get("prefixCls"),a=this.get("view"),c=a.get("labelEl"),a=a.get("filterInput");c[b?"hide":"show"]();if(this.get("allowMultiple")){var c=[],g;g=b.match(/(.+)[,\uff0c]\s*([^\uff0c,]*)/);var h=[];g&&(h=g[1].split(/[,\uff0c]/));/[,\uff0c]$/.test(b)?(c=[],g&&(c=h,g=h[h.length-1],(h=(h=this.get("highlightedItem"))&&h.get("content"))&&-1<h.indexOf(g)&&g&&(c[c.length-1]=h),a.val(c.join(",")+",")),b=""):(g&&(b=g[2]||""),
c=h);this.get("enteredItems").length!=c.length&&this.set("enteredItems",c)}var a=this.get("children"),k=b&&RegExp(b.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1").replace(/\x08/g,"\\x08"),"ig");e.each(a,function(a){var c=a.get("content");b?-1<c.indexOf(b)?(a.set("visible",!0),a.get("el").html(c.replace(k,function(b){return"<span class='"+d+"menuitem-hit'>"+b+"</span>"}))):a.set("visible",!1):(a.get("el").html(c),a.set("visible",!0))})},reset:function(){var b=this.get("view");this.set("filterStr",
"");this.set("enteredItems",[]);(b=b&&b.get("filterInput"))&&b.val("")},destructor:function(){var b=this.get("view");(b=b&&b.get("filterInput"))&&b.detach()}},{ATTRS:{allowTextSelection:{value:!0},label:{view:1},filterStr:{},enteredItems:{value:[]},allowMultiple:{value:!1},decorateChildCls:{valueFn:function(){return this.get("prefixCls")+"menu-content"}},xrender:{value:g}}},{xclass:"filter-menu",priority:20});return d},{requires:["component/base","./base","./filtermenu-render"]});
KISSY.add("menu/menu-render",function(e,c){return c.Render.extend({renderUI:function(){var a=this.get("el");a.attr("role","menu").attr("aria-haspopup",!0);a.attr("id")||a.attr("id",e.guid("ks-menu"))},_onSetActiveItem:function(a){var c=this.get("el");a?(a=a.get("el").attr("id"),c.attr("aria-activedescendant",a)):c.attr("aria-activedescendant","")},containsElement:function(a){var c=this.get("el");return c[0]===a||c.contains(a)}},{ATTRS:{activeItem:{}}})},{requires:["component/base"]});
KISSY.add("menu",function(e,c,a,g,d,b,f,i,j,l){c.Render=a;c.Item=g;g.Render=d;c.SubMenu=b;b.Render=f;c.PopupMenu=i;i.Render=j;c.FilterMenu=l;return c},{requires:"menu/base,menu/menu-render,menu/menuitem,menu/menuitem-render,menu/submenu,menu/submenu-render,menu/popupmenu,menu/popupmenu-render,menu/filtermenu".split(",")});
KISSY.add("menu/menuitem-render",function(e,c,a,g){return a.Render.extend({_onSetChecked:function(a){var b=this.get("el"),c=this.getCssClassWithState("-checked");b[a?"addClass":"removeClass"](c)},_onSetSelected:function(a){var b=this.get("el"),c=this.getCssClassWithState("-selected");b[a?"addClass":"removeClass"](c)},_onSetSelectable:function(a){this.get("el").attr("role",a?"menuitemradio":"menuitem")},_onSetCheckable:function(a){if(a){var b=this.get("el"),f=this.get("prefixCls"),e=b.one("."+f+"menuitem-checkbox");
e||(e=(new c("<div class='"+f+"menuitem-checkbox'/>")).prependTo(b),e.unselectable(g))}this.get("el").attr("role",a?"menuitemcheckbox":"menuitem")},containsElement:function(a){var b=this.get("el");return b&&(b[0]==a||b.contains(a))}},{ATTRS:{checkable:{},elAttrs:{valueFn:function(){return{role:"menuitem",id:e.guid("ks-menuitem")}}},selected:{},checked:{}},HTML_PARSER:{selectable:function(a){var b=this.getCssClassWithPrefix("menuitem-selectable");return a.hasClass(b)},checkable:function(a){var b=this.getCssClassWithPrefix("menuitem-checkable");
return a.hasClass(b)}}})},{requires:["node","component/base"]});
KISSY.add("menu/menuitem",function(e,c,a){var g=e.all,d=c.Controller.extend({handleMouseEnter:function(b){if(d.superclass.handleMouseEnter.call(this,b))return!0;this.get("parent").set("highlightedItem",this)},handleMouseLeave:function(b){if(d.superclass.handleMouseLeave.call(this,b))return!0;this.get("parent").set("highlightedItem",null)},handleMouseDown:function(b){if(d.superclass.handleMouseDown.call(this,b))return!0;this.get("parent").set("highlightedItem",this)},performActionInternal:function(){this.get("selectable")&&
this.set("selected",!0);this.get("checkable")&&this.set("checked",!this.get("checked"));this.fire("click");return!0},_onSetHighlighted:function(b){if(b){var b=this.get("el"),a=b.parent(function(b){return"visible"!=g(b).css("overflow")},this.get("parent").get("el").parent());a&&b.scrollIntoView(a,{alignWithTop:!0,allowHorizontalScroll:!0,onlyScrollIfNeeded:!0})}},containsElement:function(b){return this.get("view")&&this.get("view").containsElement(b)}},{ATTRS:{focusable:{value:!1},handleMouseEvents:{value:!1},
selectable:{view:1},checkable:{view:1},value:{},checked:{view:1},selected:{view:1},xrender:{value:a}}},{xclass:"menuitem",priority:10});return d},{requires:["component/base","./menuitem-render"]});KISSY.add("menu/popupmenu-render",function(e,c,a){return a.extend([c.ContentBox.Render,c.Position.Render,6===e.UA.ie?c.Shim.Render:null])},{requires:["component/extension","./menu-render"]});
KISSY.add("menu/popupmenu",function(e,c,a,g){var d=a.extend([c.ContentBox,c.Position,c.Align],{handleMouseLeave:function(){this.get("autoHideOnMouseLeave")&&this.get("parent").hideParentMenusBuffer()},handleBlur:function(){d.superclass.handleBlur.apply(this,arguments);this.hide()}},{ATTRS:{focusable:{value:!1},autoHideOnMouseLeave:{},xrender:{value:g}}},{xclass:"popupmenu",priority:20});return d},{requires:["component/extension","./base","./popupmenu-render"]});
KISSY.add("menu/submenu-render",function(e,c){return c.extend({createDom:function(){this.get("el").attr("aria-haspopup","true").append(e.substitute('<span class="{prefixCls}submenu-arrow">\u25ba</span>',{prefixCls:this.get("prefixCls")}))}},{ATTRS:{arrowEl:{},contentEl:{valueFn:function(){return e.all(e.substitute('<span class="{prefixCls}menuitem-content"></span>',{prefixCls:this.get("prefixCls")}))}}},HTML_PARSER:{contentEl:function(a){return a.children("."+this.get("prefixCls")+"menuitem-content")}}})},
{requires:["./menuitem-render"]});
KISSY.add("menu/submenu",function(e,c,a,g,d){function b(b,c){var d=b.get("menu");if(d&&!d.isController)if(c)d=a.create(d,b),b.setInternal("menu",d);else return null;return d}function f(a){var c=b(this),a=a.target,d=this.get("parent");this.get("el");d.containsElement(a)||(c&&c.hide(),this.get("parent").set("highlightedItem",null))}function i(){var a=b(this,1);if(a){this.bindSubMenu();var c=e.clone(a.get("align"));c.node=this.get("el");c.points=c.points||["tr","tl"];a.set("align",c);a.show();this.get("el").attr("aria-haspopup",
a.get("el").attr("id"))}}function j(){var a=b(this);a&&a.hide()}function l(a){a.newVal&&(this.clearSubMenuTimers(),this.get("parent").set("highlightedItem",this));a.stopPropagation()}function h(a){var c=b(this);c&&c.hide();a.stopPropagation()}var k=c.KeyCodes,n=e.Env.host.document,m=g.extend([a.DecorateChild],{bindSubMenu:function(){var a=this,b=a.get("menu"),d=a.get("parent");d&&(d.on("hide",h,a),d.__bindDocClickToHide||(c.on(n,"click",f,a),d.__bindDocClickToHide=1,b.__bindDocClickToHide=1),b.on("afterActiveItemChange",
function(a){d.set("activeItem",a.newVal);a.stopPropagation()}),b.on("afterHighlightedItemChange",function(b){b.newVal&&a.set("highlighted",true);b.stopPropagation()}),a.bindSubMenu=e.noop);b.on("beforeHighlightedItemChange",l,a)},handleMouseEnter:function(a){if(m.superclass.handleMouseEnter.call(this,a))return!0;this.clearSubMenuTimers();this.showTimer_=e.later(i,1E3*this.get("menuDelay"),!1,this)},_onSetHighlighted:function(a){a||(this.dismissTimer_=e.later(j,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);m.superclass.performActionInternal.apply(this,arguments)},handleKeydown:function(a){var d=b(this),f=d&&d.get("visible"),e=a.keyCode;if(f){if(!d.handleKeydown(a))if(e==k.LEFT)j.call(this),this.get("parent").set("activeItem",this);else return}else if(e==k.RIGHT){if(i.call(this),d=b(this))a=
d.get("children"),a[0]&&d.set("highlightedItem",a[0])}else{if(a.keyCode==c.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 c=b(this);return c&&
c.containsElement(a)},decorateChildrenInternal:function(a,b){b.css("visibility","hidden");e.one(b[0].ownerDocument.body).prepend(b);this.setInternal("menu",new a({srcNode:b,prefixCls:this.get("prefixCls")}))},destructor:function(){var a=this.get("parent"),d=b(this);this.clearSubMenuTimers();d&&d.__bindDocClickToHide&&(d.__bindDocClickToHide=0,c.remove(n,"click",f,this));a&&a.detach("hide",h,this);d&&d.destroy&&d.destroy()}},{ATTRS:{menuDelay:{value:0.15},menu:{setter:function(b){b instanceof a.Controller&&
b.setInternal("parent",this)}},defaultChildXClass:{value:"popupmenu"},decorateChildCls:{valueFn:function(){return this.get("prefixCls")+"popupmenu"}},xrender:{value:d}}},{xclass:"submenu",priority:20});return m},{requires:["event","component/base","./menuitem","./submenu-render"]});
