(function(b){"function"===typeof define&&define.amd?define(["jquery","./core","./widget","./position","./menu"],b):b(jQuery)})(function(b){return b.widget("ui.selectmenu",{version:"1.11.4",defaultElement:"<select>",options:{appendTo:null,disabled:null,icons:{button:"ui-icon-triangle-1-s"},position:{my:"left top",at:"left bottom",collision:"none"},width:null,change:null,close:null,focus:null,open:null,select:null},_create:function(){var a=this.element.uniqueId().attr("id");this.ids={element:a,button:a+
"-button",menu:a+"-menu"};this._drawButton();this._drawMenu();this.options.disabled&&this.disable()},_drawButton:function(){var a=this;this.label=b("label[for='"+this.ids.element+"']").attr("for",this.ids.button);this._on(this.label,{click:function(a){this.button.focus();a.preventDefault()}});this.element.hide();this.button=b("<span>",{"class":"ui-selectmenu-button ui-widget ui-state-default ui-corner-all",tabindex:this.options.disabled?-1:0,id:this.ids.button,role:"combobox","aria-expanded":"false",
"aria-autocomplete":"list","aria-owns":this.ids.menu,"aria-haspopup":"true"}).insertAfter(this.element);b("<span>",{"class":"ui-icon "+this.options.icons.button}).prependTo(this.button);this.buttonText=b("<span>",{"class":"ui-selectmenu-text"}).appendTo(this.button);this._setText(this.buttonText,this.element.find("option:selected").text());this._resizeButton();this._on(this.button,this._buttonEvents);this.button.one("focusin",function(){a.menuItems||a._refreshMenu()});this._hoverable(this.button);
this._focusable(this.button)},_drawMenu:function(){var a=this;this.menu=b("<ul>",{"aria-hidden":"true","aria-labelledby":this.ids.button,id:this.ids.menu});this.menuWrap=b("<div>",{"class":"ui-selectmenu-menu ui-front"}).append(this.menu).appendTo(this._appendTo());this.menuInstance=this.menu.menu({role:"listbox",select:function(c,b){c.preventDefault();a._setSelection();a._select(b.item.data("ui-selectmenu-item"),c)},focus:function(c,b){var d=b.item.data("ui-selectmenu-item");null!=a.focusIndex&&
d.index!==a.focusIndex&&(a._trigger("focus",c,{item:d}),a.isOpen||a._select(d,c));a.focusIndex=d.index;a.button.attr("aria-activedescendant",a.menuItems.eq(d.index).attr("id"))}}).menu("instance");this.menu.addClass("ui-corner-bottom").removeClass("ui-corner-all");this.menuInstance._off(this.menu,"mouseleave");this.menuInstance._closeOnDocumentClick=function(){return!1};this.menuInstance._isDivider=function(){return!1}},refresh:function(){this._refreshMenu();this._setText(this.buttonText,this._getSelectedItem().text());
this.options.width||this._resizeButton()},_refreshMenu:function(){this.menu.empty();var a;a=this.element.find("option");a.length&&(this._parseOptions(a),this._renderMenu(this.menu,this.items),this.menuInstance.refresh(),this.menuItems=this.menu.find("li").not(".ui-selectmenu-optgroup"),a=this._getSelectedItem(),this.menuInstance.focus(null,a),this._setAria(a.data("ui-selectmenu-item")),this._setOption("disabled",this.element.prop("disabled")))},open:function(a){this.options.disabled||(this.menuItems?
(this.menu.find(".ui-state-focus").removeClass("ui-state-focus"),this.menuInstance.focus(null,this._getSelectedItem())):this._refreshMenu(),this.isOpen=!0,this._toggleAttr(),this._resizeMenu(),this._position(),this._on(this.document,this._documentClick),this._trigger("open",a))},_position:function(){this.menuWrap.position(b.extend({of:this.button},this.options.position))},close:function(a){this.isOpen&&(this.isOpen=!1,this._toggleAttr(),this.range=null,this._off(this.document),this._trigger("close",
a))},widget:function(){return this.button},menuWidget:function(){return this.menu},_renderMenu:function(a,c){var f=this,d="";b.each(c,function(c,e){e.optgroup!==d&&(b("<li>",{"class":"ui-selectmenu-optgroup ui-menu-divider"+(e.element.parent("optgroup").prop("disabled")?" ui-state-disabled":""),text:e.optgroup}).appendTo(a),d=e.optgroup);f._renderItemData(a,e)})},_renderItemData:function(a,c){return this._renderItem(a,c).data("ui-selectmenu-item",c)},_renderItem:function(a,c){var f=b("<li>");c.disabled&&
f.addClass("ui-state-disabled");this._setText(f,c.label);return f.appendTo(a)},_setText:function(a,c){c?a.text(c):a.html("&#160;")},_move:function(a,c){var b,d=".ui-menu-item";this.isOpen?b=this.menuItems.eq(this.focusIndex):(b=this.menuItems.eq(this.element[0].selectedIndex),d+=":not(.ui-state-disabled)");b="first"===a||"last"===a?b["first"===a?"prevAll":"nextAll"](d).eq(-1):b[a+"All"](d).eq(0);b.length&&this.menuInstance.focus(c,b)},_getSelectedItem:function(){return this.menuItems.eq(this.element[0].selectedIndex)},
_toggle:function(a){this[this.isOpen?"close":"open"](a)},_setSelection:function(){var a;this.range&&(window.getSelection?(a=window.getSelection(),a.removeAllRanges(),a.addRange(this.range)):this.range.select(),this.button.focus())},_documentClick:{mousedown:function(a){this.isOpen&&(b(a.target).closest(".ui-selectmenu-menu, #"+this.ids.button).length||this.close(a))}},_buttonEvents:{mousedown:function(){var a;window.getSelection?(a=window.getSelection(),a.rangeCount&&(this.range=a.getRangeAt(0))):
this.range=document.selection.createRange()},click:function(a){this._setSelection();this._toggle(a)},keydown:function(a){var c=!0;switch(a.keyCode){case b.ui.keyCode.TAB:case b.ui.keyCode.ESCAPE:this.close(a);c=!1;break;case b.ui.keyCode.ENTER:this.isOpen&&this._selectFocusedItem(a);break;case b.ui.keyCode.UP:a.altKey?this._toggle(a):this._move("prev",a);break;case b.ui.keyCode.DOWN:a.altKey?this._toggle(a):this._move("next",a);break;case b.ui.keyCode.SPACE:this.isOpen?this._selectFocusedItem(a):
this._toggle(a);break;case b.ui.keyCode.LEFT:this._move("prev",a);break;case b.ui.keyCode.RIGHT:this._move("next",a);break;case b.ui.keyCode.HOME:case b.ui.keyCode.PAGE_UP:this._move("first",a);break;case b.ui.keyCode.END:case b.ui.keyCode.PAGE_DOWN:this._move("last",a);break;default:this.menu.trigger(a),c=!1}c&&a.preventDefault()}},_selectFocusedItem:function(a){var b=this.menuItems.eq(this.focusIndex);b.hasClass("ui-state-disabled")||this._select(b.data("ui-selectmenu-item"),a)},_select:function(a,
b){var f=this.element[0].selectedIndex;this.element[0].selectedIndex=a.index;this._setText(this.buttonText,a.label);this._setAria(a);this._trigger("select",b,{item:a});a.index!==f&&this._trigger("change",b,{item:a});this.close(b)},_setAria:function(a){a=this.menuItems.eq(a.index).attr("id");this.button.attr({"aria-labelledby":a,"aria-activedescendant":a});this.menu.attr("aria-activedescendant",a)},_setOption:function(a,b){"icons"===a&&this.button.find("span.ui-icon").removeClass(this.options.icons.button).addClass(b.button);
this._super(a,b);"appendTo"===a&&this.menuWrap.appendTo(this._appendTo());"disabled"===a&&(this.menuInstance.option("disabled",b),this.button.toggleClass("ui-state-disabled",b).attr("aria-disabled",b),this.element.prop("disabled",b),b?(this.button.attr("tabindex",-1),this.close()):this.button.attr("tabindex",0));"width"===a&&this._resizeButton()},_appendTo:function(){var a=this.options.appendTo;a&&(a=a.jquery||a.nodeType?b(a):this.document.find(a).eq(0));a&&a[0]||(a=this.element.closest(".ui-front"));
a.length||(a=this.document[0].body);return a},_toggleAttr:function(){this.button.toggleClass("ui-corner-top",this.isOpen).toggleClass("ui-corner-all",!this.isOpen).attr("aria-expanded",this.isOpen);this.menuWrap.toggleClass("ui-selectmenu-open",this.isOpen);this.menu.attr("aria-hidden",!this.isOpen)},_resizeButton:function(){var a=this.options.width;a||(a=this.element.show().outerWidth(),this.element.hide());this.button.outerWidth(a)},_resizeMenu:function(){this.menu.outerWidth(Math.max(this.button.outerWidth(),
this.menu.width("").outerWidth()+1))},_getCreateOptions:function(){return{disabled:this.element.prop("disabled")}},_parseOptions:function(a){var c=[];a.each(function(a,d){var g=b(d),e=g.parent("optgroup");c.push({element:g,index:a,value:g.val(),label:g.text(),optgroup:e.attr("label")||"",disabled:e.prop("disabled")||g.prop("disabled")})});this.items=c},_destroy:function(){this.menuWrap.remove();this.button.remove();this.element.show();this.element.removeUniqueId();this.label.attr("for",this.ids.element)}})});