template.js.base.selectmenu.min.js Maven / Gradle / Ivy
'use strict';(function(b){"function"===typeof define&&define.amd?define("jquery ./menu ../escape-selector ../form-reset-mixin ../keycode ../labels ../position ../unique-id ../version ../widget".split(" "),b):b(jQuery)})(function(b){return b.widget("ui.selectmenu",[b.ui.formResetMixin,{version:"1.12.1",defaultElement:"\x3cselect\x3e",options:{appendTo:null,classes:{"ui-selectmenu-button-open":"ui-corner-top","ui-selectmenu-button-closed":"ui-corner-all"},disabled:null,icons:{button:"ui-icon-triangle-1-s"},
position:{my:"left top",at:"left bottom",collision:"none"},width:!1,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._bindFormResetHandler();this._rendered=!1;this.menuItems=b()},_drawButton:function(){var a,c=this,d=this._parseOption(this.element.find("option:selected"),this.element[0].selectedIndex);this.labels=this.element.labels().attr("for",
this.ids.button);this._on(this.labels,{click:function(a){this.button.focus();a.preventDefault()}});this.element.hide();this.button=b("\x3cspan\x3e",{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",title:this.element.attr("title")}).insertAfter(this.element);this._addClass(this.button,"ui-selectmenu-button ui-selectmenu-button-closed","ui-button ui-widget");a=b("\x3cspan\x3e").appendTo(this.button);
this._addClass(a,"ui-selectmenu-icon","ui-icon "+this.options.icons.button);this.buttonItem=this._renderButtonItem(d).appendTo(this.button);!1!==this.options.width&&this._resizeButton();this._on(this.button,this._buttonEvents);this.button.one("focusin",function(){c._rendered||c._refreshMenu()})},_drawMenu:function(){var a=this;this.menu=b("\x3cul\x3e",{"aria-hidden":"true","aria-labelledby":this.ids.button,id:this.ids.menu});this.menuWrap=b("\x3cdiv\x3e").append(this.menu);this._addClass(this.menuWrap,
"ui-selectmenu-menu","ui-front");this.menuWrap.appendTo(this._appendTo());this.menuInstance=this.menu.menu({classes:{"ui-menu":"ui-corner-bottom"},role:"listbox",select:function(c,b){c.preventDefault();a._setSelection();a._select(b.item.data("ui-selectmenu-item"),c)},focus:function(c,b){var e=b.item.data("ui-selectmenu-item");null!=a.focusIndex&&e.index!==a.focusIndex&&(a._trigger("focus",c,{item:e}),a.isOpen||a._select(e,c));a.focusIndex=e.index;a.button.attr("aria-activedescendant",a.menuItems.eq(e.index).attr("id"))}}).menu("instance");
this.menuInstance._off(this.menu,"mouseleave");this.menuInstance._closeOnDocumentClick=function(){return!1};this.menuInstance._isDivider=function(){return!1}},refresh:function(){this._refreshMenu();this.buttonItem.replaceWith(this.buttonItem=this._renderButtonItem(this._getSelectedItem().data("ui-selectmenu-item")||{}));null===this.options.width&&this._resizeButton()},_refreshMenu:function(){var a;a=this.element.find("option");this.menu.empty();this._parseOptions(a);this._renderMenu(this.menu,this.items);
this.menuInstance.refresh();this.menuItems=this.menu.find("li").not(".ui-selectmenu-optgroup").find(".ui-menu-item-wrapper");this._rendered=!0;a.length&&(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._rendered?(this._removeClass(this.menu.find(".ui-state-active"),null,"ui-state-active"),this.menuInstance.focus(null,this._getSelectedItem())):
this._refreshMenu(),this.menuItems.length&&(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},_renderButtonItem:function(a){var c=
b("\x3cspan\x3e");this._setText(c,a.label);this._addClass(c,"ui-selectmenu-text");return c},_renderMenu:function(a,c){var d=this,e="";b.each(c,function(c,f){var g;f.optgroup!==e&&(g=b("\x3cli\x3e",{text:f.optgroup}),d._addClass(g,"ui-selectmenu-optgroup","ui-menu-divider"+(f.element.parent("optgroup").prop("disabled")?" ui-state-disabled":"")),g.appendTo(a),e=f.optgroup);d._renderItemData(a,f)})},_renderItemData:function(a,c){return this._renderItem(a,c).data("ui-selectmenu-item",c)},_renderItem:function(a,
c){var d=b("\x3cli\x3e"),e=b("\x3cdiv\x3e",{title:c.element.attr("title")});c.disabled&&this._addClass(d,null,"ui-state-disabled");this._setText(e,c.label);return d.append(e).appendTo(a)},_setText:function(a,c){c?a.text(c):a.html("\x26#160;")},_move:function(a,c){var b,e=".ui-menu-item";this.isOpen?b=this.menuItems.eq(this.focusIndex).parent("li"):(b=this.menuItems.eq(this.element[0].selectedIndex).parent("li"),e+=":not(.ui-state-disabled)");b="first"===a||"last"===a?b["first"===a?"prevAll":"nextAll"](e).eq(-1):
b[a+"All"](e).eq(0);b.length&&this.menuInstance.focus(c,b)},_getSelectedItem:function(){return this.menuItems.eq(this.element[0].selectedIndex).parent("li")},_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, #"+b.ui.escapeSelector(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 c=
this.menuItems.eq(this.focusIndex).parent("li");c.hasClass("ui-state-disabled")||this._select(c.data("ui-selectmenu-item"),a)},_select:function(a,c){var b=this.element[0].selectedIndex;this.element[0].selectedIndex=a.index;this.buttonItem.replaceWith(this.buttonItem=this._renderButtonItem(a));this._setAria(a);this._trigger("select",c,{item:a});a.index!==b&&this._trigger("change",c,{item:a});this.close(c)},_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){if("icons"===a){var d=this.button.find("span.ui-icon");this._removeClass(d,null,this.options.icons.button)._addClass(d,null,b.button)}this._super(a,b);"appendTo"===a&&this.menuWrap.appendTo(this._appendTo());"width"===a&&this._resizeButton()},_setOptionDisabled:function(a){this._super(a);this.menuInstance.option("disabled",a);this.button.attr("aria-disabled",a);this._toggleClass(this.button,null,"ui-state-disabled",
a);this.element.prop("disabled",a);a?(this.button.attr("tabindex",-1),this.close()):this.button.attr("tabindex",0)},_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, dialog"));a.length||(a=this.document[0].body);return a},_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 a=this.options.width;!1===a?this.button.css("width",""):(null===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(){var a=this._super();
a.disabled=this.element.prop("disabled");return a},_parseOptions:function(a){var c=this,d=[];a.each(function(a,h){d.push(c._parseOption(b(h),a))});this.items=d},_parseOption:function(a,b){var d=a.parent("optgroup");return{element:a,index:b,value:a.val(),label:a.text(),optgroup:d.attr("label")||"",disabled:d.prop("disabled")||a.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)}}])});
© 2015 - 2024 Weber Informatics LLC | Privacy Policy