mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-28 02:37:40 +00:00
8d0cdf272c
Added Telerik MVC Controls, JQuery, JQueryUI and YUI.
1 line
No EOL
7 KiB
JavaScript
1 line
No EOL
7 KiB
JavaScript
(function(c){var a=c.telerik;a.scripts.push("telerik.combobox.js");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(){this.$element.val(r.target.value);m(this)},this),0)},this));var l=function(t){var r="class",s=n.attr(r);if((t.attrName&&t.attrName=="class")||(t.propertyName&&t.propertyName=="className")){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)}n.closest("form").bind("reset",c.proxy(function(s){var r=this;window.setTimeout(function(){if(n.val()!=""){r.value(n.val())}else{r.highlight(0);r.selectedIndex=0}},1)},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;if(this.filter){r.dataBind(this.data,this.encoded)}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");n.removeAttr("disabled");if(!e.data("events")){e.bind("click",c.proxy(h,this))}};this.disable=function(){g.addClass("t-state-disabled");i.attr("disabled","disabled");n.attr("disabled","disabled");e.unbind("click")};this[this.enabled?"enable":"disable"]();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()||this.onDataBinding)&&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(t){var s=this.highlight(t);if(s!=-1){var u=this.filteredDataIndexes;this.selectedIndex=(u&&u.length)>0?u[s]:s;var r=this.data[this.selectedIndex];a.list.updateTextAndValue(this,r.Text,r.Value)}return s};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(z){var u=this.trigger;var r=this.dropDown;var w=z.keyCode||z.which;this.lastKeyCode=w;if(z.altKey&&(w==38||w==40)){var s=w==38?u.close:u.open;if(!r.$items){this.fill(s)}else{s()}return}if(!z.shiftKey&&(w==38||w==40)){z.preventDefault();var y=c.proxy(function(){var B=r.$items,A=B.filter(".t-state-selected:first");var C=A.length==0||B.length==1||this.selectedIndex==-1?B.first():(w==38)?A.prev():(w==40)?A.next():[];if(C.length){var D=C[0];this.select(D);r.scrollTo(D);if(!r.isOpened()){u.change()}}},this);if(!r.$items){if(this.index!=-1||this.value()||this.selectedValue){y=null}this.fill(y);return}y()}if(w==8||w==46){var v=this.$text;if(v.val()!=""){m(this)}setTimeout(c.proxy(function(){if(v.val()==""){this.selectedIndex=-1;this.$element.val("")}else{this.$element.val(this.$text.val())}},this),0)}if(w==13){if(r.isOpened()){z.preventDefault();var x=r.$items.filter(".t-state-selected:first");if(x.length>0){this.select(x[0])}else{this.$element.val(this.$text.val())}u.change();u.close();a.list.moveToEnd(this.$text[0])}}if(w==27||w==9){clearTimeout(this.timeout);var t=b(this.data,this.$text.val());if(t){this.text(t.Text);this.$element.val(t.Value||t.Text)}u.change();u.close();if(w==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,enabled:true,cache:true,queryString:{text:"text"}}})(jQuery); |