1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-29 11:25:26 +00:00
Radarr/NzbDrone.Web/Scripts/2011.3.1115/telerik.combobox.min.js
2011-11-22 17:51:44 -08:00

1 line
No EOL
7 KiB
JavaScript

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