Lidarr/NzbDrone.Web/Scripts/2010.3.1318/telerik.combobox.min.js

1 line
5.3 KiB
JavaScript

(function(a){var b=a.telerik;b.combobox=function(d,e){a.extend(this,e);var f=a(d);this.element=d;this.$element=f;this.loader=new b.list.loader(this);this.trigger=new b.list.trigger(this);var g=f.find("> .t-dropdown-wrap > .t-select");var l=a.browser.msie?"paste":"input";var h=this.$text=f.find("> .t-dropdown-wrap > .t-input").attr("autocomplete","off").bind(l,a.proxy(function(r){var o=r.target.value;if(a.browser.msie){var q=d.document.selection.createRange().text;var p=window.clipboardData.getData("Text");if(q&&q.length>0){o=o.replace(q,p)}else{o+=p}}this.$input.val(o);m(this)},this));var j=a.browser.msie?"propertychange":"DOMAttrModified";var c=this.$input=this.$element.find("input:last").bind(j,function(q){var o="class",p=c.attr(o);if(p!=h.attr(o)){h.attr(o,p).addClass("t-input")}});if(!c.attr("disabled")){g.bind("click",a.proxy(n,this))}this.filtering=new b.list.filtering(this);this.filtering.autoFill=function(o,p){if(o.autoFill&&(o.lastKeyCode!=8&&o.lastKeyCode!=46)){var q=o.$text[0];var u=b.caretPos(q);var t=q.value.substring(0,u);var s=p.toLowerCase().indexOf(t.toLowerCase());if(s!=-1){var r=p.substring(s+t.length);q.value=t+r;b.list.selection(q,u,u+r.length)}}};this.dropDown=new b.dropDown({attr:this.dropDownAttr,effects:this.effects,onOpen:a.proxy(function(){var p=this.data;var o=this.dropDown;if(p.length==0){return}var r=this.$text.val();var q=this.selectedIndex;if(q!=-1&&this.isFiltered){if(r==p[q].Text){this.filteredDataIndexes=[];o.onItemCreate=null;o.dataBind(this.data);this.select(o.$items[q])}else{this.filters[this.filter](this,this.data,r)}this.isFiltered=false}},this),onClick:a.proxy(function(o){this.select(o.item);this.trigger.change();this.trigger.close()},this)});this.dropDown.$element.css("direction",f.closest(".t-rtl").length?"rtl":"");this.enable=function(){f.removeClass("t-state-disabled").find(".t-input").removeAttr("disabled");g.bind("click",a.proxy(n,this))};this.disable=function(){f.addClass("t-state-disabled").find(".t-input").attr("disabled","disabled");g.unbind("click")};this.fill=function(p){function r(x){var w=x.selectedValue||x.value();if(w){x.value(w);return}var y=o.$items;var A=x.index;var z=y.filter(".t-state-selected");var B=z.length;var C=A!=-1&&A<y.length?y[A]:B>0?z[B-1]:null;if(C){x.select(C)}else{x.selectedIndex=-1;if(x.highlightFirst){x.highlight(y[0])}}}var s=this.loader;var o=this.dropDown;var u=this.minChars;var t=this.text();var q=t.length;if(!o.$items&&!s.ajaxError){if(s.isAjax()&&q>=u){var v={};v[this.queryString.text]=t;s.ajaxRequest(function(w){this.dataBind(w,true);r(this);b.trigger(this.element,"dataBound");this.trigger.change();if(p){p()}},{data:v})}else{this.dataBind(this.data,true);r(this);if(p){p()}}}};this.reload=function(){this.dropDown.$items=null;this.fill()};this.select=function(p){var o=this.highlight(p);if(o==-1){return o}var q=this.filteredDataIndexes;this.selectedIndex=(q&&q.length)>0?q[o]:o;b.list.updateTextAndValue(this,a(this.dropDown.$items[o]).text(),this.data[this.selectedIndex].Value)};this.text=function(){return this.$text.val.apply(this.$text,arguments)};this.value=function(){if(arguments.length){var p=arguments[0];var o=this.select(function(q){return p==(q.Value||q.Text)});if(o==-1){this.selectedIndex=o;this.$input.val(p);this.text(p)}this.previousValue=this.$input.val()}else{return this.$input.val()}};b.list.common.call(this);b.list.filters.call(this);b.list.initialize.call(this);this.$text.bind({change:a.proxy(function(o){o.stopPropagation()},this),keydown:a.proxy(k,this),keypress:a.proxy(i,this),focus:a.proxy(function(r){var p=this.trigger;var o=this.dropDown;if(!o.$items){this.fill(p.open)}else{p.open()}var q=this.$text;b.list.selection(q[0],0,q.val().length)},this)});function n(o){this.loader.ajaxError=false;if(!this.dropDown.isOpened()){this.$text[0].focus()}else{this.trigger.close()}}function m(o){clearTimeout(o.timeout);o.timeout=setTimeout(function(){o.filtering.filter(o)},o.delay)}function k(w){var r=this.trigger;var p=this.dropDown;var t=w.keyCode||w.which;this.lastKeyCode=t;if(w.altKey&&t==38){r.close();return}if(w.altKey&&t==40){r.open();return}if(!w.shiftKey&&(t==38||t==40)){w.preventDefault();if(!p.$items){this.fill()}var q=p.$items;var u=q.filter(".t-state-selected:first");var o=u.length==0||q.length==1?q.first():(t==38)?u.prev():(t==40)?u.next():[];if(o.length){var x=o[0];this.select(x);p.scrollTo(x);if(!p.isOpened()){r.change()}}}if(t==8||t==46){var s=this.$text;if(s.val()!=""){m(this)}setTimeout(a.proxy(function(){if(s.val()==""){this.selectedIndex=-1;this.$input.val("")}else{this.$input.val(this.$text.val())}},this),0)}if(t==13){if(p.isOpened()){w.preventDefault()}var v=p.$items.filter(".t-state-selected:first");if(v.length>0){this.select(v[0])}else{this.$input.val(this.$text.val())}r.change();r.close();b.list.moveToEnd(this.$text[0])}if(t==27||t==9){r.change();r.close();if(t==27){this.$text.blur()}}}function i(p){var o=p.keyCode||p.charCode;if(o==0||a.inArray(o,b.list.keycodes)!=-1||p.ctrlKey){return true}setTimeout(a.proxy(function(){this.$input.val(this.$text.val())},this),0);m(this)}};a.fn.tComboBox=function(c){return b.create(this,{name:"tComboBox",init:function(d,e){return new b.combobox(d,e)},options:c})};a.fn.tComboBox.defaults={encoded:true,effects:b.fx.slide.defaults(),index:-1,autoFill:true,highlightFirst:true,filter:0,delay:200,minChars:0,cache:true,queryString:{text:"text"}}})(jQuery);