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