@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
3 lines • 15 kB
JavaScript
/* @license */
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`kendo.list.min.js`),require(`kendo.mobile.scroller.min.js`),require(`kendo.virtuallist.min.js`),require(`kendo.core.min.js`)):typeof define==`function`&&define.amd?define([`exports`,`kendo.list.min`,`kendo.mobile.scroller.min`,`kendo.virtuallist.min`,`kendo.core.min`],t):(e=typeof globalThis<`u`?globalThis:e||self,t((e.kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Autocomplete={}),e.kendo._globals.List,e.kendo._globals.MobileScroller,e.kendo._globals.Virtuallist,e.kendo._globals.Core))})(this,function(e,t,n,r,i){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let a=kendo.jQuery;function o({widget:e,wrapper:t,options:n,prefixInsertBefore:r,suffixInsertAfter:i}){var o=n.prefixOptions,s=n.suffixOptions,c=o.template||o.icon,l=s.template||s.icon,i=i||r,u=n.layoutFlow,d=u?u==`vertical`?`horizontal`:`vertical`:`horizontal`,f=`<span class="k-input-separator k-input-separator-${u==`vertical`?`horizontal`:`vertical`}"></span>`,p,m;o&&c&&(p=t.children(`.k-input-prefix`),p[0]||(n._isInInlineAIPrompt&&(d=u||`horizontal`),p=a(`<span class="k-input-prefix k-input-prefix-${d}" />`),r?p.insertBefore(r):p.prependTo(t)),o.icon&&p.html(kendo.html.renderIcon({icon:o.icon,iconClass:o.iconClass})),o.template&&p.html(kendo.template(o.template)({})),o.separator&&a(f).insertAfter(p)),s&&l&&(m=t.children(`.k-input-suffix`),m[0]||(m=a(`<span class="k-input-suffix k-input-suffix-${d}" />`).appendTo(t),i?m.insertAfter(i):m.appendTo(t)),s.icon&&m.html(kendo.html.renderIcon({icon:s.icon,iconClass:s.iconClass})),s.template&&m.html(kendo.template(s.template)({})),s.separator&&a(f).insertBefore(m)),e._prefixContainer=p,e._suffixContainer=m}let s={id:`autocomplete`,name:`AutoComplete`,category:`web`,description:`The AutoComplete widget provides suggestions depending on the typed text.It also allows multiple value entries.`,depends:[`list`],features:[{id:`mobile-scroller`,name:`Mobile scroller`,description:`Support for kinetic scrolling in mobile device`,depends:[`mobile.scroller`]},{id:`virtualization`,name:`VirtualList`,description:`Support for virtualization`,depends:[`virtuallist`]}]};(function(e,t){var n=window.kendo,r=n.htmlEncode;n.support;var i=n.caret,a=n._activeElement,s=n.ui,c=s.List,l=n.keys,u=n.data.DataSource,d=`aria-disabled`,f=`aria-readonly`,p=`change`,m=`disabled`,h=`readonly`,g=`k-focus`,_=`k-selected`,v=`k-disabled`,y=`off`,b=`k-hover`,x=`.kendoAutoComplete`,S=`mouseenter`+x+` mouseleave`+x;function C(e,t,n){return n?t.substring(0,e).split(n).length-1:0}function w(e,t,n){return t.split(n)[C(e,t,n)]}function T(e,t,n,r,i){var a=t.split(r);return a.splice(C(e,t,r),1,n),r&&a[a.length-1]!==``&&a.push(``),a.join(i)}var E=c.extend({init:function(t,r){var i=this,a,s;i.ns=x,r=Array.isArray(r)?{dataSource:r}:r,c.fn.init.call(i,t,r),t=i.element,r=i.options,r.placeholder=r.placeholder||t.attr(`placeholder`),r.inputMode=r.inputMode||t.attr(`inputmode`)||`text`,t.attr(`placeholder`,r.placeholder),i._wrapper(),i._clearButton(),i._dataSource(),i._ignoreCase(),t[0].type=`text`,a=i.wrapper,i._popup(),t.addClass(`k-input-inner`).on(`keydown`+x,i._keydown.bind(i)).on(`keypress`+x,i._keypress.bind(i)).on(`input`+x,i._search.bind(i)).on(`paste`+x,i._search.bind(i)).on(`focus`+x,function(e){i._prev=i._accessor(),i._oldText=i._prev,a.addClass(g)}).on(`focusout`+x,function(e){i.filterInput&&e.relatedTarget===i.filterInput[0]||(i._change(),i.close(),a.removeClass(g))}).attr({autocomplete:y,role:`combobox`,"aria-expanded":!1,inputmode:r.inputMode}),i._clear.on(`click`+x+` touchend`+x,i._clearValue.bind(i)),i._clear.on(`mousedown`+x,i._clearValueMouseDownHandler.bind(i)),i._enable(),i._old=i._accessor(),i._initList(),i.options.virtual&&i.listView.one(`listBound`,function(){i._aria()}),i.listView.bind(`dataBound`,function(){i._aria()}),s=e(i.element).parents(`fieldset`).is(`:disabled`),s&&i.enable(!1),i.listView.bind(`click`,function(e){e.preventDefault()}),i._resetFocusItemHandler=i._resetFocusItem.bind(i),o({widget:i,wrapper:i.wrapper,options:i.options,prefixInsertBefore:i._inputValuesContainer,suffixInsertAfter:r.clearButton?i._clear:i.element}),n.notify(i),i._toggleCloseVisibility(),i._applyCssClasses(),r.label&&i._label(),i._aria()},options:{name:`AutoComplete`,enabled:!0,suggest:!1,template:``,groupTemplate:e=>r(e),fixedGroupTemplate:e=>r(e),prefixOptions:{separator:!0},suffixOptions:{separator:!0},dataTextField:``,minLength:1,enforceMinLength:!1,delay:200,height:200,filter:`startswith`,ignoreCase:!0,highlightFirst:!1,separator:null,placeholder:``,animation:{},virtual:!1,value:null,clearButton:!0,autoWidth:!1,popup:null,size:t,fillMode:t,rounded:t,label:null,adaptiveTitle:null,adaptiveTitleSubtitle:null},_clearValueMouseDownHandler:function(e){var t=this;e&&e.currentTarget&&e.currentTarget.classList.contains(`k-clear-value`)?t._clearValueTrigger=!0:t._clearValueTrigger=!1},_onActionSheetCreate:function(){var e=this;e._unboundClick=!0,e.element.on(`click`,function(){e._isEnabled()?e.popup.toggle():e.popup.close()}),e.filterInput&&(e.filterInput.on(`keydown`+x,e._keydown.bind(e)).on(`keypress`+x,e._keypress.bind(e)).on(`input`+x,e._search.bind(e)).on(`paste`+x,e._search.bind(e)).attr({autocomplete:y,role:`combobox`,"aria-expanded":!1}),e.popup.bind(`activate`,()=>{e.filterInput.val(e.element.val()),e.filterInput.trigger(`focus`)}),e.popup.bind(`deactivate`,()=>{e.element.trigger(`focus`)}))},_isEnabled:function(){let e=this,t=e.element,n=t.prop(h)||!!e.element.attr(`readonly`);return!(t.prop(m)||e.element.attr(`disabled`))&&!n},_onCloseButtonPressed:function(){var e=this;e.filterInput&&a()===e.filterInput[0]&&e.element.val(e.filterInput.val())},_popup:function(){c.fn._popup.call(this),this.popup.element.addClass(`k-autocomplete-popup`)},_dataSource:function(){var e=this;e.dataSource&&e._refreshHandler?e._unbindDataSource():(e._progressHandler=e._showBusy,e._errorHandler=e._hideBusy),e.dataSource=u.create(e.options.dataSource).bind(`progress`,e._progressHandler).bind(`error`,e._errorHandler)},setDataSource:function(e){this.options.dataSource=e,this._dataSource(),this.listView.setDataSource(this.dataSource)},events:[`open`,`close`,p,`select`,`filtering`,`dataBinding`,`dataBound`],setOptions:function(e){var t=this._listOptions(e);c.fn.setOptions.call(this,e),this.listView.setOptions(t),this._accessors(),this._aria(),this._clearButton()},_listOptions:function(t){var n=c.fn._listOptions.call(this,e.extend(t,{skipUpdateOnBind:!0}));return n.dataValueField=n.dataTextField,n.selectedItemChange=null,n},_editable:function(e){var t=this,n=t.element,r=t.wrapper.off(x),i=e.readonly,a=e.disable;!i&&!a?(r.removeClass(v).on(S,t._toggleHover),n.prop(m,!1).prop(h,!1).attr(d,!1).attr(f,!1)):(r.addClass(a?v:``).removeClass(a?``:v),n.attr(m,a).attr(h,i).attr(d,a).attr(f,i)),t._toggleCloseVisibility()},close:function(){var e=this,t=e.listView.focus();t&&t.removeClass(_),e.popup.close(),e._deactivateItem()},destroy:function(){var e=this;e.element.off(x),e._clear.off(x),e.wrapper.off(x),e.filterInput&&e.filterInput.off(x),c.fn.destroy.call(e)},refresh:function(){this.listView.refresh()},select:function(e){this._select(e)},search:function(e){let t=this,n=t.options,r=n.ignoreCase,o=t._separator(),s,c,l=t.dataSource.options.accentFoldingFiltering,u=t.filterInput&&a()===t.filterInput[0]?t.filterInput:t.element;e||=t._accessor(),clearTimeout(t._typingTimeout),o&&(e=w(i(u)[0],e,o)),s=e.length,(!n.enforceMinLength&&!s||s>=n.minLength)&&(t._open=!0,t._mute(function(){this.listView.value([])}),c=l?e.toLocaleLowerCase(l):e.toLowerCase(),t._filterSource({value:r?c:e,operator:n.filter,field:n.dataTextField,ignoreCase:r}),t.one(`close`,t._unifySeparators.bind(t))),t._toggleCloseVisibility()},suggest:function(e){var n=this,r=n._last,o=n._accessor(),s=n.value(),u=n.element[0],d=i(u)[0],f=n._separator(),p=o.split(f),m=C(d,o,f),h=d,g,_=n.dataSource.options.accentFoldingFiltering;if(r==l.BACKSPACE||r==l.DELETE){n._last=t;return}if(e||=``,typeof e!=`string`&&(e[0]&&(e=n.dataSource.view()[c.inArray(e[0],n.ul[0])]),e=e?n._text(e):``),d<=0&&(d=(_?o.toLocaleLowerCase(_):o.toLowerCase()).indexOf(_?e.toLocaleLowerCase(_):e.toLowerCase())+1),g=o.substring(0,d).lastIndexOf(n._defaultSeparator()),g=g>-1?d-(g+n._defaultSeparator().length):d,o=p[m].substring(0,g),e&&(e=e.toString(),g=(_?e.toLocaleLowerCase(_):e.toLowerCase()).indexOf(_?o.toLocaleLowerCase(_):o.toLowerCase()),g>-1&&(e=e.substring(g+o.length),h=d+e.length,o+=e),f&&p[p.length-1]!==``&&p.push(``)),p[m]=o,typeof n.options.separator==`object`&&n.options.separator!=null)if(s.length>1){let e=[...s.matchAll(f.source)].pop();e?n._accessor(p.slice(0,-1).join(n._defaultSeparator()||``)+e+p[p.length-1]):n._accessor(p.slice(0,-1).join(n._defaultSeparator()||``))}else n._accessor(p.join(this._defaultSeparator()||``));else n._accessor(p.join(f||``));u===a()&&i(u,d,h)},value:function(e){if(e!==t)this.listView.value(e),this._accessor(e),this._old=this._accessor(),this._oldText=this._accessor();else return this._accessor();this._toggleCloseVisibility(),this._refreshFloatingLabel()},_click:function(e){var t=e.item,n=this,r=n.element,a=n.listView.dataItemByIndex(n.listView.getElementIndex(t));if(e.preventDefault(),n._active=!0,n.trigger(`select`,{dataItem:a,item:t})){n.close();return}n._oldText=r.val(),n._select(t).done(function(){n._blur(),i(r,r.val().length)})},_clearText:e.noop,_highlightFirst:function(){var e=this.options.highlightFirst?0:-1;this.listView.focus(e)},_resetFocusItem:function(){this.options.virtual&&this.listView.scrollTo(0),this._highlightFirst()},_listBound:function(){var e=this,n=e.popup,r=e.options,i=e.dataSource.flatView(),o=i.length,s=e.dataSource._group?e.dataSource._group.length:0,c=e.element[0]===a()||e.filterInput&&e.filterInput[0]===a(),l;e._renderFooter(),e._renderNoData(),e._toggleNoData(!o),e._toggleHeader(!!s&&!!o),e._resizePopup(),n.position(),o&&(r.suggest&&c&&e._inputValue()&&e.suggest(i[0]),e._highlightFirst()),e._open&&(e._open=!1,l=e._allowOpening()?`open`:`close`,e._typingTimeout&&!c&&(l=`close`),o&&(e._resetFocusItem(),r.virtual&&e.popup.unbind(`activate`,e._resetFocusItemHandler).one(`activate`,e._resetFocusItemHandler)),n[l](),e._typingTimeout=t),e._touchScroller&&e._touchScroller.reset(),e._hideBusy(),e.trigger(`dataBound`)},_mute:function(e){this._muted=!0,e.call(this),this._muted=!1},_listChange:function(){(this._active||this.element[0]===a())&&!this._muted&&this._selectValue(this.listView.selectedDataItems()[0])},_selectValue:function(e){var t=this._separator(),n=``;e&&(n=this._text(e)),n===null&&(n=``),t&&(n=T(i(this.element)[0],this._accessor(),n,t,this._defaultSeparator())),this._prev=n,this._accessor(n)},_unifySeparators:function(){return this._accessor(this.value().split(this._separator()).join(this._defaultSeparator())),this},_preselect:function(e,t){this._inputValue(t),this._accessor(e),this._old=this.oldText=this._accessor(),this.listView.setValue(e)},_change:function(){var e=this,t=e._unifySeparators().value(),n=t!==c.unifyType(e._old,typeof t),r=n&&!e._typing,i=e._oldText!==t,o=e._clearValueTrigger;e._old=t,e._oldText=t,e.filterInput&&a()===e.filterInput[0]&&e.element.val(e.filterInput.val()),(r||i)&&!o&&e.element.trigger(p),n&&!o&&e.trigger(p),e.typing=!1,e._toggleCloseVisibility()},_accessor:function(e){var n=this,r=n.filterInput&&a()===n.filterInput[0]?n.filterInput[0]:n.element[0];if(e!==t)r.value=e===null?``:e;else return e=r.value,r.className.indexOf(`k-readonly`)>-1&&e===n.options.placeholder?``:e},_keydown:function(e){var t=this,n=e.keyCode,r=t.listView,i=t.popup.visible(),a=r.focus();if(t._last=n,n===l.DOWN){if(!t._isEnabled())return;i?this._move(a?`focusNext`:`focusFirst`):t.value()&&t._filterSource({value:t.ignoreCase?t.value().toLowerCase():t.value(),operator:t.options.filter,field:t.options.dataTextField,ignoreCase:t.ignoreCase}).done(function(){t._allowOpening()&&(t._resetFocusItem(),t.popup.open())}),e.preventDefault()}else if(n===l.ESC){if(!t._isEnabled())return;i?(e.preventDefault(),t.close()):t._clearValue()}else if(e.altKey&&n===l.UP&&i)e.preventDefault(),t.close();else if(n===l.UP)i&&this._move(a?`focusPrev`:`focusLast`),e.preventDefault();else if(n===l.HOME)this._move(`focusFirst`);else if(n===l.END)this._move(`focusLast`);else if(n===l.ENTER||n===l.TAB){if(n===l.ENTER&&i&&e.preventDefault(),i&&a){var o=r.dataItemByIndex(r.getElementIndex(a));if(t.trigger(`select`,{dataItem:o,item:a}))return;this._select(a)}this._blur()}else if(t.popup.visible()&&(n===l.PAGEDOWN||n===l.PAGEUP)){e.preventDefault();var s=n===l.PAGEDOWN?1:-1;r.scrollWith(s*r.screenHeight())}else t.popup._hovered=!0,t._search()},_keypress:function(){this._oldText=this.element.val(),this._typing=!0},_move:function(e){if(this.listView[e](),this.options.suggest&&this.listView.focus()==null&&e==`focusNext`)this.listView.focus(0),this.suggest(this.listView._view[0].item);else if(this.options.suggest&&this.listView.focus()==null&&e==`focusPrev`){let e=this.listView._view.length-1;this.listView.focus(e),this.suggest(this.listView._view[e].item)}else this.options.suggest&&(e==`focusFirst`||e==`focusLast`)?i(this.element):this.options.suggest&&this.listView.focus()!=null&&this.suggest(this.listView.focus())},_separator:function(){var e=this.options.separator;return e instanceof Array?new RegExp(e.join(`|`),`gi`):e},_defaultSeparator:function(){var e=this.options.separator;return e instanceof Array?e[0]:e},_inputValue:function(){return this.element.val()},_search:function(){var e=this;clearTimeout(e._typingTimeout),e._typingTimeout=setTimeout(function(){e._prev!==e._accessor()&&(e._prev=e._accessor(),e.search())},e.options.delay)},_select:function(e){var t=this;return t._active=!0,t.listView.select(e).done(function(){t._active=!1})},_clearButton:function(){c.fn._clearButton.call(this),this.options.clearButton&&this._clear.insertAfter(this.element)},_toggleHover:function(t){e(t.currentTarget).toggleClass(b,t.type===`mouseenter`)},_toggleCloseVisibility:function(){var e=this.element.is(`:disabled`)||this.element.is(`[readonly]`);this.value()&&!e?this._showClear():this._hideClear()},_wrapper:function(){var e=this,t=e.element,n=t[0],r=t.parent();r.is(`span.k-autocomplete`)||(r=t.wrap(`<span />`).parent()),r.attr(`tabindex`,-1),r[0].style.cssText=n.style.cssText,t.css({width:``,height:n.style.height}),e._focused=e.element,e.wrapper=r.addClass(`k-autocomplete k-input`).addClass(n.className).removeClass(`input-validation-error`)},_clearValue:function(){this._clearValueTrigger=!1,c.fn._clearValue.call(this),this.element.trigger(`focus`)}});s.plugin(E),n.cssProperties.registerPrefix(`AutoComplete`,`k-input-`),n.cssProperties.registerValues(`AutoComplete`,[{prop:`rounded`,values:n.cssProperties.roundedValues.concat([[`full`,`full`]])}])})(window.kendo.jQuery);var c=kendo;e.__meta__=s,e.default=c});
//# sourceMappingURL=kendo.autocomplete.min.js.map