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

16 lines
7.0 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,n){return n?t.substring(0,e).split(n).length-1:0}function i(e,t,i){return t.split(i)[n(e,t,i)]}function r(e,t,i,r){var o=t.split(r);return o.splice(n(e,t,r),1,i),r&&""!==o[o.length-1]&&o.push(""),o.join(r)}var o=window.kendo,a=o.support,s=o.caret,l=o._activeElement,u=a.placeholder,c=o.ui,d=c.List,f=o.keys,h=o.data.DataSource,p="aria-disabled",g="aria-readonly",m="k-state-default",v="disabled",_="readonly",y="k-state-focused",b="k-state-selected",w="k-state-disabled",x="k-state-hover",k=".kendoAutoComplete",C="mouseenter"+k+" mouseleave"+k,T=e.proxy,S=d.extend({init:function(t,n){var i,r=this;r.ns=k,n=e.isArray(n)?{dataSource:n}:n,d.fn.init.call(r,t,n),t=r.element,n=r.options,n.placeholder=n.placeholder||t.attr("placeholder"),u&&t.attr("placeholder",n.placeholder),r._wrapper(),r._loader(),r._dataSource(),r._ignoreCase(),t[0].type="text",i=r.wrapper,r._popup(),t.addClass("k-input").on("keydown"+k,T(r._keydown,r)).on("paste"+k,T(r._search,r)).on("focus"+k,function(){r._prev=r._accessor(),r._placeholder(!1),i.addClass(y)}).on("focusout"+k,function(){r._change(),r._placeholder(),i.removeClass(y)}).attr({autocomplete:"off",role:"textbox","aria-haspopup":!0}),r._enable(),r._old=r._accessor(),t[0].id&&t.attr("aria-owns",r.ul[0].id),r._aria(),r._placeholder(),o.notify(r)},options:{name:"AutoComplete",enabled:!0,suggest:!1,template:"",dataTextField:"",minLength:1,delay:200,height:200,filter:"startswith",ignoreCase:!0,highlightFirst:!1,separator:null,placeholder:"",animation:{},value:null},_dataSource:function(){var e=this;e.dataSource&&e._refreshHandler?e._unbindDataSource():(e._refreshHandler=T(e.refresh,e),e._progressHandler=T(e._showBusy,e)),e.dataSource=h.create(e.options.dataSource).bind("change",e._refreshHandler).bind("progress",e._progressHandler)},setDataSource:function(e){this.options.dataSource=e,this._dataSource()},events:["open","close","change","select","dataBinding","dataBound"],setOptions:function(e){d.fn.setOptions.call(this,e),this._template(),this._accessors(),this._aria()},_editable:function(e){var t=this,n=t.element,i=t.wrapper.off(k),r=e.readonly,o=e.disable;r||o?(i.addClass(o?w:m).removeClass(o?m:w),n.attr(v,o).attr(_,r).attr(p,o).attr(g,r)):(i.addClass(m).removeClass(w).on(C,t._toggleHover),n.removeAttr(v).removeAttr(_).attr(p,!1).attr(g,!1))},close:function(){var e=this,t=e._current;t&&t.removeClass(b),e.current(null),e.popup.close()},destroy:function(){var e=this;e.element.off(k),e.wrapper.off(k),d.fn.destroy.call(e)},refresh:function(){var n,i=this,r=i.ul[0],a=i.popup,s=i.options,u=i._data(),c=u.length;i._angularItems("cleanup"),i.trigger("dataBinding"),r.innerHTML=o.render(i.template,u),i._height(c),a.visible()&&a._position(),c&&(s.highlightFirst&&i.current(e(r.firstChild)),s.suggest&&i.suggest(e(r.firstChild))),i._open&&(i._open=!1,n=c?"open":"close",i._typing&&i.element[0]!==l()&&(n="close"),a[n](),i._typing=t),i._touchScroller&&i._touchScroller.reset(),i._makeUnselectable(),i._hideBusy(),i._angularItems("compile"),i.trigger("dataBound")},select:function(e){this._select(e)},search:function(e){var t,n=this,r=n.options,o=r.ignoreCase,a=r.separator;e=e||n._accessor(),n._current=null,clearTimeout(n._typing),a&&(e=i(s(n.element)[0],e,a)),t=e.length,t?t>=n.options.minLength&&(n._open=!0,n._filterSource({value:o?e.toLowerCase():e,operator:r.filter,field:r.dataTextField,ignoreCase:o})):n.popup.close()},suggest:function(e){var i,r=this,o=r._last,a=r._accessor(),u=r.element[0],c=s(u)[0],h=r.options.separator,p=a.split(h),g=n(c,a,h),m=c;return o==f.BACKSPACE||o==f.DELETE?(r._last=t,t):(e=e||"","string"!=typeof e&&(i=d.inArray(e[0],r.ul[0]),e=i>-1?r._text(r._data()[i]):""),0>=c&&(c=a.toLowerCase().indexOf(e.toLowerCase())+1),i=a.substring(0,c).lastIndexOf(h),i=i>-1?c-(i+h.length):c,a=p[g].substring(0,i),e&&(i=e.toLowerCase().indexOf(a.toLowerCase()),i>-1&&(e=e.substring(i+a.length),m=c+e.length,a+=e),h&&""!==p[p.length-1]&&p.push("")),p[g]=a,r._accessor(p.join(h||"")),u===l()&&s(u,c,m),t)},value:function(e){return e===t?this._accessor():(this._accessor(e),this._old=this._accessor(),t)},_accessor:function(e){var n=this,i=n.element[0];return e===t?(e=i.value,i.className.indexOf("k-readonly")>-1&&e===n.options.placeholder?"":e):(i.value=null===e?"":e,n._placeholder(),t)},_accept:function(e){var t=this.element;this._focus(e),s(t,t.val().length)},_keydown:function(t){var n=this,i=n.ul[0],r=t.keyCode,o=n._current,a=n.popup.visible();n._last=r,r===f.DOWN?(a&&n._move(o?o.next():e(i.firstChild)),t.preventDefault()):r===f.UP?(a&&n._move(o?o.prev():e(i.lastChild)),t.preventDefault()):r===f.ENTER||r===f.TAB?(r===f.ENTER&&n.popup.visible()&&t.preventDefault(),n._accept(o)):r===f.ESC?(n.popup.visible()&&t.preventDefault(),n.close()):n._search()},_move:function(e){var t=this;e=e[0]?e:null,t.current(e),t.options.suggest&&t.suggest(e)},_hideBusy:function(){var e=this;clearTimeout(e._busy),e._loading.hide(),e.element.attr("aria-busy",!1),e._busy=null},_showBusy:function(){var e=this;e._busy||(e._busy=setTimeout(function(){e.element.attr("aria-busy",!0),e._loading.show()},100))},_placeholder:function(e){if(!u){var n,i=this,r=i.element,o=i.options.placeholder;if(o){if(n=r.val(),e===t&&(e=!n),e||(o=n!==o?n:""),n===i._old&&!e)return;r.toggleClass("k-readonly",e).val(o),o||r[0]!==document.activeElement||s(r[0],0,0)}}},_search:function(){var e=this;clearTimeout(e._typing),e._typing=setTimeout(function(){e._prev!==e._accessor()&&(e._prev=e._accessor(),e.search())},e.options.delay)},_select:function(t){var n,i,o=this,a=o.options.separator,l=o._data();t=e(t),t[0]&&!t.hasClass(b)&&(i=d.inArray(t[0],o.ul[0]),i>-1&&(l=l[i],n=o._text(l),a&&(n=r(s(o.element)[0],o._accessor(),n,a)),o._accessor(n),o._prev=o._accessor(),o.current(t.addClass(b))))},_loader:function(){this._loading=e('<span class="k-icon k-loading" style="display:none"></span>').insertAfter(this.element)},_toggleHover:function(t){e(t.currentTarget).toggleClass(x,"mouseenter"===t.type)},_wrapper:function(){var e,t=this,n=t.element,i=n[0];e=n.parent(),e.is("span.k-widget")||(e=n.wrap("<span />").parent()),e.attr("tabindex",-1),e.attr("role","presentation"),e[0].style.cssText=i.style.cssText,n.css({width:"100%",height:i.style.height}),t._focused=t.element,t.wrapper=e.addClass("k-widget k-autocomplete k-header").addClass(i.className)}});c.plugin(S)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()});