-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathangular-numeric-input.min.js
2 lines (2 loc) · 1.79 KB
/
angular-numeric-input.min.js
1
2
!function(){"use strict";angular.module("ui.numericInput",[]).directive("uiNumericInput",["$filter",function(t){return{restrict:"A",require:"ngModel",link:function(e,r,n,a){function u(t){var e=parseFloat(t),r=Math.pow(10,w);return Math.round(e*r)/r}function i(t){return parseFloat(t).toFixed(w)}function s(t){var e=0,r=(t+"").match(/,/g);return r&&(e=r.length),e}function o(t){return a.$isEmpty(t)?"":""+t}function l(e){return t("number")(e)}function c(t){var e=0,r=(t+"").match(/\d/g);return r&&(e=r.length),e}function m(t){var e=v?t<=x:t<x;return!a.$isEmpty(t)&&e?a.$setValidity("min",!1):a.$setValidity("min",!0),t}function $(t){var e=g?t>=d:t>d;return!a.$isEmpty(t)&&e?a.$setValidity("max",!1):a.$setValidity("max",!0),t}var d,f,p,h,v,g,V=/^\s*[-+]?(\d+|\d*\.\d*)\s*$/,x=1,y=!0,E=9,w=0;n.maxLength>=1&&(E=n.maxLength),n.allowDecimal&&(y=!1,w=2,x=0),n.minNotEqual&&(v=!0),n.maxNotEqual&&(g=!0),a.$parsers.push(function(t){(angular.isUndefined(t)||t!==t)&&(t="");var e=t.replace(/\,/g,""),r=e.substr(e.length-1);y||(p="."===r),0===e.indexOf(".")&&(e="0"+e),h=/\d*\.0$/.test(e);var n=a.$isEmpty(e);return n||V.test(e)&&c(e)<=E?f=""===e?null:n?e:u(e):(a.$setViewValue(o(f)),a.$render()),a.$setValidity("numeric",!p),f}),a.$formatters.push(l),n.$observe("min",function(t){x=parseFloat(t||x),m(a.$modelValue)}),a.$parsers.push(m),a.$formatters.push(m),angular.isDefined(n.max)&&(n.$observe("max",function(t){d=parseFloat(t),$(a.$modelValue)}),a.$parsers.push($),a.$formatters.push($)),a.$formatters.push(function(t){return t?i(t):t}),a.$parsers.push(function(t){var e=l(t);!y&&p&&(e+="."),!y&&h&&(e+=".0");var n=r[0].selectionStart,u=r[0].selectionEnd,i=a.$viewValue;return s(i)>s(e)&&(n--,u--),s(i)<s(e)&&(n++,u++),a.$viewValue=e,a.$render(),r[0].setSelectionRange(n,u),t})}}}])}();
//# sourceMappingURL=angular-numeric-input.min.js.map