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.
Sonarr/NzbDrone.Web/Scripts/2010.2.825/telerik.autocomplete.min.js

1 line
4.6 KiB

(function(a){var b=a.telerik;b.autocomplete=function(c,d){a.extend(this,d);var e=a(c);this.$text=e;this.element=c;this.$element=e;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];var i=u.value;var s=r.separator;var o=b.caretPos(u);var k=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);var j=f(u,s);var m=i.split(s);m[j]=l+q;u.value=m.join(s)+(r.multiple&&j!=0&&j==m.length-1?s:"");b.list.selection(u,o,o+q.length)}}};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({outerHeight:e.outerHeight(),outerWidth:e.outerWidth(),zIndex:b.list.getZIndex(e),attr:this.dropDownAttr,effects:this.effects,onOpen:a.proxy(function(){var j=this.dropDown;var i=e.offset();j.position(i.top,i.left);if(!j.outerHeight){j.outerHeight=e.outerHeight()}if(!j.outerWidth){j.outerWidth=e.outerWidth();j.$element.css("width",j.outerWidth-2)}return true},this),onClick:a.proxy(function(i){this.select(i.item);this.trigger.change();this.trigger.close()},this)});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()&&p>=k){var l={};l[this.queryString.text]=m;o.ajaxRequest(function(q){this.data=q;n.dataBind(q);i(this);b.trigger(this.element,"dataBound");if(j){j()}},{data:l})}else{n.dataBind(this.data);i(this);if(j){j()}}}};this.text=function(i){return this.$text.val(i)};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(i)};this.previousValue=this.value();b.list.common.call(this);b.list.filters.call(this);b.bind(this,{dataBinding:this.onDataBinding,dataBound:this.onDataBound,error:this.onError,open:this.onOpen,close:this.onClose,valueChange:this.onChange,load:this.onLoad});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){return true}g(this)},this)});a(document).bind("mousedown",a.proxy(function(j){var i=this.dropDown.$element.parent();if((i.length>0)&&!a.contains(c,j.target)&&!a.contains(i[0],j.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.$items.length){var q=j.$items.filter(".t-state-selected:first");if(j.isOpened()){r.preventDefault()}if(q.length>0){this.select(q[0]);m.change();m.close();b.list.moveToEnd(this.element)}}}if(n==27||n==9){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={effects:b.fx.slide.defaults(),filter:1,delay:200,minChars:1,cache:true,autoFill:false,highlightFirst:false,queryString:{text:"text"},multiple:false,separator:", "}})(jQuery);