Sonarr/packages/TelerikMvcExtensions.2011.2.../content/Scripts/2011.2.712/telerik.autocomplete.min.js

1 line
4.9 KiB
JavaScript

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