"),wrapper=$("",{title:item.element.attr("title")});return item.disabled&&this._addClass(li,null,"ui-state-disabled"),this._setText(wrapper,item.label),li.append(wrapper).appendTo(ul)},_setText:function(element,value){value?element.text(value):element.html(" ")},_move:function(direction,event){var item,filter=".ui-menu-item";this.isOpen?item=this.menuItems.eq(this.focusIndex).parent("li"):(item=this.menuItems.eq(this.element[0].selectedIndex).parent("li"),filter+=":not(.ui-state-disabled)"),(item="first"===direction||"last"===direction?item["first"===direction?"prevAll":"nextAll"](filter).eq(-1):item[direction+"All"](filter).eq(0)).length&&this.menuInstance.focus(event,item)},_getSelectedItem:function(){return this.menuItems.eq(this.element[0].selectedIndex).parent("li")},_toggle:function(event){this[this.isOpen?"close":"open"](event)},_setSelection:function(){var selection;this.range&&(window.getSelection?((selection=window.getSelection()).removeAllRanges(),selection.addRange(this.range)):this.range.select(),this.button.focus())},_documentClick:{mousedown:function(event){this.isOpen&&($(event.target).closest(".ui-selectmenu-menu, #"+$.escapeSelector(this.ids.button)).length||this.close(event))}},_buttonEvents:{mousedown:function(){var selection;window.getSelection?(selection=window.getSelection()).rangeCount&&(this.range=selection.getRangeAt(0)):this.range=document.selection.createRange()},click:function(event){this._setSelection(),this._toggle(event)},keydown:function(event){var preventDefault=!0;switch(event.keyCode){case $.ui.keyCode.TAB:case $.ui.keyCode.ESCAPE:this.close(event),preventDefault=!1;break;case $.ui.keyCode.ENTER:this.isOpen&&this._selectFocusedItem(event);break;case $.ui.keyCode.UP:event.altKey?this._toggle(event):this._move("prev",event);break;case $.ui.keyCode.DOWN:event.altKey?this._toggle(event):this._move("next",event);break;case $.ui.keyCode.SPACE:this.isOpen?this._selectFocusedItem(event):this._toggle(event);break;case $.ui.keyCode.LEFT:this._move("prev",event);break;case $.ui.keyCode.RIGHT:this._move("next",event);break;case $.ui.keyCode.HOME:case $.ui.keyCode.PAGE_UP:this._move("first",event);break;case $.ui.keyCode.END:case $.ui.keyCode.PAGE_DOWN:this._move("last",event);break;default:this.menu.trigger(event),preventDefault=!1}preventDefault&&event.preventDefault()}},_selectFocusedItem:function(event){var item=this.menuItems.eq(this.focusIndex).parent("li");item.hasClass("ui-state-disabled")||this._select(item.data("ui-selectmenu-item"),event)},_select:function(item,event){var oldIndex=this.element[0].selectedIndex;this.element[0].selectedIndex=item.index,this.buttonItem.replaceWith(this.buttonItem=this._renderButtonItem(item)),this._setAria(item),this._trigger("select",event,{item:item}),item.index!==oldIndex&&this._trigger("change",event,{item:item}),this.close(event)},_setAria:function(item){item=this.menuItems.eq(item.index).attr("id");this.button.attr({"aria-labelledby":item,"aria-activedescendant":item}),this.menu.attr("aria-activedescendant",item)},_setOption:function(key,value){var icon;"icons"===key&&(icon=this.button.find("span.ui-icon"),this._removeClass(icon,null,this.options.icons.button)._addClass(icon,null,value.button)),this._super(key,value),"appendTo"===key&&this.menuWrap.appendTo(this._appendTo()),"width"===key&&this._resizeButton()},_setOptionDisabled:function(value){this._super(value),this.menuInstance.option("disabled",value),this.button.attr("aria-disabled",value),this._toggleClass(this.button,null,"ui-state-disabled",value),this.element.prop("disabled",value),value?(this.button.attr("tabindex",-1),this.close()):this.button.attr("tabindex",0)},_appendTo:function(){var element=this.options.appendTo;return element=(element=(element=element&&(element.jquery||element.nodeType?$(element):this.document.find(element).eq(0)))&&element[0]?element:this.element.closest(".ui-front, dialog")).length?element:this.document[0].body},_toggleAttr:function(){this.button.attr("aria-expanded",this.isOpen),this._removeClass(this.button,"ui-selectmenu-button-"+(this.isOpen?"closed":"open"))._addClass(this.button,"ui-selectmenu-button-"+(this.isOpen?"open":"closed"))._toggleClass(this.menuWrap,"ui-selectmenu-open",null,this.isOpen),this.menu.attr("aria-hidden",!this.isOpen)},_resizeButton:function(){var width=this.options.width;!1!==width?(null===width&&(width=this.element.show().outerWidth(),this.element.hide()),this.button.outerWidth(width)):this.button.css("width","")},_resizeMenu:function(){this.menu.outerWidth(Math.max(this.button.outerWidth(),this.menu.width("").outerWidth()+1))},_getCreateOptions:function(){var options=this._super();return options.disabled=this.element.prop("disabled"),options},_parseOptions:function(options){var that=this,data=[];options.each(function(index,item){item.hidden||data.push(that._parseOption($(item),index))}),this.items=data},_parseOption:function(option,index){var optgroup=option.parent("optgroup");return{element:option,index:index,value:option.val(),label:option.text(),optgroup:optgroup.attr("label")||"",disabled:optgroup.prop("disabled")||option.prop("disabled")}},_destroy:function(){this._unbindFormResetHandler(),this.menuWrap.remove(),this.button.remove(),this.element.show(),this.element.removeUniqueId(),this.labels.attr("for",this.ids.element)}}])});