UNPKG

@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.59 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("kendo.core.js"),require("kendo.chip.js"),require("kendo.html.chiplist.js")):"function"==typeof define&&define.amd?define(["exports","kendo.core.min","kendo.chip","kendo.html.chiplist"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Chiplist={}))}(this,(function(e){!function(e){var t=window.kendo,i=t.ui,n=i.Widget,s=t.keys,o=e.isPlainObject,l=e.isEmptyObject,r=".kendoChipList",a=".",d="select",c="remove",m=t.html,h={widget:"k-chip-list",item:"k-chip",selected:"k-selected",disabled:"k-disabled",enabledItemSelector:"k-chip:not(.k-disabled)"},p=n.extend({init:function(t,i){var s=this;i=i||{},n.fn.init.call(s,t,i),m.renderChipList(t,e.extend({},i)),s._selectable=s.options.selectable,s._bindEvents(),s._items()},options:{name:"ChipList",selectable:"none",items:[],fillMode:"solid",rounded:"medium",size:"medium",itemSize:"medium"},events:[d,c],destroy:function(){var e=this;e._keydownProxy&&(e.unbind(e._keydownProxy),e._keydownProxy=null),e._selectProxy&&(e.unbind(e._selectProxy),e._selectProxy=null),e._removeProxy&&(e.unbind(e._removeProxy),e._removeProxy=null),e.element.off(r),e.element.find("[data-role='chip']").each((function(){e._getChipFromElement(this).destroy()})),n.fn.destroy.call(this)},_updateCssClasses:function(){var e=this,i=e.options,n=h;e.element.removeClass((function(t,i){0===i.indexOf("k-")&&e.element.removeClass(i)})),e.element.addClass(n.widget),e.element.addClass(t.getValidCssClass("k-chip-list-","size",i.size))},_getInitializeChipOptions:function(t){var i=this,n=i.options,s=e.extend(t.attributes||{},{tabindex:"-1"});return"none"!==n.selectable&&(s.role="option",s["aria-selected"]=t.selected),(n.removable||t.removable)&&(s["aria-keyshortcuts"]="Enter Delete"),e.extend({fillMode:n.fillMode,size:n.itemSize,rounded:n.rounded,selectable:"none"!==n.selectable,removable:n.removable,remove:i._removeProxy,select:i._selectProxy},t,{attributes:s})},_getChipFromElement:function(t){return e(t).getKendoChip()||e(t).find("[data-role='chip']").getKendoChip()},_items:function(){for(var t,i,n,s,o=this,l=o.options.items,r=0;r<l.length;r++)t=o._getInitializeChipOptions(l[r]),n=e("<span></span>"),o.element.append(n),o._createChip(n,t);(s=o._getFirstNavigatableItem())&&o._applyTabIndex(o.items().index(s)),"single"===o._selectable&&(i=o.items().filter(a+h.selected)).each((function(e,t){if(e!==i.length-1){var n=o._getChipFromElement(t);n&&n.select(!1)}}))},_isItem:function(t){return(t=e(t)).is(a+h.item)&&!!this.element.find(t).length},_applyTabIndex:function(t){var i=this.item(+t?+t:0);this.items().each((function(t,i){e(i).attr("tabindex","-1")})),i.attr("tabindex","0")},_createChip:function(e,t){return e.kendoChip(t)},_bindEvents:function(){var e=this;e._keydownProxy=e._keydown.bind(e),e._selectProxy=e._select.bind(e),e._removeProxy=e._remove.bind(e),e.element.on("keydown"+r,a+h.item,e._keydownProxy)},_select:function(e){var t=e.sender;"none"!=this._selectable?this._triggerSelect(t,e):e.preventDefault()},_triggerSelect:function(e,t){var i,n=this;n.element.is(a+h.disabled)||n.trigger(d,{originalEvent:t,item:e})||"single"===n._selectable&&(i=n.select()).length>0&&i.each((function(t,i){var s=n._getChipFromElement(i);s&&s!==e&&s.select(!1)}))},_remove:function(e){var t=e.sender;this.trigger(c,{originalEvent:e,item:e.sender})||this._removeItem(t)},_removeItem:function(e){if(e){var t=e.wrapper;e.destroy(),t.remove(),this._focusNavigatableItem()}},_keydown:function(t){var i=e(t.target).closest(a+h.item),n=t.keyCode;n!==s.LEFT&&n!==s.RIGHT||this._focusNavigatableItem(n,i)},_focusNavigatableItem:function(e,t){var i=this,n=i._getNavigatableItem(e,t);n&&(i._applyTabIndex(i.items().index(n)),n.trigger("focus"))},_getFirstNavigatableItem:function(){return this.items().filter(a+h.enabledItemSelector).first()},_getLastNavigatableItem:function(){return this.items().filter(a+h.enabledItemSelector).last()},_getNavigatableItem:function(e,t){var i;return i=t||this._getFirstNavigatableItem(),e===s.LEFT&&t&&(i=t.prevAll(a+h.enabledItemSelector).first()),e===s.RIGHT&&t&&(i=t.nextAll(a+h.enabledItemSelector).first()),i.length?i:null},items:function(){return this.element.children()},select:function(e,t){var i,n=this,s=n.items().filter(a+h.selected);if(!e)return s;t=!1!==t,(i=n._getChipFromElement(e))&&("single"===n._selectable&&(s=n.select()).length>0&&s.each((function(t,i){var s=n._getChipFromElement(i);s&&s!==e&&s.select(!1)})),i.select(t))},enable:function(e,t){var i=this._getChipFromElement(e);t=!1!==t,i&&i.enable(t)},item:function(e){return isNaN(e)?null:this.items().eq(e)},itemById:function(e){return this.element.find("#"+e)},add:function(t,i){var n,s,r=this,a="append",d=r.element;i&&r._isItem(i)&&(a="before",d=e(i)),(n=r._getChipFromElement(t))?("none"!==r._selectable&&n.wrapper.attr("role","option"),d[a](n.wrapper)):t&&o(t)&&!l(t)&&(s=e("<span></span>"),d[a](s),r._createChip(s,r._getInitializeChipOptions(t)))},remove:function(e){e&&this._isItem(e)&&(t.destroy(e),e.remove(),this._focusNavigatableItem())},setOptions:function(e){var t=this;n.fn.setOptions.call(this,e),t._updateCssClasses(),e.items&&(t.element.empty(),t._items())}});i.plugin(p)}(window.kendo.jQuery);var t=kendo;e.__meta__={id:"chiplist",name:"ChipList",category:"web",docsCategory:"navigation",description:"The ChipList component.",depends:["core","chip","html.chiplist"]},e.default=t,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=kendo.chiplist.min.js.map