EOS/Scripts/kendo/2015.3.1111/kendo.multiselect.min.js
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

9 lines
15 KiB
JavaScript

/*
* Kendo UI v2015.3.1111 (http://www.telerik.com/kendo-ui)
* Copyright 2015 Telerik AD. All rights reserved.
*
* Kendo UI commercial licenses may be obtained at
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
* If you do not own a commercial license, this file shall be governed by the trial license terms.
*/
!function(e,define){define(["./kendo.list.min","./kendo.mobile.scroller.min"],e)}(function(){return function(e,t){function n(e,t){var n;if(null===e&&null!==t||null!==e&&null===t)return!1;if(n=e.length,n!==t.length)return!1;for(;n--;)if(e[n]!==t[n])return!1;return!0}var i=window.kendo,o=i.ui,r=o.List,s=i.keys,a=i._activeElement,l=i.data.ObservableArray,c=e.proxy,u="id",d="li",h="accept",f="filter",p="rebind",g="open",m="close",v="change",_="progress",w="select",b="aria-disabled",y="aria-readonly",x="k-state-focused",k="k-loading-hidden",C="k-state-hover",S="k-state-disabled",T="disabled",D="readonly",A=".kendoMultiSelect",E="click"+A,M="keydown"+A,P="mouseenter"+A,I="mouseleave"+A,R=P+" "+I,B=/"/g,z=e.isArray,L=["font-family","font-size","font-stretch","font-style","font-weight","letter-spacing","text-transform","line-height"],F=r.extend({init:function(t,n){var o,s,a=this;a.ns=A,r.fn.init.call(a,t,n),a._optionsMap={},a._customOptions={},a._wrapper(),a._tagList(),a._input(),a._textContainer(),a._loader(),a._tabindex(a.input),t=a.element.attr("multiple","multiple").hide(),n=a.options,n.placeholder||(n.placeholder=t.data("placeholder")),o=t.attr(u),o&&(a._tagID=o+"_tag_active",o+="_taglist",a.tagList.attr(u,o)),a._aria(o),a._dataSource(),a._ignoreCase(),a._popup(),a._tagTemplate(),a._initList(),a._reset(),a._enable(),a._placeholder(),n.autoBind?a.dataSource.fetch():n.value&&a._preselect(n.value),s=e(a.element).parents("fieldset").is(":disabled"),s&&a.enable(!1),i.notify(a)},_preselect:function(t,n){var o=this;z(t)||t instanceof i.data.ObservableArray||(t=[t]),(e.isPlainObject(t[0])||t[0]instanceof i.data.ObservableObject||!o.options.dataValueField)&&(o.dataSource.data(t),o.value(n||o._initialValues),o._retrieveData=!0)},options:{name:"MultiSelect",tagMode:"multiple",enabled:!0,autoBind:!0,autoClose:!0,highlightFirst:!0,dataTextField:"",dataValueField:"",filter:"startswith",ignoreCase:!0,minLength:0,delay:100,value:null,maxSelectedItems:null,placeholder:"",height:200,animation:{},virtual:!1,itemTemplate:"",tagTemplate:"",groupTemplate:"#:data#",fixedGroupTemplate:"#:data#"},events:[g,m,v,w,"filtering","dataBinding","dataBound"],setDataSource:function(e){this.options.dataSource=e,this._dataSource(),this.listView.setDataSource(this.dataSource),this.options.autoBind&&this.dataSource.fetch()},setOptions:function(e){var t=this._listOptions(e);r.fn.setOptions.call(this,e),this._normalizeOptions(t),this.listView.setOptions(t),this._accessors(),this._aria(this.tagList.attr(u)),this._tagTemplate()},currentTag:function(e){var n=this;return e===t?n._currentTag:(n._currentTag&&(n._currentTag.removeClass(x).removeAttr(u),n.input.removeAttr("aria-activedescendant")),e&&(e.addClass(x).attr(u,n._tagID),n.input.attr("aria-activedescendant",n._tagID)),n._currentTag=e,t)},dataItems:function(){return this.listView.selectedDataItems()},destroy:function(){var e=this,t=e.ns;clearTimeout(e._busy),clearTimeout(e._typingTimeout),e.wrapper.off(t),e.tagList.off(t),e.input.off(t),r.fn.destroy.call(e)},_activateItem:function(){r.fn._activateItem.call(this),this.currentTag(null)},_normalizeOptions:function(e){var t=this.options.itemTemplate||this.options.template,n=e.itemTemplate||t||e.template;n||(n="#:"+i.expr(e.dataTextField,"data")+"#"),e.template=n},_initList:function(){var t=this,n=t.options.virtual,o=!!n,r=c(t._listBound,t),s={autoBind:!1,selectable:"multiple",dataSource:t.dataSource,click:c(t._click,t),change:c(t._listChange,t),activate:c(t._activateItem,t),deactivate:c(t._deactivateItem,t),dataBinding:function(){t.trigger("dataBinding"),t._angularItems("cleanup")},dataBound:r,listBound:r,selectedItemChange:c(t._selectedItemChange,t)};s=e.extend(t._listOptions(),s,"object"==typeof n?n:{}),t._normalizeOptions(s),t.listView=o?new i.ui.VirtualList(t.ul,s):new i.ui.StaticList(t.ul,s),t.listView.bind("click",function(e){e.preventDefault()}),t.listView.value(t._initialValues||t.options.value)},_listChange:function(e){this._state===p&&(this._state="",e.added=[]),this._selectValue(e.added,e.removed)},_selectedItemChange:function(e){var t,n,i=e.items;for(n=0;i.length>n;n++)t=i[n],this.tagList.children().eq(t.index).children("span:first").html(this.tagTextTemplate(t.item))},_wrapperMousedown:function(t){var n=this,o="input"!==t.target.nodeName.toLowerCase(),r=e(t.target),s=r.hasClass("k-select")||r.hasClass("k-icon");s&&(s=!r.closest(".k-select").children(".k-i-arrow-s").length),!o||s&&i.support.mobileOS||t.preventDefault(),s||(n.input[0]!==a()&&o&&n.input.focus(),0===n.options.minLength&&n.open())},_inputFocus:function(){this._placeholder(!1),this.wrapper.addClass(x)},_inputFocusout:function(){var e=this;clearTimeout(e._typingTimeout),e.wrapper.removeClass(x),e._placeholder(!e.listView.selectedDataItems()[0],!0),e.close(),e._state===f&&(e._state=h,e.listView.filter(!1),e.listView.skipUpdate(!0)),e.element.blur()},_removeTag:function(e){var n,i=this,o=i._state,r=e.index(),s=i.listView,a=s.value()[r],l=i._customOptions[a];l!==t||o!==h&&o!==f||(l=i._optionsMap[a]),l!==t?(n=i.element[0].children[l],n.removeAttribute("selected"),n.selected=!1,s.removeAt(r),e.remove()):s.select(s.select()[r]),i.currentTag(null),i._change(),i._close()},_tagListClick:function(t){var n=e(t.currentTarget);n.children(".k-i-arrow-s").length||this._removeTag(n.closest(d))},_editable:function(t){var n=this,i=t.disable,o=t.readonly,r=n.wrapper.off(A),s=n.tagList.off(A),a=n.element.add(n.input.off(A));o||i?(i?r.addClass(S):r.removeClass(S),a.attr(T,i).attr(D,o).attr(b,i).attr(y,o)):(r.removeClass(S).on(R,n._toggleHover).on("mousedown"+A+" touchend"+A,c(n._wrapperMousedown,n)),n.input.on(M,c(n._keydown,n)).on("paste"+A,c(n._search,n)).on("focus"+A,c(n._inputFocus,n)).on("focusout"+A,c(n._inputFocusout,n)),a.removeAttr(T).removeAttr(D).attr(b,!1).attr(y,!1),s.on(P,d,function(){e(this).addClass(C)}).on(I,d,function(){e(this).removeClass(C)}).on(E,"li.k-button .k-select",c(n._tagListClick,n)))},_close:function(){var e=this;e.options.autoClose?e.close():e.popup.position()},_filterSource:function(e,t){t||(t=this._retrieveData),this._retrieveData=!1,r.fn._filterSource.call(this,e,t)},close:function(){this.popup.close()},open:function(){var e=this;e._request&&(e._retrieveData=!1),e._retrieveData||!e.listView.isBound()||e._state===h?(e._open=!0,e._state=p,e.listView.filter(!1),e.listView.skipUpdate(!0),e._filterSource()):e._allowSelection()&&(e.popup.open(),e._focusItem())},toggle:function(e){e=e!==t?e:!this.popup.visible(),this[e?g:m]()},refresh:function(){this.listView.refresh()},_listBound:function(){var e=this,n=e.dataSource.flatView(),i=e.dataSource.page(),o=n.length;e._angularItems("compile"),e._render(n),e._calculateGroupPadding(e._height(o)),e._open&&(e._open=!1,e.toggle(o)),e.popup.position(),!e.options.highlightFirst||i!==t&&1!==i||e.listView.focusFirst(),e._touchScroller&&e._touchScroller.reset(),e._hideBusy(),e._makeUnselectable(),e.trigger("dataBound")},search:function(e){var t,n,i=this,o=i.options,r=o.ignoreCase,s=o.filter,a=o.dataTextField,l=i.input.val();o.placeholder===l&&(l=""),clearTimeout(i._typingTimeout),e="string"==typeof e?e:l,n=e.length,(!n||n>=o.minLength)&&(i.listView.filter(!0),i._state=f,i._open=!0,t={value:r?e.toLowerCase():e,field:a,operator:s,ignoreCase:r},i._filterSource(t))},value:function(e){var n=this,i=n.listView.value().slice(),o=n.options.maxSelectedItems;return e===t?i:(e=n._normalizeValues(e),null!==o&&e.length>o&&(e=e.slice(0,o)),n.listView.value(e),n._old=e,n._fetchData(),t)},_setOption:function(e,t){var n=this.element[0].children[this._optionsMap[e]];n&&(t?n.setAttribute("selected","selected"):n.removeAttribute("selected"),n.selected=t)},_fetchData:function(){var e=this,t=!!e.dataSource.view().length,n=0===e.listView.value().length;n||e._request||(e._retrieveData||!e._fetch&&!t)&&(e._fetch=!0,e._retrieveData=!1,e.dataSource.read().done(function(){e._fetch=!1}))},_dataSource:function(){var e=this,t=e.element,n=e.options,o=n.dataSource||{};o=z(o)?{data:o}:o,o.select=t,o.fields=[{field:n.dataTextField},{field:n.dataValueField}],e.dataSource&&e._refreshHandler?e._unbindDataSource():e._progressHandler=c(e._showBusy,e),e.dataSource=i.data.DataSource.create(o).bind(_,e._progressHandler)},_reset:function(){var t=this,n=t.element,i=n.attr("form"),o=i?e("#"+i):n.closest("form");o[0]&&(t._resetHandler=function(){setTimeout(function(){t.value(t._initialValues),t._placeholder()})},t._form=o.on("reset",t._resetHandler))},_initValue:function(){var e=this.options.value||this.element.val();this._old=this._initialValues=this._normalizeValues(e)},_normalizeValues:function(t){var n=this;return null===t?t=[]:t&&e.isPlainObject(t)?t=[n._value(t)]:t&&e.isPlainObject(t[0])?t=e.map(t,function(e){return n._value(e)}):z(t)||t instanceof l||(t=[t]),t},_change:function(){var e=this,t=e.value();n(t,e._old)||(e._old=t.slice(),e.trigger(v),e.element.trigger(v))},_click:function(e){var n=e.item;return this.trigger(w,{item:n})?(this._close(),t):(this._select(n),this._change(),this._close(),t)},_keydown:function(n){var o=this,r=n.keyCode,a=o._currentTag,l=o.listView.focus(),c=o.input.val(),u=i.support.isRtl(o.wrapper),d=o.popup.visible();if(r===s.DOWN){if(n.preventDefault(),!d)return o.open(),l||this.listView.focusFirst(),t;l?(this.listView.focusNext(),this.listView.focus()||this.listView.focusLast()):this.listView.focusFirst()}else if(r===s.UP)d&&(l&&this.listView.focusPrev(),this.listView.focus()||o.close()),n.preventDefault();else if(r===s.LEFT&&!u||r===s.RIGHT&&u)c||(a=a?a.prev():e(o.tagList[0].lastChild),a[0]&&o.currentTag(a));else if(r===s.RIGHT&&!u||r===s.LEFT&&u)!c&&a&&(a=a.next(),o.currentTag(a[0]?a:null));else if(r===s.ENTER&&d){if(l){if(o.trigger(w,{item:l}))return o._close(),t;o._select(l)}o._change(),o._close(),n.preventDefault()}else r===s.ESC?(d?n.preventDefault():o.currentTag(null),o.close()):r===s.HOME?d?this.listView.focusFirst():c||(a=o.tagList[0].firstChild,a&&o.currentTag(e(a))):r===s.END?d?this.listView.focusLast():c||(a=o.tagList[0].lastChild,a&&o.currentTag(e(a))):r!==s.DELETE&&r!==s.BACKSPACE||c?(clearTimeout(o._typingTimeout),setTimeout(function(){o._scale()}),o._search()):(r!==s.BACKSPACE||a||(a=e(o.tagList[0].lastChild)),a&&a[0]&&o._removeTag(a))},_hideBusy:function(){var e=this;clearTimeout(e._busy),e.input.attr("aria-busy",!1),e._loading.addClass(k),e._request=!1,e._busy=null},_showBusyHandler:function(){this.input.attr("aria-busy",!0),this._loading.removeClass(k)},_showBusy:function(){var e=this;e._request=!0,e._busy||(e._busy=setTimeout(c(e._showBusyHandler,e),100))},_placeholder:function(e,n){var o=this,r=o.input,s=a();e===t&&(e=!1,r[0]!==s&&(e=!o.listView.selectedDataItems()[0])),o._prev="",r.toggleClass("k-readonly",e).val(e?o.options.placeholder:""),r[0]!==s||n||i.caret(r[0],0,0),o._scale()},_scale:function(){var e,t=this,n=t.wrapper,i=n.width(),o=t._span.text(t.input.val());n.is(":visible")?e=o.width()+25:(o.appendTo(document.documentElement),i=e=o.width()+25,o.appendTo(n)),t.input.width(e>i?i:e)},_option:function(e,n,o){var r="<option";return e!==t&&(e+="",-1!==e.indexOf('"')&&(e=e.replace(B,"&quot;")),r+=' value="'+e+'"'),o&&(r+=" selected"),r+=">",n!==t&&(r+=i.htmlEncode(n)),r+="</option>"},_render:function(e){var t,n,i,o,r,s,a=this.listView.selectedDataItems(),l=this.listView.value(),c=e.length,u="";for(l.length!==a.length&&(a=this._buildSelectedItems(l)),r={},s={},o=0;c>o;o++)n=e[o],i=this._value(n),t=this._selectedItemIndex(i,a),-1!==t&&a.splice(t,1),s[i]=o,u+=this._option(i,this._text(n),-1!==t);if(a.length)for(o=0;a.length>o;o++)n=a[o],i=this._value(n),r[i]=c,s[i]=c,c+=1,u+=this._option(i,this._text(n),!0);this._customOptions=r,this._optionsMap=s,this.element.html(u)},_buildSelectedItems:function(e){var t,n,i=this.options.dataValueField,o=this.options.dataTextField,r=[];for(n=0;e.length>n;n++)t={},t[i]=e[n],t[o]=e[n],r.push(t);return r},_selectedItemIndex:function(e,t){for(var n=this._value,i=0;t.length>i;i++)if(e===n(t[i]))return i;return-1},_search:function(){var e=this;e._typingTimeout=setTimeout(function(){var t=e.input.val();e._prev!==t&&(e._prev=t,e.search(t))},e.options.delay)},_allowSelection:function(){var e=this.options.maxSelectedItems;return null===e||e>this.listView.value().length},_angularTagItems:function(t){var n=this;n.angular(t,function(){return{elements:n.tagList[0].children,data:e.map(n.dataItems(),function(e){return{dataItem:e}})}})},_selectValue:function(e,t){var n,i,o,r=this,s=r.value(),a=r.dataSource.total(),l=r.tagList,c=r._value;if(r._angularTagItems("cleanup"),"multiple"===r.options.tagMode){for(o=t.length-1;o>-1;o--)n=t[o],l[0].removeChild(l[0].children[n.position]),r._setOption(c(n.dataItem),!1);for(o=0;e.length>o;o++)i=e[o],l.append(r.tagTemplate(i.dataItem)),r._setOption(c(i.dataItem),!0)}else{for((!r._maxTotal||a>r._maxTotal)&&(r._maxTotal=a),l.html(""),s.length&&l.append(r.tagTemplate({values:s,dataItems:r.dataItems(),maxTotal:r._maxTotal,currentTotal:a})),o=t.length-1;o>-1;o--)r._setOption(c(t[o].dataItem),!1);for(o=0;e.length>o;o++)r._setOption(c(e[o].dataItem),!0)}r._angularTagItems("compile"),r._placeholder()},_select:function(e){var t=this;t._state===p&&(t._state=""),t._allowSelection()&&(this.listView.select(e),t._placeholder(),t._state===f&&(t._state=h,t.listView.filter(!1),t.listView.skipUpdate(!0)))},_input:function(){var t=this,n=t.element[0].accessKey,i=t._innerWrapper.children("input.k-input");i[0]||(i=e('<input class="k-input" style="width: 25px" />').appendTo(t._innerWrapper)),t.element.removeAttr("accesskey"),t._focused=t.input=i.attr({accesskey:n,autocomplete:"off",role:"listbox","aria-expanded":!1})},_tagList:function(){var t=this,n=t._innerWrapper.children("ul");n[0]||(n=e('<ul role="listbox" unselectable="on" class="k-reset"/>').appendTo(t._innerWrapper)),t.tagList=n},_tagTemplate:function(){var e,t=this,n=t.options,o=n.tagTemplate,r=n.dataSource,s="multiple"===n.tagMode;t.element[0].length&&!r&&(n.dataTextField=n.dataTextField||"text",n.dataValueField=n.dataValueField||"value"),e=s?i.template("#:"+i.expr(n.dataTextField,"data")+"#",{useWithBlock:!1}):i.template("#:values.length# item(s) selected"),t.tagTextTemplate=o=o?i.template(o):e,t.tagTemplate=function(e){return'<li class="k-button" unselectable="on"><span unselectable="on">'+o(e)+'</span><span unselectable="on" class="k-select"><span unselectable="on" class="k-icon '+(s?"k-i-close":"k-i-arrow-s")+'">'+(s?"delete":"open")+"</span></span></li>"}},_loader:function(){this._loading=e('<span class="k-icon k-loading '+k+'"></span>').insertAfter(this.input)},_textContainer:function(){var t=i.getComputedStyles(this.input[0],L);t.position="absolute",t.visibility="hidden",t.top=-3333,t.left=-3333,this._span=e("<span/>").css(t).appendTo(this.wrapper)},_wrapper:function(){var t=this,n=t.element,i=n.parent("span.k-multiselect");i[0]||(i=n.wrap('<div class="k-widget k-multiselect k-header" unselectable="on" />').parent(),i[0].style.cssText=n[0].style.cssText,i[0].title=n[0].title,e('<div class="k-multiselect-wrap k-floatwrap" unselectable="on" />').insertBefore(n)),t.wrapper=i.addClass(n[0].className).css("display",""),t._innerWrapper=e(i[0].firstChild)}});o.plugin(F)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()});