@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
3 lines (2 loc) • 5.98 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("kendo.core.js"),require("kendo.popup.js"),require("kendo.icons.js")):"function"==typeof define&&define.amd?define(["exports","kendo.core.min","kendo.popup.min","kendo.icons.min"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).kendo=t.kendo||{},t.kendo._globals=t.kendo._globals||{},t.kendo._globals.ButtonMenu={}))}(this,(function(t){!function(t){var e=window.kendo,n=e.ui.Widget,i=".kendoButtonMenu",s=e.ui,o=e.keys,l=e.htmlEncode,a=e.sanitizeLink,r=t.extend,d=".",u="id",p="next",c="k-disabled",f="k-hidden",m="aria-disabled",g="tabindex",h="click",k="menuClick",_="menuOpen",b="menuClose",C="keydown",y="focus",v={down:{origin:"bottom left",position:"top left"},up:{origin:"top left",position:"bottom left"}},$="k-menu-popup",x="k-menu-group",B="k-item k-menu-item",w="k-menu-item",E="k-menu-link-text",H="k-link k-menu-link",P="k-sprite",T="k-image",D={text:null,icon:null,url:null,attributes:null,enabled:!0,hidden:!1,id:null,imageUrl:null,spriteCssClass:null},M=({imageUrl:t})=>""+(t?`<img alt="icon" class="${T}" src="${l(t)}" />`:""),U=({spriteCssClass:t})=>""+(t?`<span class="${P} ${l(t)}"></span>`:""),j=({icon:t})=>`${t?e.ui.icon(l(t)):""}`,O=({text:t})=>""+(t?`<span class="${E}">${l(t)}</span>`:""),I=({imageUrl:t,spriteCssClass:e,icon:n,text:i})=>`<span class="${H}">${M({imageUrl:t})}${U({spriteCssClass:e})}${j({icon:n})}${O({text:i})}</span>`,A=({url:t,imageUrl:e,spriteCssClass:n,icon:i,text:s,attributes:o})=>`<a href="${a(t)}" ${o&&o.target?`target="${o.target}"`:""} class="${H}">${M({imageUrl:e})}${U({spriteCssClass:n})}${j({icon:i})}${O({text:s})}</a>`;function F(e,n){var i=n===p?t.fn.next:t.fn.prev,s=n===p?t.fn.first:t.fn.last,o=i.call(e),l=":kendoFocusable";return o.length||(o=s.call(e.parent().find(d+w))),o.is(l)||!o.length?o:o.find(l).length?s.call(o.find(l)):F(o,n)}var L=n.extend({init:function(t,e){var i=this;n.fn.init.call(i,t,e),i.mainButton=e.mainButton,i._clickHandlers={},i._renderList(),i._initPopup(),i._attachEvents(),i._applyCssClasses(i.list)},options:{name:"ButtonMenu",direction:"down",element:null,items:[],size:"medium"},events:[k,_,b],_renderList:function(){var n=this,i=n.options.items,s=n.element.addClass($),o=n.mainButton.attr(u)||e.guid(),l=t('<ul role="menu"></ul>').addClass(x);n.list=l.appendTo(s),n.list.attr(u,o+"_buttonmenu"),i.forEach(n._renderListItem.bind(n)),n.list.find(d+w+":first-child").addClass("k-first"),n.list.find(d+w+":last-child").addClass("k-last")},_renderListItem:function(n){var i,s,o=this,l=n.attributes?n.attributes.id:null;i=(n=r({},D,n,{enabled:n.enable&&n.enabled})).id||l||e.guid(),s=t('<li id="'+i+'" role="menuitem" class="'+B+'">'+o._renderItemButton(n)+"</li>"),n.click&&(o._clickHandlers[i]=n.click),n.attributes&&(delete n.attributes.target,n.attributes.class&&(s.addClass(n.attributes.class),delete n.attributes.class),s.attr(n.attributes)),n.data&&e.isFunction(n.data)&&s.data(n.data(n)),o.list.append(s),o.enable(n.enabled,s),o._hide(n.hidden,s)},_renderItemButton:function(t){var n=this.options;return n.itemTemplate?e.template(n.itemTemplate)(t):t.url?e.template(A)(t):e.template(I)(t)},_initPopup:function(){var t=this,e=t.options,n=e.direction||"down";t._popup=new s.Popup(t.element,r({},e.popup,{anchor:t.mainButton,isRtl:t._isRtl,toggleTarget:e.toggleTarget,copyAnchorStyles:!1,animation:e.animation,open:t._popupOpenHandler.bind(t),close:t._popupCloseHandler.bind(t),activate:t._popupExpandHandler.bind(t)},v[n]))},_popupOpenHandler:function(t){this.trigger(_)?t.preventDefault():this.list.find(d+w).attr(g,0)},_popupCloseHandler:function(t){this.trigger(b)&&t.preventDefault(),this.list.find(d+w).attr(g,-1)},_popupExpandHandler:function(){this.list.find(":kendoFocusable").first().trigger(y)},adjustPopupWidth:function(t){this.element.css({"min-width":t})},_attachEvents:function(){var t=this;t.list.on(h+i,d+w,t._click.bind(t)).on(C+i,d+w,t.listItemKeydown.bind(t)),t.mainButton.on(C+i,t._keydown.bind(t))},_keydown:function(e){if(!t(e.target).is(d+c)&&!t(e.target).parents(d+c).length)return e.altKey&&e.keyCode===o.DOWN?(this.open(),void e.preventDefault()):void 0},listItemKeydown:function(e){var n=this,i=t(e.target);e.preventDefault(),e.keyCode===o.ESC||e.keyCode===o.TAB||e.altKey&&e.keyCode===o.UP?(n.close(),n.mainButton.trigger(y)):e.keyCode===o.DOWN?F(i,p).trigger(y):e.keyCode===o.UP?F(i,"prev").trigger(y):i.is(d+c)||e.keyCode!==o.SPACEBAR&&e.keyCode!==o.ENTER?e.keyCode===o.HOME?n.list.find(":kendoFocusable").filter(d+w).first().trigger(y):e.keyCode===o.END&&n.list.find(":kendoFocusable").filter(d+w).last().trigger(y):i.trigger(h)},_click:function(e){var n=this,i=t(e.target).closest(d+w),s=i.attr(u);n._clickHandlers[s]&&n._clickHandlers[s](e),n.trigger(k,{id:s,target:i,type:"menu-click",originalEvent:e})},toggle:function(){this._popup.toggle()},enable:function(t,e){(e=e&&e.length?this.list.find(e):this.items()).toggleClass(c,!t),t?e.removeAttr(m):e.attr(m,!t)},_hide:function(t,e){(e=e&&e.length?this.list.find(e):this.items()).toggleClass(f,t)},hide:function(t){this._hide(!0,t)},show:function(t){this._hide(!1,t)},open:function(){0!==this.items().length&&(0!==this.items().filter(`:not(.${f})`).length&&this._popup.open())},close:function(){this._popup.close()},items:function(){return this.list.children(d+w)},destroyPopup:function(){var t=this;t._popup&&(t._popup.destroy(),t._popup=null,t.list.off(i),t.list.remove(),t.list=null)},destroy:function(){var t=this;delete t._clickHandlers,t.destroyPopup(),t.mainButton.off(i),n.fn.destroy.call(t)}});e.cssProperties.registerPrefix("ButtonMenu","k-menu-group-"),s.plugin(L)}(window.kendo.jQuery);var e=kendo;t.__meta__={id:"button.menu",name:"ButtonMenu",category:"web",description:"The popup Menu list part of the SplitButton and the DropDownButton",depends:["core","popup","icons"]},t.default=e,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=kendo.button.menu.min.js.map