35 lines
28 KiB
JavaScript
35 lines
28 KiB
JavaScript
|
|
/**
|
||
|
|
* autoNumeric.js
|
||
|
|
* @author: Bob Knothe
|
||
|
|
* @author: Sokolov Yura
|
||
|
|
* @version: 1.9.25 - 2014-08-02 GMT 11:00 AM
|
||
|
|
*
|
||
|
|
* 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($){function getElementSelection(that){var position={};if(that.selectionStart===undefined){that.focus();var select=document.selection.createRange();position.length=select.text.length;select.moveStart("character",-that.value.length);position.end=select.text.length;position.start=position.end-position.length}else{position.start=that.selectionStart;position.end=that.selectionEnd;position.length=position.end-position.start}return position}function setElementSelection(that,start,end){if(that.selectionStart===undefined){that.focus();var r=that.createTextRange();r.collapse(true);r.moveEnd("character",end);r.moveStart("character",start);r.select()}else{that.selectionStart=start;that.selectionEnd=end}}function runCallbacks($this,settings){$.each(settings,function(k,val){if(typeof val==="function"){settings[k]=val($this,settings,k)}else{if(typeof $this.autoNumeric[val]==="function"){settings[k]=$this.autoNumeric[val]($this,settings,k)}}})}function convertKeyToNumber(settings,key){if(typeof(settings[key])==="string"){settings[key]*=1}}function autoCode($this,settings){runCallbacks($this,settings);settings.oEvent=null;settings.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 vmax=settings.vMax.toString().split("."),vmin=(!settings.vMin&&settings.vMin!==0)?[]:settings.vMin.toString().split(".");convertKeyToNumber(settings,"vMax");convertKeyToNumber(settings,"vMin");convertKeyToNumber(settings,"mDec");settings.mDec=(settings.mRound==="CHF")?"2":settings.mDec;settings.allowLeading=true;settings.aNeg=settings.vMin<0?"-":"";vmax[0]=vmax[0].replace("-","");vmin[0]=vmin[0].replace("-","");settings.mInt=Math.max(vmax[0].length,vmin[0].length,1);if(settings.mDec===null){var vmaxLength=0,vminLength=0;if(vmax[1]){vmaxLength=vmax[1].length}if(vmin[1]){vminLength=vmin[1].length}settings.mDec=Math.max(vmaxLength,vminLength)}if(settings.altDec===null&&settings.mDec>0){if(settings.aDec==="."&&settings.aSep!==","){settings.altDec=","}else{if(settings.aDec===","&&settings.aSep!=="."){settings.altDec="."}}}var aNegReg=settings.aNeg?"([-\\"+settings.aNeg+"]?)":"(-?)";settings.aNegRegAutoStrip=aNegReg;settings.skipFirstAutoStrip=new RegExp(aNegReg+"[^-"+(settings.aNeg?"\\"+settings.aNeg:"")+"\\"+settings.aDec+"\\d].*?(\\d|\\"+settings.aDec+"\\d)");settings.skipLastAutoStrip=new RegExp("(\\d\\"+settings.aDec+"?)[^\\"+settings.aDec+"\\d]\\D*$");var allowed="-"+settings.aNum+"\\"+settings.aDec;settings.allowedAutoStrip=new RegExp("[^"+allowed+"]","gi");settings.numRegAutoStrip=new RegExp(aNegReg+"(?:\\"+settings.aDec+"?(\\d+\\"+settings.aDec+"\\d+)|(\\d*(?:\\"+settings.aDec+"\\d*)?))");return settings}function autoStrip(s,settings,strip_zero){if(settings.aSign){while(s.indexOf(settings.aSign)>-1){s=s.replace(settings.aSign,"")}}s=s.replace(settings.skipFirstAutoStrip,"$1$2");s=s.replace(settings.skipLastAutoStrip,"$1");s=s.replace(settings.allowedAutoStrip,"");if(settings.altDec){s=s.replace(settings.altDec,settings.aDec)}var m=s.match(settings.numRegAutoStrip);s=m?[m[1],m[2],m[3]].join(""):"";if((settings.lZero==="allow"||settings.lZero==="keep")&&strip_zero!=="strip"){var parts=[],nSign="";parts=s.split(settings.aDec);if(parts[0].indexOf("-")!==-1){nSign="-";parts[0]=parts[0].replace("-","")}if(parts[0].length>settings.mInt&&parts[0].charAt(0)==="0"){parts[0]=parts[0].slice(1)}s=nSign+parts.join(settings.aDec)}if((strip_zero&&settings.lZero==="deny")||(strip_zero&&settings.lZero==="allow"&&settings.allowLeading===false)){var strip_reg="^"+settings.aNegRegAutoStrip+"0*(\\d"+(strip_zero==="leading"?")":"|$)");strip_reg=new RegExp(strip_reg);s=s.replace(strip_reg,"$1$2")}return s}function negativeBracket(s,nBracket,oEvent){nBracket=nBracket.split(",");if(oEvent==="set"||oEvent==="focusout"){s=s.replace("-","");s=nBracket[0]+s+nBracket[1]}else{if((oEvent==="get"||oEvent==="focusin"||oEvent==="pageLoad")&&s.charAt(0)===nBracket[0]){s=s.replace(nBracket[0],"-");s=s.replace(nBracket[1],"")}}return s}functio
|