ldc-sbv/wp-content/plugins/ninja-forms/assets/js/lib/jquery.autoNumeric.min.js

36 lines
20 KiB
JavaScript
Raw Normal View History

2021-09-21 15:01:08 +02:00
/**
* autoNumeric.js
* @author: Bob Knothe
* @author: Sokolov Yura aka funny_falcon
* @version: 1.9.15 - 2013-08-05 GMT 6:30 PM
*
* Created by Robert J. Knothe on 2010-10-25. Please report any bugs to https://github.com/BobKnothe/autoNumeric
* Created by Sokolov Yura on 2010-11-07
*
* Copyright (c) 2011 Robert J. Knothe http://www.decorplanit.com/plugin/
*
* The MIT License (http://www.opensource.org/licenses/mit-license.php)
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
(function(e){"use strict";function t(e){var t={};if(e.selectionStart===undefined){e.focus();var n=document.selection.createRange();t.length=n.text.length;n.moveStart("character",-e.value.length);t.end=n.text.length;t.start=t.end-t.length}else{t.start=e.selectionStart;t.end=e.selectionEnd;t.length=t.end-t.start}return t}function n(e,t,n){if(e.selectionStart===undefined){e.focus();var r=e.createTextRange();r.collapse(true);r.moveEnd("character",n);r.moveStart("character",t);r.select()}else{e.selectionStart=t;e.selectionEnd=n}}function r(t,n){e.each(n,function(e,r){if(typeof r==="function"){n[e]=r(t,n,e)}else if(typeof t.autoNumeric[r]==="function"){n[e]=t.autoNumeric[r](t,n,e)}})}function i(e,t){if(typeof e[t]==="string"){e[t]*=1}}function s(e,t){r(e,t);t.oEvent=null;t.tagList=["B","CAPTION","CITE","CODE","DD","DEL","DIV","DFN","DT","EM","H1","H2","H3","H4","H5","H6","INS","KDB","LABEL","LI","OUTPUT","P","Q","S","SAMPLE","SPAN","STRONG","TD","TH","U","VAR"];var n=t.vMax.toString().split("."),s=!t.vMin&&t.vMin!==0?[]:t.vMin.toString().split(".");i(t,"vMax");i(t,"vMin");i(t,"mDec");t.allowLeading=true;t.aNeg=t.vMin<0?"-":"";n[0]=n[0].replace("-","");s[0]=s[0].replace("-","");t.mInt=Math.max(n[0].length,s[0].length,1);if(t.mDec===null){var o=0,u=0;if(n[1]){o=n[1].length}if(s[1]){u=s[1].length}t.mDec=Math.max(o,u)}if(t.altDec===null&&t.mDec>0){if(t.aDec==="."&&t.aSep!==","){t.altDec=","}else if(t.aDec===","&&t.aSep!=="."){t.altDec="."}}var a=t.aNeg?"([-\\"+t.aNeg+"]?)":"(-?)";t.aNegRegAutoStrip=a;t.skipFirstAutoStrip=new RegExp(a+"[^-"+(t.aNeg?"\\"+t.aNeg:"")+"\\"+t.aDec+"\\d]"+".*?(\\d|\\"+t.aDec+"\\d)");t.skipLastAutoStrip=new RegExp("(\\d\\"+t.aDec+"?)[^\\"+t.aDec+"\\d]\\D*$");var f="-"+t.aNum+"\\"+t.aDec;t.allowedAutoStrip=new RegExp("[^"+f+"]","gi");t.numRegAutoStrip=new RegExp(a+"(?:\\"+t.aDec+"?(\\d+\\"+t.aDec+"\\d+)|(\\d*(?:\\"+t.aDec+"\\d*)?))");return t}function o(e,t,n){if(t.aSign){while(e.indexOf(t.aSign)>-1){e=e.replace(t.aSign,"")}}e=e.replace(t.skipFirstAutoStrip,"$1$2");e=e.replace(t.skipLastAutoStrip,"$1");e=e.replace(t.allowedAutoStrip,"");if(t.altDec){e=e.replace(t.altDec,t.aDec)}var r=e.match(t.numRegAutoStrip);e=r?[r[1],r[2],r[3]].join(""):"";if((t.lZero==="allow"||t.lZero==="keep")&&n!=="strip"){var i=[],s="";i=e.split(t.aDec);if(i[0].indexOf("-")!==-1){s="-";i[0]=i[0].replace("-","")}if(i[0].length>t.mInt&&i[0].charAt(0)==="0"){i[0]=i[0].slice(1)}e=s+i.join(t.aDec)}if(n&&t.lZero==="deny"||n&&t.lZero==="allow"&&t.allowLeading===false){var o="^"+t.aNegRegAutoStrip+"0*(\\d"+(n==="leading"?")":"|$)");o=new RegExp(o);e=e.replace(o,"$1$2")}return e}function u(e,t,n){t=t.split(",");if(n==="set"||n==="focusout"){e=e.replace("-","");e=t[0]+e+t[1]}else if((n==="get"||n==="focusin"||n==="pageLoad")&&e.charAt(0)===t[0]){e=e.replace(t[0],"-");e=e.replace(t[1],"")}return e}function a(e,t,n){if(t&&n){var r=e.split(t);if(r[1]&&r[1].length>n){if(n>0){r[1]=r[1].substring(0,n);e=r.join(t)}else{e=r[0]}}}return e}function f(e,t,n){if(t&&t!=="."){e=e.replace(t,".")}if(n&&n!=="-"){e=e.replace(n,"-")}if(!e.match(/\d/)){e+="0"}return e}function l(e){var t=e.indexOf(".");if(t!==-1){if(t===1&&e.charAt(0)==="0"){e=+e;if(e<1e-6&&e>0){e=(e+1).toString();e=e.substring(1)}if(e<0&&e>-1){e=(e-1).toString();e="-"+e.substring(2)}e=e.toString()}else{var n=e.split(".");if(n[1]!==undefined){if(+n[1]===0){e=n[0]}else{n[1]=n[1].replace(/0*$/,"");e=n.join(".")}}}}return e.replace(/^0*(\d)/,"$1")}function c(e,t,n){if(n&&n!=="-"){e=e.replace("-",n)}if(t&&t!=="."){e=e.replace(".",t)}return e}function h(t,n){t=o(t,n);t=a(t,n.aDec,n.mDec);t=f(t,n.aDec,n.aNeg);var r=+t;if(n.oEvent==="set"&&(r<n.vMin||r>n.vMax)){e.error("The value ("+r+") from the 'set' method falls outside of the vMin / vMax range")}return r>=n.vMin&&r<=n.vMax}function p(e,t,n){if(e===""||e===t.aNeg){if(t.wEmpty==="zero"){return e+"0"}if(t.wEmpty==="sign"||n){return e+t.aSign}return e}return null}function d(e,t){e=o(e,t);var n=e.replace(",","."),r=p(e,t,true);if(r!==null){return r}var i="";if(t.dGroup===2){i=/(\d)((\d)(\d{2}?)+)$/}else if(t.dGroup===4){i=/(\d)((\d{4}?)+)$/}else{i=/(\