1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-14 06:52:36 +01:00
Radarr/NzbDrone.Web/Scripts/2011.1.414/telerik.textbox.min.js
2011-06-27 22:01:54 -07:00

1 line
11 KiB
JavaScript

(function(e){var j=e.telerik,a=[8,9,37,38,39,40,46,35,36,44],b=["font-family","font-size","font-stretch","font-style","font-weight","letter-spacing","line-height","color","text-align","text-decoration","text-transform"];function g(m){var p={};for(var l=0,o=b.length;l<o;l++){var n=b[l],k=m.css(n);if(k){if(b[l]!="font-style"&&k!="normal"){p[n]=k}}}return p}j.textbox=function(k,l){if(k.nodeName.toLowerCase()!=="input"&&k.type.toLowerCase()!=="text"){throw"Target element is not a INPUT"}e.extend(this,l);this.element=k;var m=this.$element=e(k).bind({focus:function(r){var q=r.target;setTimeout(function(){if(e.browser.msie){q.select()}else{q.selectionStart=0;q.selectionEnd=q.value.length}},0)},keydown:e.proxy(this._keydown,this),keypress:e.proxy(this._keypress,this)}).bind("paste",e.proxy(this._paste,this));var p=new j.stringBuilder();if(k.parentNode.nodeName.toLowerCase()!=="div"){m.addClass("t-input").wrap(e('<div class="t-widget t-numerictextbox"></div>'));if(this.showIncreaseButton){p.cat('<a class="t-link t-icon t-arrow-up" href="#" tabindex="-1" title="').cat(this.increaseButtonTitle).cat('">Increment</a>')}if(this.showDecreaseButton){p.cat('<a class="t-link t-icon t-arrow-down" href="#" tabindex="-1" title="').cat(this.decreaseButtonTitle).cat('">Decrement</a>')}if(p.buffer.length>0){e(p.string()).insertAfter(m)}}this.$wrapper=m.closest(".t-numerictextbox").find(".t-arrow-up, .t-arrow-down").bind({click:j.preventDefault,dragstart:j.preventDefault}).end().bind({focusin:e.proxy(this._focus,this),focusout:e.proxy(this._blur,this)});this.enabled=!m.is("[disabled]");p.buffer=[];p.cat("[ |").cat(this.groupSeparator).catIf("|"+this.symbol,this.symbol).cat("]");this.replaceRegExp=new RegExp(p.string(),"g");var n=m.attr("value"),o=m.attr("class").replace("t-input","");p.buffer=[];p.cat('<div class="t-formatted-value').catIf(" t-state-empty",n==""&&this.enabled).catIf(o,o).cat('">').cat(n||(this.enabled?this.text:"")).cat("</div>");this.$text=e(p.string()).insertBefore(m).css(g(m)).click(function(q){k.focus()});this._blur();this[this.enabled?"enable":"disable"]();this.numFormat=this.numFormat===undefined?this.type.charAt(0):this.numFormat;this.step=this.parse(this.step);this.val=this.parse(this.val);this.minValue=this.parse(this.minValue);this.maxValue=this.parse(this.maxValue);this.decimals={"190":".","188":",","110":this.separator};this.value(n||this.val);j.bind(this,{load:this.onLoad,valueChange:this.onChange})};j.textbox.prototype={_paste:function(o){var m=this.$element.val();if(e.browser.msie){var l=this.element.document.selection.createRange().text;var k=window.clipboardData.getData("Text");if(l&&l.length>0){m=m.replace(l,k)}else{m+=k}}if(m=="-"){return true}var n=this.parse(m);if(n||n==0){this._update(n)}},_keydown:function(q){var n=q.keyCode,l=this.$element,p=this.separator,k=l.val();setTimeout(e.proxy(function(){l.toggleClass("t-state-error",!this.inRange(this.parse(l.val()),this.minValue,this.maxValue))},this));var m=this.decimals[n];if(m){if(m==p&&this.digits>0&&k.indexOf(p)==-1){return true}else{q.preventDefault()}}if(n==8||n==46){setTimeout(e.proxy(function(){this._update(this.parse(l.val()))},this));return true}if(n==38||n==40){var o=n==38?1:-1;this._modify(o*this.step);return true}if(n==222){q.preventDefault()}},_keypress:function(m){var l=e(m.target),k=m.keyCode||m.which;if(m.shiftKey&&k!=45){return false}if(k==0||e.inArray(k,a)!=-1||m.ctrlKey||(m.shiftKey&&k==45)){return true}if(((this.minValue!==null?this.minValue<0:true)&&String.fromCharCode(k)=="-"&&j.caretPos(l[0])==0&&l.val().indexOf("-")==-1)||this.inRange(k,48,57)){setTimeout(e.proxy(function(){var n=this.val,o=this.parse(l.val());if(o!=null&&this.digits){o=h(o,this.digits)}if(n!=o){this._value(o);if(j.trigger(this.element,"valueChange",{oldValue:n,newValue:o})){this._value(n)}}},this));return true}m.preventDefault()},_focus:function(){this.$element.css("text-indent","0").css("color",this.$text.css("color"));this.$text.hide()},_blur:function(){this.$element.css("color",this.$element.css("background-color")).removeClass("t-state-error");if(this.enabled){this.$text.show();if(!e.browser.msie){this.$element.css("text-indent","-4444px")}}var k=this.minValue,m=this.maxValue,l=this.parse(this.$element.val());if(l!=null){if(k!=null&&l<k){l=k}else{if(m!=null&&l>m){l=m}}l=parseFloat(l.toFixed(this.digits))}this._update(l)},_clearTimer:function(k){clearTimeout(this.timeout);clearInterval(this.timer);clearInterval(this.acceleration)},_stepper:function(m,k){if(m.which==1){var l=this.step;this._modify(k*l);this.timeout=setTimeout(e.proxy(function(){this.timer=setInterval(e.proxy(function(){this._modify(k*l)},this),80);this.acceleration=setInterval(function(){l+=1},1000)},this),200)}},_modify:function(n){var k=this.parse(this.element.value),l=this.minValue,m=this.maxValue;k=k?k+n:n;if(l!==null&&k<l){k=l}else{if(m!==null&&k>m){k=m}}this._update(parseFloat(k.toFixed(this.digits)))},_update:function(k){var l=this.val;this._value(k);if(l!=k){if(j.trigger(this.element,"valueChange",{oldValue:l,newValue:k})){this._value(l)}}},_value:function(k){var m=(typeof k==="number")?k:this.parse(k),n=this.enabled?this.text:"",l=m===null;if(m!=null){m=parseFloat(m.toFixed(this.digits))}this.val=m;this.$element.val(l?"":this.formatEdit(m));this.$text.html(l?n:this.format(m));if(l){this.$text.addClass("t-state-empty")}else{this.$text.removeClass("t-state-empty")}},enable:function(){var k=this.$wrapper.find(".t-arrow-up, .t-arrow-down"),l=e.proxy(this._clearTimer,this);this.enabled=true;this.$element.removeAttr("disabled");if(!this.val&&this.val!=0){this.$text.addClass("t-state-empty").html(this.text)}else{if(true==e.browser.msie){this.$text.show()}else{this.$element.css("text-indent","-4444px").css("color",this.$element.css("background-color"))}}this.$wrapper.removeClass("t-state-disabled");k.unbind("mouseup").unbind("mouseout").unbind("dblclick").bind({mouseup:l,mouseout:l,dblclick:l});var m="mousedown";k.eq(0).unbind(m).bind(m,e.proxy(function(n){this._stepper(n,1)},this));k.eq(1).unbind(m).bind(m,e.proxy(function(n){this._stepper(n,-1)},this))},disable:function(){this.enabled=false;this.$wrapper.addClass("t-state-disabled").find(".t-icon").unbind("mousedown").bind("mousedown",j.preventDefault);this.$element.attr("disabled","disabled");if(!this.val&&this.val!=0){this.$text.html("")}else{if(true==e.browser.msie){this.$text.hide()}else{this.$element.css("text-indent","-4444px").css("color",this.$element.css("background-color"))}}},value:function(l){if(l===undefined){return this.val}var k=(typeof l==="number")?l:this.parse(l);if(!this.inRange(k,this.minValue,this.maxValue)){k=null}this._value(k)},formatEdit:function(l){var k=this.separator;if(l&&k!="."){l=l.toString().replace(".",k)}return l},format:function(k){return j.textbox.formatNumber(k,this.numFormat,this.digits,this.separator,this.groupSeparator,this.groupSize,this.positive,this.negative,this.symbol,true)},inRange:function(m,k,l){return m===null||((k!==null?m>=k:true)&&(l!==null?m<=l:true))},parse:function(k){var l=null,m=this.separator;if(k||k=="0"){if(typeof k==typeof 1){return k}k=k.replace(this.replaceRegExp,"");if(m&&m!="."){k=k.replace(m,".")}var o=e.fn.tTextBox.patterns[this.type].negative[this.negative].replace(/(\(|\))/g,"\\$1").replace("*","").replace("n","([\\d|\\.]*)"),n=new RegExp(o);if(n.test(k)){l=-parseFloat(n.exec(k)[1])}else{l=parseFloat(k)}}return isNaN(l)?null:l}};e.fn.tTextBox=function(m){var l="numeric";if(m&&m.type){l=m.type}var k=e.fn.tTextBox.defaults[l];k.digits=j.cultureInfo[l+"decimaldigits"];k.separator=j.cultureInfo[l+"decimalseparator"];k.groupSeparator=j.cultureInfo[l+"groupseparator"];k.groupSize=j.cultureInfo[l+"groupsize"];k.positive=j.cultureInfo[l+"positive"];k.negative=j.cultureInfo[l+"negative"];k.symbol=j.cultureInfo[l+"symbol"];m=e.extend({},k,m);m.type=l;return this.each(function(){var n=e(this);m=e.meta?e.extend({},m,n.data()):m;if(!n.data("tTextBox")){n.data("tTextBox",new j.textbox(this,m));j.trigger(this,"load")}})};var d={val:null,text:"",step:1,inputAttributes:"",increaseButtonTitle:"Increase value",decreaseButtonTitle:"Decrease value",showIncreaseButton:true,showDecreaseButton:true};e.fn.tTextBox.defaults={numeric:e.extend(d,{minValue:-100,maxValue:100}),currency:e.extend(d,{minValue:0,maxValue:1000}),percent:e.extend(d,{minValue:0,maxValue:100})};e.fn.tTextBox.patterns={numeric:{negative:["(n)","-n","- n","n-","n -"]},currency:{positive:["*n","n*","* n","n *"],negative:["(*n)","-*n","*-n","*n-","(n*)","-n*","n-*","n*-","-n *","-* n","n *-","* n-","* -n","n- *","(* n)","(n *)"]},percent:{positive:["n *","n*","*n"],negative:["-n *","-n*","-*n"]}};if(!j.cultureInfo.numericnegative){e.extend(j.cultureInfo,{currencydecimaldigits:2,currencydecimalseparator:".",currencygroupseparator:",",currencygroupsize:3,currencynegative:0,currencypositive:0,currencysymbol:"$",numericdecimaldigits:2,numericdecimalseparator:".",numericgroupseparator:",",numericgroupsize:3,numericnegative:1,percentdecimaldigits:2,percentdecimalseparator:".",percentgroupseparator:",",percentgroupsize:3,percentnegative:0,percentpositive:0,percentsymbol:"%"})}var i=/[0#?]/;function h(k,m){var l=Math.pow(10,m||0);return Math.round(k*l)/l}function c(k){return k.split("").reverse().join("")}function f(o,k,r){var l=0,m=0,q=k.length,s=o.length,v=new j.stringBuilder();while(l<q&&m<s&&k.substring(l).search(i)>=0){if(k.charAt(l).match(i)){v.cat(o.charAt(m++))}else{v.cat(k.charAt(l))}l++}v.catIf(o.substring(m),m<s&&r).catIf(k.substring(l),l<q);var u=c(v.string()),t;if(u.indexOf("#")>-1){t=u.indexOf("0")}if(t>-1){var n=u.slice(0,t),p=u.slice(t,u.length);u=n.replace(/#/g,"")+p.replace(/#/g,"0")}else{u=u.replace(/#/g,"")}if(u.indexOf(",")==0){u=u.replace(/,/g,"")}return r?u:c(u)}j.textbox.formatNumber=function(M,q,v,x,l,S,r,t,O,H){if(!q){return M}var R,I,N,p,L=M<0;q=q.split(":");q=q.length>1?q[1].replace("}",""):q[0];var o=q.search(i)!=-1;if(o){q=q.split(";");I=q[0];N=q[1];p=q[2];q=(L&&N?N:I).indexOf("%")!=-1?"p":"n"}switch(q.toLowerCase()){case"d":return Math.round(M).toString();case"c":R="currency";break;case"n":R="numeric";break;case"p":R="percent";if(!H){M=Math.abs(M)*100}break;default:return M.toString()}var C=function(V,T,U){for(var W=V.length;W<T;W++){V=U?("0"+V):(V+"0")}return V};var K=function(U,W,T){if(l&&T!=0){var V=new RegExp("(-?[0-9]+)([0-9]{"+T+"})");while(V.test(U)){U=U.replace(V,"$1"+W+"$2")}}return U};var G=G||j.cultureInfo,J=e.fn.tTextBox.patterns,F;v=v||v===0?v:G[R+"decimaldigits"];x=x!==F?x:G[R+"decimalseparator"];l=l!==F?l:G[R+"groupseparator"];S=S||S==0?S:G[R+"groupsize"];t=t||t===0?t:G[R+"negative"];r=r||r===0?r:G[R+"positive"];O=O||G[R+"symbol"];var B,m,u;if(o){var E=(L&&N?N:I).split("."),z=E[0],D=E.length>1?E[1]:"",k=j.lastIndexOf(D,"0"),A=j.lastIndexOf(D,"#");v=(A>k?A:k)+1}var P=h(M,v);M=isFinite(P)?P:M;var y=M.toString().split(/e/i);B=y.length>1?parseInt(y[1]):0;y=y[0].split(".");m=y[0];m=L?m.replace("-",""):m;u=y.length>1?y[1]:"";if(B){if(!L){u=C(u,B,false);m+=u.slice(0,B);u=u.substr(B)}else{m=C(m,B+1,true);u=m.slice(B,m.length)+u;m=m.slice(0,B)}}var Q=u.length;if(v<1||(o&&k==-1&&Q===0)){u=""}else{u=Q>v?u.slice(0,v):C(u,v,false)}var n;if(o){if(m==0){m=""}m=f(c(m),c(z),true);m=z.indexOf(",")!=-1?K(m,l,S):m;u=u&&D?f(u,D):"";n=M===0&&p?p:(L&&!N?"-":"")+m+(u.length>0?x+u:"")}else{m=K(m,l,S);J=J[R];var w=L?J.negative[t]:O?J.positive[r]:null;var s=m+(u.length>0?x+u:"");n=w?w.replace("n",s).replace("*",O):s}return n};e.extend(j.formatters,{number:j.textbox.formatNumber})})(jQuery);