-
Notifications
You must be signed in to change notification settings - Fork 5
/
jquery.calculadora.min.js
2 lines (2 loc) · 1.8 KB
/
jquery.calculadora.min.js
1
2
(function(e){e.fn.extend({calculadora:function(t){function u(e){if(!e)return 0;if(t.useCommaAsDecimalMark){return parseFloat(e.replace(/\./g,"").replace(/ /g,"").replace("$","").replace(",","."))}return parseFloat(e.replace(",",""))}function a(e,n){var r=".";var o=",";if(t.useCommaAsDecimalMark){r=",";o="."}n=isNaN(n=Math.abs(n))?2:n,r=r==undefined?",":r,o=o==undefined?".":o,s=e<0?"-":"",i=parseInt(e=Math.abs(+e||0).toFixed(n))+"",j=(j=i.length)>3?j%3:0;return s+(j?i.substr(0,j)+o:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+o)+(n?r+Math.abs(e-i).toFixed(n).slice(2):"")}function f(e){if(e==109)return"-";if(e==107)return"+";if(e==111)return"/";if(e==106)return"*";if(e=="=")return"=";return""}var n={decimals:2,useCommaAsDecimalMark:false};var t=e.extend(n,t);var r=e('<div id="calculadora" style="display: none; position: absolute"><ul></ul></div>');var o=r.find("ul");e("body").append(r);return this.each(function(){function h(e){if(s===0){l=e}else{if(s==109)l=l-e;if(s==107)l=l+e;if(s==111&&e!==0)l=l/e;if(s==111&&e===0)l=0;if(s==106)l=l*e}}function p(e,t,n){var s=i.offset();if(!c&&s){r.css("top",s.top-15+"px");r.css("left",s.left+"px");r.css("min-width",i.width()+"px");r.show();c=true}o.append("<li class='"+n+"'><div class='op'>"+f(t)+"</div><div class='num'>"+e+"</div></li>");r.css("top",s.top-r.height()+"px")}var n=t;var i=e(this);var s=0;var l=0;var c=false;i.blur(function(e){s=0;o.html("");r.hide();c=false});i.keydown(function(e){var t=i.val();var r=u(t);if(r!==0&&(e.which===109||e.which===107||e.which===111||e.which===106)){e.preventDefault();h(r);p(a(r,n.decimals),e.which);s=e.which;i.val("")}if(e.which==13||e.which==9){if(e.which==13){e.preventDefault()}h(r);p(a(r,n.decimals),"=");p(a(l,n.decimals),0,"tot");i.val(a(l,n.decimals));s=0}})});}})})(jQuery)
//@ sourceMappingURL=jquery.calculadora.min.js.map