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

1 line
No EOL
11 KiB
JavaScript

(function(a){var b=a.telerik;var e=/\s+/;b.scripts.push("telerik.list.js");b.list={htmlBuilder:function(i,h,k){var n,m,j=i.id,l=i.name,g=new b.stringBuilder(),f=a(i);if(k){m=f.find("option:selected").text();n=f.val()}else{m=i.value}function o(){return a(['<div class="t-widget',h,'t-header"></div>'].join(" "))}this.render=function(){f.wrap(o()).hide();var p=a('<div class="t-dropdown-wrap t-state-default"></div>').insertBefore(f);this.text({builder:g,text:m,id:j,name:l}).appendTo(p);a('<span class="t-select"><span class="t-icon t-arrow-down">select</span></span>').appendTo(p);if(k){g.buffer=[];a(g.cat('<input style="display:none;" type="text" ').catIf('value="',n,'" ',n).catIf('name="',l,'" ',l).cat("/>").string()).insertAfter(p)}};this.text=function(p){return a(['<span class="t-input">',p.text||"&nbsp;","</span>"].join(""))}},initialize:function(){this.previousValue=this.value();b.bind(this,{dataBinding:this.onDataBinding,dataBound:this.onDataBound,error:this.onError,open:this.onOpen,close:this.onClose,valueChange:this.onChange,load:this.onLoad})},common:function(){this.open=function(){if(!this.loader.isAjax()&&(!this.data||this.data.length==0)){return}var f=this.$wrapper||this.$element,g=this.dropDown,h=g.$element.css("z-index");var i={offset:f.offset(),outerHeight:f.outerHeight(),outerWidth:f.outerWidth(),zIndex:h&&h!="auto"?h:b.getElementZIndex(f[0])};if(g.$items){g.open(i)}else{this.fill(function(){g.open(i)})}};this.close=function(){this.dropDown.close()};this.dataBind=function(f,l){this.data=f=(f||[]);var h=-1;for(var g=0,k=f.length;g<k;g++){var j=f[g];if(j){if(j.Selected){h=g}}}this.dropDown.dataBind(f,this.encoded);if(h!=-1){this.index=h;this.select(h)}if(!l){this.text("");this.$element.val("");if(this.filteredDataIndexes){this.filteredDataIndexes=null}}};this.highlight=function(f){var k=function(i){var l=i.dropDown;i.close();if(!l.$items){l.dataBind(i.data,i.encoded)}l.$items.removeClass("t-state-selected").eq(h).addClass("t-state-selected")};var h=-1;if(!this.data){return h}if(!isNaN(f-0)){if(f>-1&&f<this.data.length){h=f;k(this)}}else{if(a.isFunction(f)){for(var g=0,j=this.data.length;g<j;g++){if(f(this.data[g])){h=g;break}}if(h!=-1){k(this)}}else{h=this.dropDown.highlight(f)}}return h}},filtering:function(){this.filter=function(g){g.isFiltered=true;var o=true,h=g.data,l=g.$text[0],r=l.value,s=g.trigger,i=g.dropDown;r=this.multiple(r);if(r.length<g.minChars){return}var k=g.filter;if(g.loader.isAjax()){if(g.cache&&h&&h.length>0){g.filters[k](g,h,r);var j=g.filteredDataIndexes;if((j&&j.length>0)||(k==0&&g.selectedIndex!=-1)){o=false}}if(o){var p={};p[g.queryString.text]=r;g.loader.ajaxRequest(function(u){var w=g.trigger;var v=g.dropDown;if(u&&u.length==0){v.close();v.dataBind();return}g.data=u;b.trigger(g.element,"dataBound");g.filters[k](g,u,r);var t=v.$items;if(t.length>0){if(!v.isOpened()){w.open()}g.filtering.autoFill(g,t.first().text())}else{w.close()}},{data:p})}}else{o=false;g.filters[k](g,g.data,r)}if(!o){var f=i.$items;if(!f){return}var m=f.length,q=g.selectedIndex;var n=k==0?q!=-1?f[q].innerText||f[q].textContent:"":f.length>0?f.first().text():"";this.autoFill(g,n);if(m==0){s.close()}else{if(!i.isOpened()){s.open()}}}};this.multiple=function(f){return f}},filters:function(){this.filters=[function f(h,j,m){if(!j||j.length==0){return}var k=h.dropDown;var g=k.$items;if(!g||g.length==0||h.loader.isAjax()){k.dataBind(j,h.encoded);g=k.$items}for(var l=0,o=j.length;l<o;l++){if(j[l].Text.slice(0,m.length).toLowerCase()==m.toLowerCase()){var n=g[l];h.selectedIndex=l;k.highlight(n);k.scrollTo(n);return}}g.removeClass("t-state-selected");h.selectedIndex=-1;b.list.highlightFirstOnFilter(h,g)},c(false,function(g,h){return h.slice(0,g.length).toLowerCase()==g.toLowerCase()}),c(true,function(g,h){return h&&h.toLowerCase().indexOf(g.toLowerCase())!=-1})]},loader:function(g){this.ajaxError=false;this.component=g;this.isAjax=function(){return g.ajax||g.ws||g.onDataBinding};function f(h,i){var j={url:(g.ajax||g.ws)["selectUrl"],type:"POST",data:{},dataType:"text",error:function(l,k){g.loader.ajaxError=true;if(b.ajaxError(g.element,"error",l,k)){return}},complete:a.proxy(function(){this.hideBusy()},g.loader),success:function(k,m,n){try{k=eval("("+k+")")}catch(l){if(!b.ajaxError(g.element,"error",n,"parseeror")){alert("Error! The requested URL did not return JSON.")}g.loader.ajaxError=true;return}k=k.d||k;if(h){h.call(g,k)}}};a.extend(j,i);if(g.ws){j.data=b.toJson(j.data);j.contentType="application/json; charset=utf-8"}return j}this.ajaxRequest=function(h,j){var i={};if(b.trigger(g.element,"dataBinding",i)){return}if(g.ajax||g.ws){this.showBusy();a.ajax(f(h,{data:a.extend({},j?j.data:{},i.data)}))}else{if(h){h.call(g,g.data)}}},this.showBusy=function(){this.busyTimeout=setTimeout(a.proxy(function(){this.component.$wrapper.find("> .t-dropdown-wrap .t-icon").addClass("t-loading")},this),100)},this.hideBusy=function(){clearTimeout(this.busyTimeout);this.component.$wrapper.find("> .t-dropdown-wrap .t-icon").removeClass("t-loading")}},trigger:function(f){this.component=f;this.change=function(){var g=f.previousValue;var h=f.value();if(g==undefined||h!=g){b.trigger(f.element,"valueChange",{value:h})}f.previousValue=h};this.open=function(){var g=f.dropDown;if((g.$items&&g.$items.length>0)&&!g.isOpened()&&!b.trigger(f.element,"open")){f.open()}};this.close=function(){var g=f.dropDown;if((g.$element.is(":animated")||g.isOpened())&&!b.trigger(f.element,"close")){f.close()}}},retrieveData:function(l){var j=[];var g=a(l).find("option");for(var h=0,k=g.length;h<k;h++){var f=g.eq(h);j[h]={Text:f.text(),Value:f.val(),Selected:f.is(":selected")}}return j},highlightFirstOnFilter:function(g,f){if(g.highlightFirst){f.first().addClass("t-state-selected");g.dropDown.scrollTo(f[0])}},moveToEnd:function(f){if(f.createTextRange){var g=f.createTextRange();g.moveStart("textedit",1);g.select()}},selection:function(g,i,f){if(g.createTextRange){var h=g.createTextRange();h.collapse(true);h.moveStart("character",i);h.moveEnd("character",f-i);h.select()}else{if(g.selectionStart){g.selectionStart=i;g.selectionEnd=f}}},updateTextAndValue:function(f,g,i){f.text(g);var h=i===null?g:i;f.$element.val(h)},getZIndex:function(f){var g="auto";a(f).parents().andSelf().each(function(){g=a(this).css("zIndex");if(Number(g)){g=Number(g)+1;return false}});return g},keycodes:[8,9,13,27,37,38,39,40,35,36]};function c(g,f){return function(i,j,m){if(!j||j.length==0){return}var k=a.map(j,function(o,n){var p=o.Text;if(f(m,p!==undefined?p:o)){return n}});var l=new RegExp("(?![^&;]+;)(?!<[^<>]*)("+m.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi,"\\$1")+")(?![^<>]*>)(?![^&;]+;)",g?"ig":"i");i.filteredDataIndexes=k;i.selectedIndex=-1;i.dropDown.onItemCreate=function(n){if(m){n.html=n.html.replace(l,"<strong>$1</strong>")}};i.dropDown.dataBind(a.map(k,function(o,n){return j[o]}),i.encoded);var h=i.dropDown.$items;h.removeClass("t-state-selected");b.list.highlightFirstOnFilter(i,h)}}function d(g,f,k){if(!g||!f){return null}var l=k.length;k=k.toLowerCase();for(var h=0,j=g.length;h<j;h++){if(g[h].Text.slice(0,l).toLowerCase()==k){return f[h]}}}b.dropDownList=function(i,m){a.extend(this,m);var j=i.nodeName.toLowerCase()=="select";if(j&&!this.data){this.data=b.list.retrieveData(i);new b.list.htmlBuilder(i,"t-dropdown",j).render();i=i.previousSibling}var h="";this.element=i;var f=this.$element=a(i);this.loader=new b.list.loader(this);this.trigger=new b.list.trigger(this);this.$wrapper=f.closest(".t-dropdown");var g=this.$text=this.$wrapper.find("> .t-dropdown-wrap > .t-input");if(!this.$wrapper.attr("tabIndex")){this.$wrapper.attr("tabIndex",0)}this.dropDown=new b.dropDown({attr:this.dropDownAttr,effects:this.effects,onClick:a.proxy(function(p){this.select(p.item);this.trigger.change();this.trigger.close();this.$wrapper.focus()},this)});this.dropDown.$element.css("direction",this.$wrapper.closest(".t-rtl").length?"rtl":"");var o=function(r){var p="class",q=f.attr(p);if((r.attrName&&r.attrName=="class")||(r.propertyName&&r.propertyName=="className")){var s=f.prev(".t-dropdown-wrap");var t=/\b(t-state-[\w]+)\b/.exec(s.attr(p));if(!(t&&t[0])){t=""}else{t=t[0]}if(q!=s.attr(p)){s.attr(p,q).addClass("t-dropdown-wrap "+t)}}};if(a.browser.msie){i.attachEvent("onpropertychange",o)}else{f.bind("DOMAttrModified",o)}f.closest("form").bind("reset",a.proxy(function(p){var q=this;window.setTimeout(function(){if(f.val()!=""){q.value(f.val())}else{q.text("");q.highlight(0);q.selectedIndex=0}},1)},this));this.fill=function(p){function s(u){var x,y=u.selectedValue||u.value();if(y){x=function(z){return y==(z.Value||z.Text)}}else{var t=u.dropDown.$items,v=u.index,w=t.filter(".t-state-selected").length;x=v!=-1&&v<t.length?v:w>0?w-1:0}u.select(x)}var q=this.dropDown,r=this.loader;if(!q.$items&&!r.ajaxError){if(r.isAjax()){r.ajaxRequest(function(t){this.dataBind(t,true);s(this);b.trigger(this.element,"dataBound");this.trigger.change();if(p){p()}})}else{this.dataBind(this.data);s(this);if(p){p()}}}};this.enable=function(){var p=this.$wrapper.removeClass("t-state-disabled");if(!p.data("events")){this.$wrapper.removeClass("t-state-disabled").bind({keydown:a.proxy(k,this),keypress:a.proxy(l,this),click:a.proxy(function(r){var s=this.trigger;var q=this.dropDown;this.$wrapper.focus();if(q.isOpened()){s.close()}else{if(!q.$items){this.fill(s.open)}else{s.open()}}},this)})}f.removeAttr("disabled")};this.disable=function(){f.attr("disabled","disabled");this.$wrapper.addClass("t-state-disabled").unbind()};this.reload=function(){this.dropDown.$items=null;this.fill()};this.select=function(q){var p=this.highlight(q);if(p!=-1){this.selectedIndex=p;b.list.updateTextAndValue(this,this.data[p].Text,this.data[p].Value)}return p};this.text=function(p){if(p!==undefined){if(this.encoded){p=b.encode(p)}this.$text.html(p&&p.replace(e,"")?p:"&nbsp;")}else{return this.$text.html()}};this.value=function(q){if(q!==undefined){var p=this.select(function(r){return q==r.Value});if(p==-1){p=this.select(function(r){return q==r.Text})}if(p!=-1){this.previousValue=this.$element.val()}}else{return this.$element.val()}};b.list.common.call(this);b.list.initialize.call(this);a(document.documentElement).bind("mousedown",a.proxy(function(q){var p=this.dropDown.$element;var r=p&&p.parent().length>0;if(a.contains(this.$wrapper[0],q.target)||(r&&a.contains(p.parent()[0],q.target))){return}this.trigger.change();this.trigger.close()},this));this[this.enabled?"enable":"disable"]();function n(){clearTimeout(this.timeout);this.timeout=setTimeout(a.proxy(function(){h=""},this),this.delay)}function k(u){var x=this.trigger;var t=this.dropDown;var w=u.keyCode||u.which;if(u.altKey&&(w==38||w==40)){var s=w==38?x.close:x.open;if(!t.$items){this.fill(s)}else{s()}return}if(w>34&&w<41){u.preventDefault();if(!t.$items){this.fill();return}var q=t.$items,r=a(q[this.selectedIndex]);var p=(w==35)?q.last():(w==36)?q.first():(w==37||w==38)?r.prev():(w==39||w==40)?r.next():[];if(p.length){var v=p[0];this.select(v);t.scrollTo(v);if(!t.isOpened()){x.change()}}}if(w==8){a.proxy(n,this)();u.preventDefault();h=h.slice(0,-1)}if(w==9||w==13||w==27){x.change();x.close()}}function l(q){var p=this.dropDown;var s=q.keyCode||q.charCode;if(s==0||a.inArray(s,b.list.keycodes)!=-1||q.ctrlKey||q.altKey||q.shiftKey){return}if(!p.$items){this.fill();return}var t=h;t+=String.fromCharCode(s);if(t){var r=d(this.data,p.$items,t);if(r){this.select(r);p.scrollTo(r)}h=t}a.proxy(n,this)()}};a.fn.tDropDownList=function(f){return b.create(this,{name:"tDropDownList",init:function(g,h){return new b.dropDownList(g,h)},options:f})};a.fn.tDropDownList.defaults={effects:b.fx.slide.defaults(),accessible:false,index:0,delay:500,enabled:true,encoded:true}})(jQuery);