16 lines
10 KiB
JavaScript
16 lines
10 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){for(var i,r=0,o=t.length-1;o>r;++r)i=t[r],i in e||(e[i]={}),e=e[i];e[t[o]]=n}var i=window.kendo,r=i.ui,o=r.Select,a=i.support.mobileOS,s=i._activeElement,l=i.keys,u=".kendoDropDownList",c="disabled",d="readonly",f="change",h="k-state-focused",p="k-state-default",g="k-state-disabled",m="aria-disabled",v="aria-readonly",_="k-state-selected",y="mouseenter"+u+" mouseleave"+u,b="tabindex",w="filter",x="accept",k=e.proxy,C=o.extend({init:function(n,r){var a,s,l,c=this,d=r&&r.index;c.ns=u,r=e.isArray(r)?{dataSource:r}:r,o.fn.init.call(c,n,r),c._focusHandler=function(){c.wrapper.focus()},r=c.options,n=c.element.on("focus"+u,c._focusHandler),this._inputTemplate(),c._reset(),c._prev="",c._word="",c._wrapper(),c._tabindex(),c.wrapper.data(b,c.wrapper.attr(b)),c._span(),c._popup(),c._mobile(),c._dataSource(),c._ignoreCase(),c._filterHeader(),c._aria(),c._enable(),c._oldIndex=c.selectedIndex=-1,c._cascade(),d!==t&&(r.index=d),r.autoBind?c.dataSource.fetch():-1===c.selectedIndex&&(l=r.text||"",l||(a=r.optionLabel,s=a&&0===r.index,c._isSelect?l=s?a:n.children(":selected").text():!n[0].value&&s&&(l=a)),c._textAccessor(l)),i.notify(c)},options:{name:"DropDownList",enabled:!0,autoBind:!0,index:0,text:null,value:null,template:"",valueTemplate:"",delay:500,height:200,dataTextField:"",dataValueField:"",optionLabel:"",cascadeFrom:"",cascadeFromField:"",ignoreCase:!0,animation:{},filter:"none",minLength:1},events:["open","close",f,"select","dataBinding","dataBound","cascade"],setOptions:function(e){o.fn.setOptions.call(this,e),this._template(),this._inputTemplate(),this._accessors(),this._filterHeader(),this._enable(),this._aria()},destroy:function(){var e=this;e.wrapper.off(u),e.element.off(u),e._inputWrapper.off(u),o.fn.destroy.call(e)},open:function(){var e=this;e.popup.visible()||(e.ul[0].firstChild&&e._state!==x?(e.popup.open(),e._focusElement(e.filterInput),e._scroll(e._current)):(e._open=!0,e._state="rebind",e.filterInput&&e.filterInput.val(""),e._filterSource()))},toggle:function(e){this._toggle(e,!0)},refresh:function(){var t,n,r=this,o=r._data(),a=o.length,s=r.options.optionLabel,l=r._state===w,u=r.element[0];r.trigger("dataBinding"),r._current&&r.current(null),r._angularItems("cleanup"),r.ul[0].innerHTML=i.render(r.template,o),r._angularItems("compile"),r._height(l?a||1:a),r.popup.visible()&&r.popup._position(),r._isSelect&&(t=u.selectedIndex,n=r.value(),a?s&&(s=r._option("",r._optionLabelText(s))):n&&(t=0,s=r._option(n,r.text())),r._options(o,s),u.selectedIndex=-1===t?0:t),r._hideBusy(),r._makeUnselectable(),l?r.current(e(r.ul[0].firstChild)):(r._open&&r.toggle(!!a),r._open=!1,r._fetch||(a?r._selectItem():r._textAccessor()!==s&&(r.element.val(""),r._textAccessor("")))),r._bound=!!a,r.trigger("dataBound")},text:function(e){var n,i,r=this,o=r.options.ignoreCase;return e=null===e?"":e,e===t?r._textAccessor():("string"==typeof e&&(i=o?e.toLowerCase():e,n=r._select(function(e){return e=r._text(e),o&&(e=(e+"").toLowerCase()),e===i}),n&&(e=n)),r._textAccessor(e),t)},value:function(e){var n,i,r=this;return e===t?r._accessor():(null!==e&&(e=""+e),r._selectedValue=e,i=e||r.options.optionLabel&&!r.element[0].disabled&&""===e,i&&r._fetchItems(e)||(n=r._index(e),r.select(n>-1?n:0)),t)},_editable:function(e){var t=this,n=t.element,r=e.disable,o=e.readonly,a=t.wrapper.add(t.filterInput).off(u),s=t._inputWrapper.off(y),l=function(){s.addClass(h),t._prevent=!1},f=function(){var e,r;t._prevent||(e=t._state===w,r=window.self!==window.top,e&&t._select(t._current),(!e||t.dataItem())&&t._triggerCascade(),i.support.mobileOS.ios&&r?t._change():t._blur(),s.removeClass(h),t._prevent=!0,t._open=!1,n.blur()),t._wrapperClicked=!1};o||r?r?(a.removeAttr(b),s.addClass(g).removeClass(p)):(s.addClass(p).removeClass(g),a.on("focusin"+u,l).on("focusout"+u,f)):(n.removeAttr(c).removeAttr(d),s.addClass(p).removeClass(g).on(y,t._toggleHover),a.attr(b,a.data(b)).attr(m,!1).attr(v,!1).on("keydown"+u,k(t._keydown,t)).on("focusin"+u,l).on("focusout"+u,f).on("mousedown"+u,function(){t._prevent=!0}),t.wrapper.on("click"+u,function(e){e.preventDefault(),t._focused=t.wrapper,t._toggle()}),t.filterInput||a.on("keypress"+u,k(t._keypress,t))),n.attr(c,r).attr(d,o),a.attr(m,r).attr(v,o)},_accept:function(e,t){var n=this,i=n.filterInput&&n.filterInput[0]===s();n._focus(e),n._focusElement(n.wrapper),i&&t===l.TAB&&n.wrapper.focusout()},_option:function(e,t){return'<option value="'+e+'">'+t+"</option>"},_optionLabelText:function(){var e=this.options,t=e.dataTextField,n=e.optionLabel;return n&&t&&"object"==typeof n?this._text(n):n},_data:function(){var e=this,t=e.options,r=t.optionLabel,o=t.dataTextField,a=t.dataValueField,s=e.dataSource.view(),l=s.length,u=r,c=0;if(r&&l){for("object"==typeof r?u=r:o&&(u={},o=o.split("."),a=a.split("."),n(u,a,""),n(u,o,r)),u=new i.data.ObservableArray([u]);l>c;c++)u.push(s[c]);s=u}return s},_selectItem:function(){o.fn._selectItem.call(this),this.current()||this.select(0)},_keydown:function(e){var t,n=this,i=e.keyCode,r=e.altKey,o=n.ul[0];i===l.LEFT?i=l.UP:i===l.RIGHT&&(i=l.DOWN),e.keyCode=i,t=n._move(e),n.popup.visible()&&n.filterInput||(i===l.HOME?(t=!0,e.preventDefault(),n._select(o.firstChild)):i===l.END&&(t=!0,e.preventDefault(),n._select(o.lastChild))),r&&i===l.UP&&n._focusElement(n.wrapper),r||t||!n.filterInput||n._search()},_selectNext:function(e,n){for(var i,r=this,o=n,a=r._data(),s=a.length,l=r.options.ignoreCase,u=function(n,i){return n+="",l&&(n=n.toLowerCase()),0===n.indexOf(e)?(r._select(i),r._triggerEvents(),!0):t};s>n;n++)if(i=r._text(a[n]),i&&u(i,n))return!0;if(o>0&&s>o)for(n=0;o>=n;n++)if(i=r._text(a[n]),i&&u(i,n))return!0;return!1},_keypress:function(e){var t,n,r,o=this;0!==e.which&&e.keyCode!==i.keys.ENTER&&(t=String.fromCharCode(e.charCode||e.keyCode),n=o.selectedIndex,r=o._word,o.options.ignoreCase&&(t=t.toLowerCase())," "===t&&e.preventDefault(),o._last===t&&1>=r.length&&n>-1&&(r||(r=t),o._selectNext(r,n+1))||(o._word=r+t,o._last=t,o._search()))},_popup:function(){o.fn._popup.call(this),this.popup.one("open",k(function(){var e=this.popup;e.wrapper=i.wrap(e.element),e.element.closest(".km-root")[0]&&(e.wrapper.addClass("km-popup km-widget"),this.wrapper.addClass("km-widget"))},this))},_focusElement:function(e){var t=s(),n=this.wrapper,i=this.filterInput,r=e===i?n:i;i&&r[0]===t&&(this._prevent=!0,this._focused=e.focus())},_filter:function(e){var n,i;e&&(n=this,i=n.options.ignoreCase,i&&(e=e.toLowerCase()),n._select(function(r){var o=n._text(r);return o!==t?(o+="",i&&(o=o.toLowerCase()),0===o.indexOf(e)):t}))},_search:function(){var e=this,n=e.dataSource,i=e.selectedIndex,r=e._word;if(clearTimeout(e._typing),"none"!==e.options.filter)e._typing=setTimeout(function(){var t=e.filterInput.val();e._prev!==t&&(e._prev=t,e.search(t)),e._typing=null},e.options.delay);else{if(e._typing=setTimeout(function(){e._word=""},e.options.delay),-1===i&&(i=0),!e.ul[0].firstChild)return n.one(f,function(){n.data()[0]&&i>-1&&e._selectNext(r,i)}).fetch(),t;e._selectNext(r,i),e._triggerEvents()}},_select:function(e){var n,i,o=this,a=o._current,s=null;return e=o._get(e),e&&e[0]&&!e.hasClass(_)&&(o._state===w&&(o._state=x),a&&a.removeClass(_),i=r.List.inArray(e[0],o.ul[0]),i>-1&&(s=o._data()[i],n=o._value(s),o.selectedIndex=i,o._textAccessor(s),o._accessor(n!==t?n:o._text(s),i),o._selectedValue=o._accessor(),o.current(e.addClass(_)),o._optionID&&o._current.attr("aria-selected",!0))),s},_triggerEvents:function(){this.popup.visible()||(this._triggerCascade(),this._change())},_mobile:function(){var e=this,t=e.popup,n=t.element.parents(".km-root").eq(0);n.length&&a&&(t.options.animation.open.effects=a.android||a.meego?"fadeIn":a.ios||a.wp?"slideIn:up":t.options.animation.open.effects)},_filterHeader:function(){var n,i=this.options,r="none"!==i.filter;return this.filterInput&&!r?(this.filterInput.off(u).parent().remove(),this.filterInput=null,t):(r&&(n='<span unselectable="on" class="k-icon k-i-search">select</span>',this.filterInput=e('<input class="k-textbox"/>').attr({role:"listbox","aria-haspopup":!0,"aria-expanded":!1}),this.list.prepend(e('<span class="k-list-filter" />').append(this.filterInput.add(n)))),t)},_span:function(){var t,n=this,i=n.wrapper,r="span.k-input";t=i.find(r),t[0]||(i.append('<span unselectable="on" class="k-dropdown-wrap k-state-default"><span unselectable="on" class="k-input"> </span><span unselectable="on" class="k-select"><span unselectable="on" class="k-icon k-i-arrow-s">select</span></span></span>').append(n.element),t=i.find(r)),n.span=t,n._inputWrapper=e(i[0].firstChild),n._arrow=i.find(".k-icon").mousedown(function(e){e.preventDefault()})},_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[0].style.cssText=i.style.cssText),n.hide(),t._focused=t.wrapper=e.addClass("k-widget k-dropdown k-header").addClass(i.className).css("display","").attr({unselectable:"on",role:"listbox","aria-haspopup":!0,"aria-expanded":!1})},_clearSelection:function(){var e=this,n=e.options.optionLabel;return e.options.value="",e._selectedValue="",e.dataSource.view()[0]&&(n||e._userTriggered)?(e.select(0),t):(e.selectedIndex=-1,e.element.val(""),e._textAccessor(e.options.optionLabel),t)},_inputTemplate:function(){var t=this,n=t.options.valueTemplate;n=n?i.template(n):e.proxy(i.template("#:this._text(data)#",{useWithBlock:!1}),t),t.valueTemplate=n},_textAccessor:function(r){var o,a=this.dataItem(),s=this.options,l=this.span;return r===t?l.text():(e.isPlainObject(r)||r instanceof i.data.ObservableObject?a=r:a&&this._text(a)===r||(s.dataTextField?(a={},n(a,s.dataTextField.split("."),r),n(a,s.dataValueField.split("."),this._accessor())):a=r),o=function(){return{elements:l.get(),data:[{dataItem:a}]}},this.angular("cleanup",o),l.html(this.valueTemplate(a)),this.angular("compile",o),t)}});r.plugin(C)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |