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