You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readarr/packages/TelerikMvcExtensions.2011.1.../content/Scripts/2011.1.315/telerik.autocomplete.min.js

1 line
4.9 KiB

(function(a){var b=a.telerik;b.autocomplete=function(c,d){a.extend(this,d);var i=a.browser.msie?"paste":"input";var e=this.$element=a(c).addClass("t-widget t-autocomplete t-input").attr("autocomplete","off").bind(i,a.proxy(function(j){g(this)},this));this.$text=e;this.element=c;this.trigger=new b.list.trigger(this);this.trigger.change=function(){var k=this.component.text();var j=this.component.previousValue;if(j==undefined||k!=j){b.trigger(this.component.element,"valueChange",{value:k})}this.component.previousValue=k};this.loader=new b.list.loader(this);this.loader.showBusy=function(){this.busyTimeout=setTimeout(a.proxy(function(){this.component.$element.addClass("t-loading")},this),100)};this.loader.hideBusy=function(){clearTimeout(this.busyTimeout);this.component.$element.removeClass("t-loading")};this.filtering=new b.list.filtering(this);this.filtering.autoFill=function(s,o){if(s.autoFill&&(s.lastKeyCode!=8&&s.lastKeyCode!=46)){var v=s.$text[0];var j=v.value;var t=s.separator;var p=b.caretPos(v);var l=t?b.lastIndexOf(j.substring(0,p),t):-1;var q=l!=-1?l+t.length:0;var m=j.substring(q,p);var u=o.toLowerCase().indexOf(m.toLowerCase());if(u!=-1){var r=o.substring(u+m.length);var k=f(v,t);var n=j.split(t);n[k]=m+r;v.value=n.join(t)+(s.multiple&&k!=0&&k==n.length-1?t:"");b.list.selection(v,p,p+r.length)}}};this.enable=function(){e.removeClass("t-state-disabled").removeAttr("disabled")};this.disable=function(){e.addClass("t-state-disabled").attr("disabled","disabled")};this.filtering.multiple=a.proxy(function(j){if(this.multiple){j=j.split(this.separator);j=j[f(this.$text[0],this.separator)]}return j},this);this.dropDown=new b.dropDown({attr:this.dropDownAttr,effects:this.effects,onClick:a.proxy(function(j){this.select(j.item);this.trigger.change();this.trigger.close()},this)});this.dropDown.$element.css("direction",e.closest(".t-rtl").length?"rtl":"");this.fill=function(k){function j(s){var r=s.highlightFirst?o.$items.first():null;if(r){r.addClass("t-state-selected")}}var p=this.loader;var o=this.dropDown;var l=this.minChars;var n=this.text();var q=n.length;if(!o.$items&&!p.ajaxError){if(p.isAjax()&&q>=l){var m={};m[this.queryString.text]=n;p.ajaxRequest(function(r){this.dataBind(r,true);j(this);b.trigger(this.element,"dataBound");this.trigger.change();if(k){k()}},{data:m})}else{this.dataBind(this.data,true);j(this);if(k){k()}}}};this.text=function(){if(arguments.length>0){this.previousValue=arguments[0]}return this.$text.val.apply(this.$text,arguments)};this.value=function(){return this.text.apply(this,arguments)};this.select=function(r){var q=this.highlight(r);if(q==-1){return q}var k=this.filteredDataIndexes;var m=(k&&k.length)>0?k[q]:q;var r=this.data[m];var o=r.Text?r.Text:r;var j=o;if(this.multiple){var l=this.$element;var p=this.separator;var n=f(l[0],p);j=l.val().split(p);j[n]=o;j=j.join(p)+(n==j.length-1?p:"")}this.$text.val(j)};b.list.common.call(this);b.list.filters.call(this);b.list.initialize.call(this);this.dataBind=function(l,j){this.data=l=(l||[]);var m=!!this.loader.isAjax();if(this.encoded&&m){for(var k=0,n=l.length;k<n;k++){var o=l[k];if(o){if(o.Text){l[k].Text=b.encode(o.Text)}else{l[k]=b.encode(o)}}}}this.dropDown.dataBind(l);if(!j){this.$text.val("")}};e.bind({focus:a.proxy(function(j){j.stopPropagation()},this),keydown:a.proxy(h,this),keypress:a.proxy(function(k){var j=k.keyCode||k.charCode;if(j==0||a.inArray(j,b.list.keycodes)!=-1||k.ctrlKey){return true}g(this)},this)});a(document.documentElement).bind("mousedown",a.proxy(function(l){var k=this.dropDown.$element.parent();var j=k.length;if((!j&&c!==l.target)||(j&&!a.contains(c,l.target)&&!a.contains(k[0],l.target))){this.trigger.change();this.trigger.close()}},this));function f(j,k){return j.value.substring(0,b.caretPos(j)).split(k).length-1}function g(j){clearTimeout(j.timeout);j.timeout=setTimeout(function(){j.filtering.filter(j)},j.delay)}function h(s){var n=this.trigger;var k=this.dropDown;var o=s.keyCode||s.which;this.lastKeyCode=o;if(!s.shiftKey&&o>36&&o<41&&o!=37&&o!=39){s.preventDefault();if(k.isOpened()){if(!k.$items){this.fill()}var l=k.$items;var p=l.filter(".t-state-selected:first");var j=[];if(o==38){var t=p.prev();j=t.length?t:l.last()}else{if(o==40){var q=p.next();j=q.length?q:l.first()}}if(j.length){var u=j[0];this.highlight(u);k.scrollTo(u);this.filtering.autoFill(this,j.text())}}}if(o==8||o==46){var m=this.$element;if(m.val()!=""){g(this)}setTimeout(a.proxy(function(){if(m.val()==""){n.close()}},this),0)}if(o==13){if(k.isOpened()){s.preventDefault()}if(k.$items){var r=k.$items.filter(".t-state-selected:first");if(r.length>0){this.select(r[0])}}n.change();n.close();b.list.moveToEnd(this.element)}if(o==27||o==9){n.change();n.close()}}};a.fn.tAutoComplete=function(c){return b.create(this,{name:"tAutoComplete",init:function(d,e){return new b.autocomplete(d,e)},options:c})};a.fn.tAutoComplete.defaults={encoded:true,effects:b.fx.slide.defaults(),filter:1,delay:200,minChars:1,cache:true,autoFill:false,highlightFirst:false,queryString:{text:"text"},multiple:false,separator:", "}})(jQuery);