kendo-ui-core
Version:
3 lines (2 loc) • 4.54 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("kendo.core.js"),require("kendo.togglebutton.js"),require("kendo.button.js")):"function"==typeof define&&define.amd?define(["kendo.core.min","kendo.togglebutton.min","kendo.button.min"],t):((e="undefined"!=typeof globalThis?globalThis:e||self).kendobuttongroup=e.kendobuttongroup||{},e.kendobuttongroup.js=t())}(this,(function(){return function(e,t){var n=window.kendo,o=n.ui,i=o.Widget,s=o.ToggleButton,d=o.Button,l=n.keys,u=".kendoButtonGroup",r="k-button",a="k-selected",c="k-disabled",f="select",h="aria-disabled",g=".",b="none",m="single",p="multiple",_="focus",k=i.extend({init:function(e,t){var n=this;i.fn.init.call(n,e,t),n.wrapper=n.element,n.selectedIndices=[],n._buttons=n._renderItems(n.options.items),n.element.addClass("k-widget k-button-group").attr("role","group"),n._enable=!0,n.options.enable&&n.options.enabled||(n._enable=!1,n.element.attr(h,!0).addClass(c),n._buttons.forEach((function(e){e.enable(!1)}))),n.options.selection!==b&&n.select(n.options.index),n._attachEvents()},events:[f],options:{name:"ButtonGroup",selection:m,index:-1,enable:!0,enabled:!0,preventKeyNav:!1,size:"medium",rounded:"medium",fillMode:"solid",themeColor:"base"},badge:function(e,t){var o,i,s=this.element,d=isNaN(e)?s.find(e).getKendoToggleButton()||s.find(e).getKendoButton():this._buttons[e],l=t||0===t;if(d){if(!(o=d.badge)&&l)return d._badge({text:n.htmlEncode(t)}),n.htmlEncode(t);if(l)o.text(n.htmlEncode(t));else if(!1===t)return d.badge=null,i=o.element,o.destroy(),void i.empty().remove();return o?o.text():null}},current:function(){return this.element.find(g+a)},destroy:function(){var t=this;t.element.off(u),t.element.find(g+r).each((function(t,n){var o=e(n).getKendoToggleButton()||e(n).getKendoButton();o&&o.destroy()})),i.fn.destroy.call(t)},enable:function(e){void 0===e&&(e=!0),this.element.attr(h,!e).toggleClass(c,!e),this._buttons.forEach((function(t){var n=t.element.hasClass("k-focus")||t.element.is(":focus");t.enable(e),n&&t.element.removeAttr("disabled").addClass("k-focus").trigger("focus")})),this._enable=this.options.enable=e},select:function(t){var n=this,o=-1;this.options.selection!==b&&undefined!==t&&-1!==t&&(o="number"==typeof t?t:t.nodeType?(t=e(t)).index():t.index(),n._buttons[o]&&(n.options.selection===p?t.length>1?t.each((function(t,o){var i=e(o).index();n._buttons[i].toggle(),n._toggleIndex(i)})):(n._buttons[o].toggle(),n._toggleIndex(o)):n._resetIndexes(o)))},_addButton:function(e,t){if(this.options.selection===b)return delete t.selected,new d(e,t);var n=new s(e,t);return n.bind("toggle",this._select.bind(this,e)),n},_attachEvents:function(){this.options.preventKeyNav||this.element.on("keydown"+u,this._keyDown.bind(this))},_keyDown:function(t){var o=e(this.element),i=o.find(g+r),s=o.find(":focus"),d=i.index(s),u=n.support.isRtl(this.element);t.keyCode===l.LEFT&&!u||t.keyCode===l.RIGHT&&u?((0===d?i.eq(i.length-1):e(i[d-1])).trigger(_),t.preventDefault()):(t.keyCode===l.LEFT&&u||t.keyCode===l.RIGHT&&!u)&&((d+1===i.length?i.eq(0):e(i[d+1])).trigger(_),t.preventDefault())},_renderItems:function(t){var o=this,i=o.options,s=o.element.children(),d=[];return s.length>0&&s.each((function(t){var s=e(this),l=s.find("img").addClass("k-image"),u=s.is("[disabled]")||s.hasClass(c),r={badge:n.attrValue(s,"badge"),icon:l[0]?null:n.attrValue(s,"icon"),disabled:u,selected:!u&&s.is(g+a),size:i.size,rounded:i.rounded,fillMode:i.fillMode,themeColor:i.themeColor};d.push(o._addButton(s,r)),r.selected&&o.selectedIndices.push(t)})),t?(t.forEach((function(t,s){var l=t.text?!1===t.encoded?t.text:n.htmlEncode(t.text):"",u=t.url?e("<a href="+t.url+">"):e("<button>");u.html(l),t.attributes&&u.attr(t.attributes),t=e.extend({},t,{size:i.size,rounded:i.rounded,fillMode:i.fillMode,themeColor:i.themeColor}),u.appendTo(o.element),d.push(o._addButton(u,t)),t.selected&&o.selectedIndices.push(s)})),d):d},_resetIndexes:function(e){this.selectedIndices=[],this._buttons.forEach((function(e){e.toggle(!1)})),this._buttons[e].toggle(!0),this.selectedIndices.push(e)},_select:function(e){var t=this.options.selection,n=e.index();this._enable&&!e.is(g+c)&&(t===p?this._toggleIndex(n):t===m&&this._resetIndexes(n),this.trigger(f,{indices:this.selectedIndices,target:e}))},_toggleIndex:function(e){-1===this.selectedIndices.indexOf(e)?this.selectedIndices.push(e):this.selectedIndices.splice(this.selectedIndices.indexOf(e),1)}});o.plugin(k)}(window.kendo.jQuery),kendo}));
//# sourceMappingURL=kendo.buttongroup.min.js.map