mirror of https://github.com/Sonarr/Sonarr
1 line
4.5 KiB
JavaScript
1 line
4.5 KiB
JavaScript
(function(a){var b=a.telerik;b.combobox=function(c,d){a.extend(this,d);var e=a(c);this.element=c;this.$element=e;this.loader=new b.list.loader(this);this.trigger=new b.list.trigger(this);this.$text=e.find("> .t-dropdown-wrap > .t-input").attr("autocomplete","off");this.filtering=new b.list.filtering(this);this.filtering.autoFill=function(i,j){if(i.autoFill&&(i.lastKeyCode!=8&&i.lastKeyCode!=46)){var k=i.$text[0];var o=b.caretPos(k);var n=k.value.substring(0,o);var m=j.toLowerCase().indexOf(n.toLowerCase());if(m!=-1){var l=j.substring(m+n.length);k.value=n+l;b.list.selection(k,o,o+l.length)}}};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.data;var i=this.dropDown;var m=e.offset();i.position(m.top,m.left);if(!i.outerHeight){i.outerHeight=e.outerHeight()}if(!i.outerWidth){i.outerWidth=e.outerWidth();i.$element.css("width",i.outerWidth-2)}if(j.length==0){return}var k=this.$text.val();var l=this.selectedIndex;if(l!=-1&&this.isFiltered){if(k==j[l].Text){this.filteredDataIndexes=[];i.onItemCreate=null;i.dataBind(this.data);this.select(i.$items[l])}else{this.filters[this.filter](this,this.data,k)}this.isFiltered=false}return true},this),onClick:a.proxy(function(i){this.select(i.item);this.trigger.change(this);this.trigger.close()},this)});this.fill=function(j){function n(q){var r=i.$items;var t=q.index;var s=r.filter(".t-state-selected");var u=s.length;var v=t!=-1&&t<r.length?r[t]:u>0?s[u-1]:null;if(v){q.select(v)}else{q.selectedIndex=-1;if(q.highlightFirst){q.highlight(r[0])}}}var l=this.loader;var i=this.dropDown;var o=this.minChars;var m=this.text();var k=m.length;if(!i.$items&&!l.ajaxError){if(l.isAjax()&&k>=o){var p={};p[this.queryString.text]=m;l.ajaxRequest(function(q){this.data=q;i.dataBind(q);n(this);b.trigger(this.element,"dataBound");this.trigger.change();if(j){j()}},{data:p})}else{i.dataBind(this.data);n(this);if(j){j()}}}};this.reload=function(){this.dropDown.$items=null;this.fill()};this.select=function(j){var i=this.highlight(j);if(i==-1){return i}var k=this.filteredDataIndexes;this.selectedIndex=(k&&k.length)>0?k[i]:i;b.list.updateTextAndValue(this,a(this.dropDown.$items[i]).text(),this.data[this.selectedIndex].Value)};this.text=function(i){return this.$text.val(i)};this.value=function(){if(arguments.length){var j=arguments[0];var i=this.select(function(k){return j==k.Value});if(i==-1){this.$input.val(j);this.text(j)}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(i){i.stopPropagation()},this),keydown:a.proxy(g,this),keypress:a.proxy(h,this),focus:a.proxy(function(l){var j=this.trigger;var i=this.dropDown;if(!i.$items){this.fill(j.open)}else{j.open()}var k=this.$text;b.list.selection(k[0],0,k.val().length)},this)});e.find("> .t-dropdown-wrap > .t-select").click(a.proxy(function(i){this.loader.ajaxError=false;if(!this.dropDown.isOpened()){this.$text[0].focus()}else{this.trigger.close()}},this));function f(i){clearTimeout(i.timeout);i.timeout=setTimeout(function(){i.filtering.filter(i)},i.delay)}function g(q){var l=this.trigger;var j=this.dropDown;var n=q.keyCode||q.which;this.lastKeyCode=n;if(q.altKey&&n==38){l.close();return}if(q.altKey&&n==40){l.open();return}if(!q.shiftKey&&(n==38||n==40)){q.preventDefault();if(!j.$items){this.fill()}var k=j.$items;var o=k.filter(".t-state-selected:first");var i=o.length==0||k.length==1?k.first():(n==38)?o.prev():(n==40)?o.next():[];if(i.length){var r=i[0];this.select(r);j.scrollTo(r);if(!j.isOpened()){l.change()}}}if(n==8||n==46){var m=this.$text;if(m.val()!=""){f(this)}setTimeout(a.proxy(function(){if(m.val()==""){this.selectedIndex=-1;this.$input.val("")}else{this.$input.val(this.$text.val())}},this),0)}if(n==13){if(j.isOpened()){q.preventDefault()}var p=j.$items.filter(".t-state-selected:first");if(p.length>0){this.select(p[0])}else{this.$input.val(this.$text.val())}l.change();l.close();b.list.moveToEnd(this.$text[0])}if(n==27||n==9){l.change();l.close();if(n==27){this.$text.blur()}}}function h(j){var i=j.keyCode||j.charCode;if(i==0||a.inArray(i,b.list.keycodes)!=-1){return true}this.$input.val(this.$text.val()+String.fromCharCode(i));f(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={effects:b.fx.slide.defaults(),index:-1,autoFill:true,highlightFirst:true,filter:0,delay:200,minChars:0,cache:true,queryString:{text:"text"}}})(jQuery); |