sonarr-repo-only/NzbDrone.Web/Scripts/2010.2.825/telerik.textbox.min.js

1 line
9.4 KiB
JavaScript

(function(d){var g=d.telerik;var e={"190":".","110":".","188":","};var a=[8,9,37,38,39,40,46,35,36,44];g.textbox=function(h,i){this.element=h;d.extend(this,i);var o=new g.stringBuilder();o.cat("[ |").cat(this.groupSeparator).catIf("|"+this.symbol,this.symbol).cat("]");this.replaceRegExp=new RegExp(o.string(),"g");var n=d.browser.msie?"paste":"input";var k=d(".t-input",h);var l=k.attr("value");d("<input>",{id:k.attr("id")+"-text",name:k.attr("name")+"-text","class":k.attr("class"),value:(l||this.text),style:k.attr("style")}).bind({blur:g.delegate(this,this.blur),focus:g.delegate(this,this.focus),keydown:g.delegate(this,this.keydown),keypress:g.delegate(this,this.keypress),change:function(p){p.stopPropagation();return false}}).bind(n,g.delegate(this,this[n])).insertBefore(k);k.hide().appendTo(h);var j=d(".t-arrow-up, .t-arrow-down",h).bind({mouseup:g.delegate(this,this.clearTimer),mouseout:g.delegate(this,this.clearTimer),click:g.preventDefault,dragstart:g.preventDefault,dblclick:g.delegate(this,this.clearTimer)});d(j[0]).mousedown(d.proxy(function(p){this.updateState();this.stepper(p,1)},this));d(j[1]).mousedown(d.proxy(function(p){this.updateState();this.stepper(p,-1)},this));this.numFormat=this.numFormat===undefined?this.type.charAt(0):this.numFormat;var m=this.separator;this.step=this.parse(this.step,m);this.val=this.parse(this.val,m);this.minValue=this.parse(this.minValue,m);this.maxValue=this.parse(this.maxValue,m);if(l!=""){this.value(l)}g.bind(this,{change:this.onChange,load:this.onLoad})};g.textbox.prototype={enable:function(){d(".t-input:first",this.element).first().attr("disabled",false);var h=d(".t-icon",this.element);d(h[0]).mousedown(d.proxy(function(i){this.updateState();this.stepper(i,1)},this));d(h[1]).mousedown(d.proxy(function(i){this.updateState();this.stepper(i,-1)},this))},disable:function(){d(".t-input:first",this.element).first().attr("disabled",true);d(".t-icon",this.element).unbind("mousedown")},updateState:function(){var h=d("> .t-input:first",this.element).val();if(this.val!=h.replace(this.replaceRegExp,"")){this.parseTrigger(h)}},input:function(k,i){var h=d(i).val();if(h=="-"){return true}var j=this.parse(h,this.separator);if(j||j==0){this.trigger(this.round(j,this.digits))}},paste:function(m,h){var j=d(h);var i=j.val();var k=h.document.selection.createRange().text;var n=window.clipboardData.getData("Text");if(k>0){i=i.replace(k,n)}else{i+=n}var l=this.parse(i,this.separator);if(l||l==0){this.trigger(this.round(l,this.digits))}},focus:function(j,i){this.focused=true;this.updateState();var h=this.formatEdit(this.val);d(i).val(h||(h==0?0:""));if(!d.browser.safari){i.select()}},blur:function(i){var j=d(i.target);this.focused=false;var h=j.val();if(!h&&h!="0"||!this.val&&this.val!=0){this.value(null);j.removeClass("t-state-error").val(this.text||"");return true}else{if(this.inRange(this.val,this.minValue,this.maxValue)){j.removeClass("t-state-error").val(this.format(this.val))}else{j.addClass("t-state-error")}}},keydown:function(m,h){var j=m.keyCode;var k=d(h);var l=this.separator;var i=e[j];if(i){if(i==l&&this.digits>0&&g.caretPos(k[0])!=0&&k.val().indexOf(l)==-1){return true}else{m.preventDefault()}}if(j==8||j==46){setTimeout(g.delegate(this,function(){this.parseTrigger(k.val())}));return true}if(j==38||j==40){this.modifyInput(k,this.step*(j==38?1:-1));return true}if(j==222){m.preventDefault()}},keypress:function(i){var j=d(i.target);var h=i.keyCode||i.which;if(h==0||d.inArray(h,a)!=-1||i.ctrlKey||(i.shiftKey&&h==45)){return true}if(((this.minValue!==null?this.minValue<0:true)&&String.fromCharCode(h)=="-"&&g.caretPos(j[0])==0&&j.val().indexOf("-")==-1)||this.inRange(h,48,57)){setTimeout(g.delegate(this,function(){this.parseTrigger(j.val())}));return true}i.preventDefault()},clearTimer:function(h){clearTimeout(this.timeout);clearInterval(this.timer);clearInterval(this.acceleration)},stepper:function(k,h){if(k.which==1){var i=d(".t-input:first",this.element);var j=this.step;this.modifyInput(i,h*j);this.timeout=setTimeout(g.delegate(this,function(){this.timer=setInterval(g.delegate(this,function(){this.modifyInput(i,h*j)}),80);this.acceleration=setInterval(function(){j+=1},1000)}),200)}},value:function(h){if(arguments.length==0){return this.val}var j=(typeof h===typeof 1)?h:this.parse(h,this.separator);var i=j===null;this.val=j;d(".t-input:last",this.element).val(i?"":this.formatEdit(j));d(".t-input:first",this.element).toggleClass("t-state-error",!this.inRange(this.val,this.minValue,this.maxValue)).val(i?this.text:this.format(j));return this},modifyInput:function(i,h){var k=this.val;var l=this.minValue;var n=this.maxValue;k=k?k+h:h;k=(l!==null&&k<l)?l:(n!==null&&k>n)?n:k;var j=this.round(k,this.digits);this.trigger(j);var m=this.focused?this.formatEdit(j):this.format(j);i.removeClass("t-state-error").val(m)},formatEdit:function(i){var h=this.separator;if(i&&h!="."){i=i.toString().replace(".",h)}return i},format:function(h){return g.textbox.formatNumber(h,this.numFormat,this.digits,this.separator,this.groupSeparator,this.groupSize,this.positive,this.negative,this.symbol,true)},trigger:function(h){if(this.val!=h){if(g.trigger(this.element,"change",{oldValue:this.val,newValue:h})){return}d(".t-input:last",this.element).val(this.formatEdit(h));this.val=h}},parseTrigger:function(h){this.trigger(this.round(this.parse(h,this.separator),this.digits))},inRange:function(j,h,i){return(h!==null?j>=h:true)&&(i!==null?j<=i:true)},parse:function(h,j){var i=null;if(h||h=="0"){if(typeof h==typeof 1){return h}h=h.replace(this.replaceRegExp,"");if(j&&j!="."){h=h.replace(j,".")}i=parseFloat(h)}return isNaN(i)?null:i},round:function(i,h){if(i||i==0){return parseFloat(i.toFixed(h||2))}return null}};d.fn.tTextBox=function(j){var i=j.type;var h=d.fn.tTextBox.defaults[i];h.digits=g.cultureInfo[i+"decimaldigits"];h.separator=g.cultureInfo[i+"decimalseparator"];h.groupSeparator=g.cultureInfo[i+"groupseparator"];h.groupSize=g.cultureInfo[i+"groupsize"];h.positive=g.cultureInfo[i+"positive"];h.negative=g.cultureInfo[i+"negative"];h.symbol=g.cultureInfo[i+"symbol"];j=d.extend({},h,j);return this.each(function(){var k=d(this);j=d.meta?d.extend({},j,k.data()):j;if(!k.data("tTextBox")){k.data("tTextBox",new g.textbox(this,j));g.trigger(this,"load")}})};d.fn.tTextBox.defaults={numeric:{val:null,minValue:-100,maxValue:100,text:"",step:1},currency:{val:null,minValue:0,maxValue:1000,text:"",step:1},percent:{val:null,minValue:0,maxValue:100,text:"",step:1}};d.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(!g.cultureInfo.numericnegative){d.extend(g.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 c=/[0#?]/;function b(h){return h.split("").reverse().join("")}function f(n,h,k){var p=0,q=0;var s=h.length;var m=n.length;var u=new g.stringBuilder();while(p<s&&q<m&&h.substring(p).search(c)>=0){if(h.charAt(p).match(c)){u.cat(n.charAt(q));q++}else{u.cat(h.charAt(p))}p++}u.catIf(n.substring(q),q<m&&k).catIf(h.substring(p),p<s);var r=b(u.string());var o=r.indexOf("0");var l=r.indexOf("#");if(l!=-1){if(o!=-1){var v=r.slice(0,o);var t=r.slice(o,r.length);r=v.replace("#","")+t.replace("#","0")}else{r=r.replace("#","")}}return k?r:b(r)}g.textbox.formatNumber=function(K,n,s,u,i,Q,o,q,M,F){if(!n){return K}var P,G,L,m;var J=K<0;n=n.split(":");n=n.length>1?n[1].replace("}",""):n[0];var l=n.search(c)!=-1;if(l){n=n.split(";");G=n[0];L=n[1];m=n[2];n=(J&&L?L:G).indexOf("%")!=-1?"p":"n"}switch(n){case"d":case"D":return Math.round(K).toString();case"c":case"C":P="currency";break;case"n":case"N":P="numeric";break;case"p":case"P":P="percent";if(!F){K=Math.abs(K)*100}break;default:return K.toString()}var z=function(T,R,S){for(var U=T.length;U<R;U++){T=S?("0"+T):(T+"0")}return T};var I=function(S,U,R){if(i){var T=new RegExp("(-?[0-9]+)([0-9]{"+R+"})");while(T.test(S)){S=S.replace(T,"$1"+U+"$2")}}return S};var E=E||g.cultureInfo;var H=d.fn.tTextBox.patterns;var D;s=s||s===0?s:E[P+"decimaldigits"];u=u!==D?u:E[P+"decimalseparator"];i=i!==D?i:E[P+"groupseparator"];Q=Q||Q==0?Q:E[P+"groupsize"];q=q||q===0?q:E[P+"negative"];o=o||o===0?o:E[P+"positive"];M=M||E[P+"symbol"];var y,j,r;if(l){var C=(J&&L?L:G).split(".");var w=C[0];var A=C.length>1?C[1]:"";var h=g.lastIndexOf(A,"0");var x=g.lastIndexOf(A,"#");var s=(x>h?x:h)+1}var B=Math.pow(10,s);var N=(Math.round(K*B)/B);K=isFinite(N)?N:K;var v=K.toString().split(/e/i);y=v.length>1?parseInt(v[1]):0;v=v[0].split(".");j=v[0];j=J?j.replace("-",""):j;r=v.length>1?v[1]:"";if(y){if(!J){r=z(r,y,false);j+=r.slice(0,y);r=r.substr(y)}else{j=z(j,y+1,true);r=j.slice(y,j.length)+r;j=j.slice(0,y)}}var O=r.length;if(s<1||(l&&h==-1&&O===0)){r=""}else{r=O>s?r.slice(0,s):z(r,s,false)}var k;if(l){j=f(b(j),b(w),true);j=w.indexOf(",")!=-1?I(j,i,Q):j;r=r&&A?f(r,A):"";k=K===0&&m?m:(J&&!L?"-":"")+j+(r.length>0?u+r:"")}else{j=I(j,i,Q);H=H[P];var t=J?H.negative[q]:M?H.positive[o]:null;var p=j+(r.length>0?u+r:"");k=t?t.replace("n",p).replace("*",M):p}return k};d.extend(g.formatters,{number:g.textbox.formatNumber})})(jQuery);