demo20230512/Scripts/kendo/2014.2.716/kendo.multiselect.min.js
2023-05-12 10:20:28 +08:00

16 lines
13 KiB
JavaScript

/**
* Copyright 2014 Telerik AD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
!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}function i(t){var n=t.firstChild;return n&&"none"===n.style.display&&(n=o(n,x)),n?e(n):n}function r(t){var n=t.lastChild;return n&&"none"===n.style.display&&(n=o(n,k)),n?e(n):n}function o(e,t){return e=e[t],e&&"none"===e.style.display&&(e=o(e,t)),e}var a=window.kendo,s=a.ui,l=s.List,u=a.keys,c=a._activeElement,d=a.data.ObservableArray,f=e.proxy,h="id",p="li",g="accept",m="filter",v="open",_="close",y="change",b="progress",w="select",x="nextSibling",k="previousSibling",C=' style="display:none"',T="aria-disabled",S="aria-readonly",F="k-state-focused",D="k-loading-hidden",M="k-state-hover",E="k-state-disabled",O="disabled",A="readonly",z=".kendoMultiSelect",I="click"+z,P="keydown"+z,H="mouseenter"+z,N="mouseleave"+z,L=H+" "+N,B=/"/g,R=e.isArray,W=["font-family","font-size","font-stretch","font-style","font-weight","letter-spacing","text-transform","line-height"],q=l.extend({init:function(t,n){var i,r,o=this;o.ns=z,l.fn.init.call(o,t,n),o._wrapper(),o._tagList(),o._input(),o._textContainer(),o._loader(),o._tabindex(o.input),t=o.element.attr("multiple","multiple").hide(),n=o.options,r=n.value,n.placeholder||(n.placeholder=t.data("placeholder")),i=t.attr(h),i&&(o._tagID=i+"_tag_active",i+="_taglist",o.tagList.attr(h,i)),o._aria(i),o._dataSource(),o._ignoreCase(),o._popup(),o._values=[],o._dataItems=[],o._reset(),o._enable(),o._placeholder(),n.autoBind?o.dataSource.fetch():r&&(R(r)||(r=[r]),(e.isPlainObject(r[0])||!n.dataValueField)&&(o._retrieveData=!0,o.dataSource.data(r),o.value(o._initialValues))),a.notify(o)},options:{name:"MultiSelect",enabled:!0,autoBind:!0,autoClose:!0,highlightFirst:!0,dataTextField:"",dataValueField:"",filter:"startswith",ignoreCase:!0,minLength:0,delay:100,value:null,maxSelectedItems:null,itemTemplate:"",tagTemplate:"",placeholder:"",height:200,animation:{}},events:[v,_,y,w,"dataBinding","dataBound"],setDataSource:function(e){this.options.dataSource=e,this._dataSource(),this.options.autoBind&&this.dataSource.fetch()},setOptions:function(e){l.fn.setOptions.call(this,e),this._template(),this._accessors(),this._aria(this.tagList.attr(h))},current:function(e){return this.currentTag(null),l.fn.current.call(this,e)},currentTag:function(e){var n=this;return e===t?n._currentTag:(n._currentTag&&(n._currentTag.removeClass(F).removeAttr(h),n.input.removeAttr("aria-activedescendant")),e&&(e.addClass(F).attr(h,n._tagID),n.input.attr("aria-activedescendant",n._tagID)),n._currentTag=e,t)},dataItems:function(){return this._dataItems},destroy:function(){var e=this,t=e.ns;e.wrapper.off(t),e.tagList.off(t),e.input.off(t),l.fn.destroy.call(e)},_editable:function(t){var n=this,i=t.disable,r=t.readonly,o=n.wrapper.off(z),a=n.tagList.off(z),s=n.element.add(n.input.off(z));r||i?(i?o.addClass(E):o.removeClass(E),s.attr(O,i).attr(A,r).attr(T,i).attr(S,r)):(o.removeClass(E).on(L,n._toggleHover).on("mousedown"+z,function(e){var t="input"!==e.target.nodeName.toLowerCase();t&&e.preventDefault(),-1===e.target.className.indexOf("k-delete")&&(n.input[0]!==c()&&t&&n.input.focus(),0===n.options.minLength&&n.open())}),n.input.on(P,f(n._keydown,n)).on("paste"+z,f(n._search,n)).on("focus"+z,function(){n._placeholder(!1),o.addClass(F)}).on("focusout"+z,function(){clearTimeout(n._typing),o.removeClass(F),n._placeholder(!n._dataItems[0],!0),n.close(),n._state===m&&(n._state=g),n.element.blur()}),s.removeAttr(O).removeAttr(A).attr(T,!1).attr(S,!1),a.on(H,p,function(){e(this).addClass(M)}).on(N,p,function(){e(this).removeClass(M)}).on(I,".k-delete",function(t){n._unselect(e(t.target).closest(p)),n._change(),n.close()}))},_close:function(){var e=this;e.options.autoClose||!e._visibleItems?e.close():(e.current(e.options.highlightFirst?i(e.ul[0]):null),e.popup._position())},close:function(){this.popup.close(),this.current(null)},open:function(){var e=this;e._request&&(e._retrieveData=!1),!e.ul[0].firstChild||e._state===g||e._retrieveData?(e._state="",e._open=!0,e._retrieveData=!1,e._filterSource()):e._visibleItems&&e._allowSelection()&&(e.popup.open(),e.current(e.options.highlightFirst?i(e.ul[0]):null))},toggle:function(e){e=e!==t?e:!this.popup.visible(),this[e?v:_]()},refresh:function(){var e,t=this,n=null;t.trigger("dataBinding"),e=t._render(t.dataSource.view()),t._height(e),t._setInitialValues&&(t._setInitialValues=!1,t.value(t._initialValues)),t._open&&(t._open=!1,t.toggle(e)),t.popup.visible()&&(t.popup._position(),t.options.highlightFirst&&(n=i(t.ul[0]))),t.current(n),t._touchScroller&&t._touchScroller.reset(),t._makeUnselectable(),t._hideBusy(),t.trigger("dataBound")},search:function(e){var t=this,n=t.options,i=n.ignoreCase,r=n.filter,o=n.dataTextField,a=t.input.val();n.placeholder===a&&(a=""),clearTimeout(t._typing),e="string"==typeof e?e:a,e.length>=n.minLength&&(t._state=m,t._open=!0,t._filterSource({value:i?e.toLowerCase():e,field:o,operator:r,ignoreCase:i}))},value:function(n){var i,r=this,o=e(r.tagList[0].children),a=o.length,s=0;if(n===t)return r._values;if(!r._fetchItems(n)){for(;a>s;s++)r._unselect(o.eq(s));if(null!==n){for(n=R(n)||n instanceof d?n:[n],s=0,a=n.length;a>s;s++)i=r._index(n[s]),i>-1&&r._select(i);r._old=r._values.slice()}}},_dataSource:function(){var e=this,t=e.element,n=e.options,i=n.dataSource||{};i=R(i)?{data:i}:i,i.select=t,i.fields=[{field:n.dataTextField},{field:n.dataValueField}],e.dataSource&&e._refreshHandler?e._unbindDataSource():(e._refreshHandler=f(e.refresh,e),e._progressHandler=f(e._showBusy,e)),e.dataSource=a.data.DataSource.create(i).bind(y,e._refreshHandler).bind(b,e._progressHandler)},_fetchItems:function(n){var i=this,r=e.isArray(n)&&0===n.length;if(!r&&n)return i._fetch||i.ul[0].firstChild?t:(i.dataSource.one(y,function(){i.value(n),i._fetch=!1}),i._fetch=!0,i.dataSource.fetch(),!0)},_reset:function(){var t=this,n=t.element,i=n.attr("form"),r=i?e("#"+i):n.closest("form");r[0]&&(t._resetHandler=function(){setTimeout(function(){t.value(t._initialValues)})},t._form=r.on("reset",t._resetHandler))},_initValue:function(){var e=this,n=e.options.value||e.element.val();null===n?n=[]:(R(n)||(n=[n]),n=e._mapValues(n)),e._old=e._initialValues=n,e._setInitialValues=n[0]!==t},_mapValues:function(t){var n=this;return t&&e.isPlainObject(t[0])&&(t=e.map(t,function(e){return n._value(e)})),t},_change:function(){var e=this,t=e.value();n(t,e._old)||(e._old=t.slice(),e.trigger(y),e.element.trigger(y))},_click:function(n){var i=this,r=e(n.currentTarget);if(!n.isDefaultPrevented()){if(i.trigger(w,{item:r}))return i._close(),t;i._select(r),i._change(),i._close()}},_item:function(e,t){return e=e[t](),e[0]&&!e.is(":visible")&&(e=this._item(e,t)),e},_keydown:function(n){var s=this,l=n.keyCode,c=s._currentTag,d=s._current,f=s.input.val(),h=a.support.isRtl(s.wrapper),p=s.popup.visible();if(l===u.DOWN){if(n.preventDefault(),!p)return s.open(),t;d=d?o(d[0],x):i(s.ul[0]),d&&s.current(e(d))}else if(l===u.UP)p&&(d=d?o(d[0],k):r(s.ul[0]),s.current(e(d)),s._current[0]||s.close()),n.preventDefault();else if(l===u.LEFT&&!h||l===u.RIGHT&&h)f||(c=c?c.prev():e(s.tagList[0].lastChild),c[0]&&s.currentTag(c));else if(l===u.RIGHT&&!h||l===u.LEFT&&h)!f&&c&&(c=c.next(),s.currentTag(c[0]?c:null));else if(l===u.ENTER&&p){if(d){if(s.trigger(w,{item:d}))return s._close(),t;s._select(d)}s._change(),s._close(),n.preventDefault()}else l===u.ESC?(p?n.preventDefault():s.currentTag(null),s.close()):l===u.HOME?p?s.current(i(s.ul[0])):f||(c=s.tagList[0].firstChild,c&&s.currentTag(e(c))):l===u.END?p?s.current(r(s.ul[0])):f||(c=s.tagList[0].lastChild,c&&s.currentTag(e(c))):l!==u.DELETE&&l!==u.BACKSPACE||f?(clearTimeout(s._typing),setTimeout(function(){s._scale()}),s._search()):(l!==u.BACKSPACE||c||(c=e(s.tagList[0].lastChild)),c&&c[0]&&(s._unselect(c),s._change(),s._close()))},_hideBusy:function(){var e=this;clearTimeout(e._busy),e.input.attr("aria-busy",!1),e._loading.addClass(D),e._request=!1,e._busy=null},_showBusy:function(){var e=this;e._request=!0,e._busy||(e._busy=setTimeout(function(){e.input.attr("aria-busy",!0),e._loading.removeClass(D)},100))},_placeholder:function(e,n){var i=this,r=i.input,o=c();e===t&&(e=!1,r[0]!==o&&(e=!i._dataItems[0])),i._prev="",r.toggleClass("k-readonly",e).val(e?i.options.placeholder:""),r[0]!==o||n||a.caret(r[0],0,0),i._scale()},_scale:function(){var e,t=this,n=t.wrapper,i=n.width(),r=t._span.text(t.input.val());n.is(":visible")?e=r.width()+25:(r.appendTo(document.documentElement),i=e=r.width()+25,r.appendTo(n)),t.input.width(e>i?i:e)},_option:function(e,n){var i="<option",r=this._text(e),o=this._value(e);return o!==t&&(o+="",-1!==o.indexOf('"')&&(o=o.replace(B,"&quot;")),i+=' value="'+o+'"'),n&&(i+=' selected="selected"'),i+=">",r!==t&&(i+=a.htmlEncode(r)),i+="</option>"},_render:function(e){for(var t,n,i=this,r=e.length,o=i.itemTemplate,a=i._dataItems.slice(0),s=0,l=0,u="",c="";r>l;l++)t=e[l],n=i._selected(a,t),c+=o(t,l,n),u+=i._option(t,n),n||(s+=1);if(r=a.length)for(l=0;r>l;l++)u+=i._option(a[l],!0);return i.ul[0].innerHTML=c,i.element.html(u),i._visibleItems=s,s},_selected:function(e,n){var i,r=this,o=r._text,a=r._value,s=a(n),l=e.length,u=!1,c=0;for(s===t&&(s=o(n));l>c;c++)if(n=e[c],i=a(n),i===t&&(i=o(n)),i!==t&&i===s){u=!0;break}return u&&e.splice(c,1),u},_search:function(){var e=this;e._typing=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._values.length},_select:function(e){var t,n,i=this,r=i._values;i._allowSelection()&&(isNaN(e)?n=e.hide().data("idx"):(n=e,i.ul[0].children[n].style.display="none"),i.element[0].children[n].selected=!0,t=i.dataSource.view()[n],i.tagList.append(i.tagTemplate(t)),i._dataItems.push(t),r.push(i._dataValue(t)),i._visibleItems-=1,i.currentTag(null),i._placeholder(),i._height(i._visibleItems),i._state===m&&(i._state=g))},_unselect:function(t){var n,i,r,o,a,s=this,l=t.index();if(t.remove(),s.currentTag(null),s._values.splice(l,1),n=s._dataItems.splice(l,1)[0],i=s._dataValue(n),l=s._index(i),-1!==l)e(s.ul[0].children[l]).show(),s.element[0].children[l].selected=!1,s._visibleItems+=1,s._height(s._visibleItems);else for(l=s.dataSource.view().length,r=s.element[0].children,a=r.length;a>l;l++)if(o=r[l],o.value==i){o.selected=!1;break}s._placeholder()},_template:function(){var e,t=this,n=t.options,i=n.itemTemplate,r=n.tagTemplate,o=n.dataSource;t.element[0].length&&!o&&(n.dataTextField=n.dataTextField||"text",n.dataValueField=n.dataValueField||"value"),e=a.template("#:"+a.expr(n.dataTextField,"data")+"#",{useWithBlock:!1}),i=i?a.template(i):e,r=r?a.template(r):e,t.itemTemplate=function(e,t,n){return'<li tabindex="-1" role="option" data-idx="'+t+'" unselectable="on" class="k-item"'+(n?C:"")+">"+i(e)+"</li>"},t.tagTemplate=function(e){return'<li class="k-button" unselectable="on"><span unselectable="on">'+r(e)+'</span><span unselectable="on" class="k-icon k-delete">delete</span></li>'}},_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},_loader:function(){this._loading=e('<span class="k-icon k-loading '+D+'"></span>').insertAfter(this.input)},_textContainer:function(){var t=a.getComputedStyles(this.input[0],W);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,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)}});s.plugin(q)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()});