You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
91 KiB
JavaScript

11 months ago
/*!
* jquery.inputmask.bundle.js
* http://github.com/RobinHerbots/jquery.inputmask
* Copyright (c) 2010 - 2015 Robin Herbots
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
* Version: 3.2.3-5
* @ThinkGem 新增money千分位格式别名举例如下
* $(".moneyMask").inputmask({alias:"money"}); // 金额数据格式(初始化完成表单后调用)
* $('.moneyMask').inputmask('remove'); // 金额数据格式化恢复(表单提交之前调用)
*/
!function($){function Inputmask(alias,options){return this instanceof Inputmask?("object"==typeof alias?options=alias:(options=options||{},options.alias=alias),this.el=void 0,this.opts=$.extend(!0,{},this.defaults,options),this.noMasksCache=options&&void 0!==options.definitions,this.userOptions=options||{},void resolveAlias(this.opts.alias,options,this.opts)):new Inputmask(alias,options)}function isInputEventSupported(eventName){var el=document.createElement("input"),evName="on"+eventName,isSupported=evName in el;return isSupported||(el.setAttribute(evName,"return;"),isSupported="function"==typeof el[evName]),el=null,isSupported}function isInputTypeSupported(inputType){var isSupported="text"===inputType||"tel"===inputType||"password"===inputType;if(!isSupported){var el=document.createElement("input");el.setAttribute("type",inputType),isSupported="text"===el.type,el=null}return isSupported}function resolveAlias(aliasStr,options,opts){var aliasDefinition=opts.aliases[aliasStr];return aliasDefinition?(aliasDefinition.alias&&resolveAlias(aliasDefinition.alias,void 0,opts),$.extend(!0,opts,aliasDefinition),$.extend(!0,opts,options),!0):(null===opts.mask&&(opts.mask=aliasStr),!1)}function importAttributeOptions(npt,opts,userOptions){function importOption(option){var optionData=npt.getAttribute("data-inputmask-"+option.toLowerCase());null!==optionData&&(optionData="boolean"==typeof optionData?optionData:optionData.toString(),"string"==typeof optionData&&0===option.indexOf("on")&&(optionData=eval("("+optionData+")")),"mask"===option&&0===optionData.indexOf("[")?(userOptions[option]=optionData.replace(/[\s[\]]/g,"").split(","),userOptions[option][0]=userOptions[option][0].replace("'",""),userOptions[option][userOptions[option].length-1]=userOptions[option][userOptions[option].length-1].replace("'","")):userOptions[option]=optionData)}var attrOptions=npt.getAttribute("data-inputmask");if(attrOptions&&""!==attrOptions){try{attrOptions=attrOptions.replace(new RegExp("'","g"),'"');var dataoptions=$.parseJSON("{"+attrOptions+"}");$.extend(!0,userOptions,dataoptions)}catch(ex){}}for(var option in opts){importOption(option)}if(userOptions.alias){resolveAlias(userOptions.alias,userOptions,opts);for(option in opts){importOption(option)}}return $.extend(!0,opts,userOptions),opts}function generateMaskSet(opts,nocache){function analyseMask(mask){function MaskToken(isGroup,isOptional,isQuantifier,isAlternator){this.matches=[],this.isGroup=isGroup||!1,this.isOptional=isOptional||!1,this.isQuantifier=isQuantifier||!1,this.isAlternator=isAlternator||!1,this.quantifier={min:1,max:1}}function insertTestDefinition(mtoken,element,position){var maskdef=opts.definitions[element];position=void 0!==position?position:mtoken.matches.length;var prevMatch=mtoken.matches[position-1];if(maskdef&&!escaped){maskdef.placeholder=$.isFunction(maskdef.placeholder)?maskdef.placeholder(opts):maskdef.placeholder;for(var prevalidators=maskdef.prevalidator,prevalidatorsL=prevalidators?prevalidators.length:0,i=1;i<maskdef.cardinality;i++){var prevalidator=prevalidatorsL>=i?prevalidators[i-1]:[],validator=prevalidator.validator,cardinality=prevalidator.cardinality;mtoken.matches.splice(position++,0,{fn:validator?"string"==typeof validator?new RegExp(validator):new function(){this.test=validator}():new RegExp("."),cardinality:cardinality?cardinality:1,optionality:mtoken.isOptional,newBlockMarker:void 0===prevMatch||prevMatch.def!==(maskdef.definitionSymbol||element),casing:maskdef.casing,def:maskdef.definitionSymbol||element,placeholder:maskdef.placeholder,mask:element}),prevMatch=mtoken.matches[position-1]}mtoken.matches.splice(position++,0,{fn:maskdef.validator?"string"==typeof maskdef.validator?new RegExp(maskdef.validator):new function(){this.test=maskdef.validator}():new RegExp("."),cardinality:maskdef.cardinality,optionality:mtoken.isOptional,newBlockMarker:void 0===prevMatch||prevMatch.def!==(maskdef.definitionSymbol||element),casing:maskdef.casing,def:maskdef.definitionSymbol||element,placeholder:maskdef.placeholder,mask:element})}else{mtoken.matches.splice(positi
}function writeBuffer(input,buffer,caretPos,event,triggerInputEvent){if(event&&$.isFunction(opts.onBeforeWrite)){var result=opts.onBeforeWrite.call(input,event,buffer,caretPos,opts);if(result){if(result.refreshFromBuffer){var refresh=result.refreshFromBuffer;refreshFromBuffer(refresh===!0?refresh:refresh.start,refresh.end,result.buffer||buffer),resetMaskSet(!0),buffer=getBuffer()}void 0!==caretPos&&(caretPos=void 0!==result.caret?result.caret:caretPos)}}input.inputmask._valueSet(buffer.join("")),void 0===caretPos||void 0!==event&&"blur"===event.type||caret(input,caretPos),triggerInputEvent===!0&&(skipInputEvent=!0,$(input).trigger("input"))}function getPlaceholder(pos,test){if(test=test||getTest(pos),void 0!==test.placeholder){return test.placeholder}if(null===test.fn){if(pos>-1&&!opts.keepStatic&&void 0===getMaskSet().validPositions[pos]){for(var prevTest,tests=getTests(pos),hasAlternations=!1,i=0;i<tests.length;i++){if(prevTest&&""!==tests[i].match.def&&tests[i].match.def!==prevTest.match.def&&(void 0===tests[i].alternation||tests[i].alternation===prevTest.alternation)){hasAlternations=!0;break}tests[i].match.optionality!==!0&&tests[i].match.optionalQuantifier!==!0&&(prevTest=tests[i])}if(hasAlternations){return opts.placeholder.charAt(pos%opts.placeholder.length)}}return test.def}return opts.placeholder.charAt(pos%opts.placeholder.length)}function checkVal(input,writeOut,strict,nptvl){function isTemplateMatch(){var isMatch=!1,charCodeNdx=getBufferTemplate().slice(initialNdx,seekNext(initialNdx)).join("").indexOf(charCodes);if(-1!==charCodeNdx&&!isMask(initialNdx)){isMatch=!0;for(var bufferTemplateArr=getBufferTemplate().slice(initialNdx,initialNdx+charCodeNdx),i=0;i<bufferTemplateArr.length;i++){if(" "!==bufferTemplateArr[i]){isMatch=!1;break}}}return isMatch}var inputValue=nptvl.slice(),charCodes="",initialNdx=0;if(resetMaskSet(),getMaskSet().p=seekNext(-1),!strict){if(opts.autoUnmask!==!0){var staticInput=getBufferTemplate().slice(0,seekNext(-1)).join(""),matches=inputValue.join("").match(new RegExp("^"+Inputmask.escapeRegex(staticInput),"g"));matches&&matches.length>0&&(inputValue.splice(0,matches.length*staticInput.length),initialNdx=seekNext(initialNdx))}else{initialNdx=seekNext(initialNdx)}}$.each(inputValue,function(ndx,charCode){var keypress=$.Event("keypress");keypress.which=charCode.charCodeAt(0),charCodes+=charCode;var lvp=getLastValidPosition(void 0,!0),lvTest=getMaskSet().validPositions[lvp],nextTest=getTestTemplate(lvp+1,lvTest?lvTest.locator.slice():void 0,lvp);if(!isTemplateMatch()||strict||opts.autoUnmask){var pos=strict?ndx:null==nextTest.match.fn&&nextTest.match.optionality&&lvp+1<getMaskSet().p?lvp+1:getMaskSet().p;keypressEvent.call(input,keypress,!0,!1,strict,pos),initialNdx=pos+1,charCodes=""}else{keypressEvent.call(input,keypress,!0,!1,!0,lvp+1)}}),writeOut&&writeBuffer(input,getBuffer(),document.activeElement===input?seekNext(getLastValidPosition(0)):void 0,$.Event("checkval"))}function unmaskedvalue(input){if(input&&void 0===input.inputmask){return input.value}var umValue=[],vps=getMaskSet().validPositions;for(var pndx in vps){vps[pndx].match&&null!=vps[pndx].match.fn&&umValue.push(vps[pndx].input)}var unmaskedValue=0===umValue.length?null:(isRTL?umValue.reverse():umValue).join("");if(null!==unmaskedValue){var bufferValue=(isRTL?getBuffer().slice().reverse():getBuffer()).join("");$.isFunction(opts.onUnMask)&&(unmaskedValue=opts.onUnMask.call(input,bufferValue,unmaskedValue,opts)||unmaskedValue)}return unmaskedValue}function caret(input,begin,end){function translatePosition(pos){if(isRTL&&"number"==typeof pos&&(!opts.greedy||""!==opts.placeholder)){var bffrLght=getBuffer().join("").length;pos=bffrLght-pos}return pos}var range;if("number"!=typeof begin){return input.setSelectionRange?(begin=input.selectionStart,end=input.selectionEnd):window.getSelection?(range=window.getSelection().getRangeAt(0),(range.commonAncestorContainer.parentNode===input||range.commonAncestorContainer===input)&&(begin=range.startOffset,end=range.endOffset)):document.selection&&document.selection.createRange&&(range=doc
},option:function(options){return"string"==typeof options?this.opts[options]:"object"==typeof options?($.extend(this.opts,options),$.extend(this.userOptions,options),this.el&&(void 0!==options.mask||void 0!==options.alias?this.mask(this.el):($.data(this.el,"_inputmask_opts",this.opts),maskScope({action:"mask",el:this.el}))),this):void 0},unmaskedvalue:function(value){return maskScope({action:"unmaskedvalue",el:this.el,value:value},this.el&&this.el.inputmask?this.el.inputmask.maskset:generateMaskSet(this.opts,this.noMasksCache),this.opts)},remove:function(){return this.el?(maskScope({action:"remove",el:this.el}),this.el.inputmask=void 0,this.el):void 0},getemptymask:function(){return maskScope({action:"getemptymask"},this.maskset||generateMaskSet(this.opts,this.noMasksCache),this.opts)},hasMaskedValue:function(){return !this.opts.autoUnmask},isComplete:function(){return maskScope({action:"isComplete",el:this.el},this.maskset||generateMaskSet(this.opts,this.noMasksCache),this.opts)},getmetadata:function(){return maskScope({action:"getmetadata"},this.maskset||generateMaskSet(this.opts,this.noMasksCache),this.opts)},isValid:function(value){return maskScope({action:"isValid",value:value},this.maskset||generateMaskSet(this.opts,this.noMasksCache),this.opts)},format:function(value,metadata){return maskScope({action:"format",value:value,metadata:metadata},this.maskset||generateMaskSet(this.opts,this.noMasksCache),this.opts)}},Inputmask.extendDefaults=function(options){$.extend(Inputmask.prototype.defaults,options)},Inputmask.extendDefinitions=function(definition){$.extend(Inputmask.prototype.defaults.definitions,definition)},Inputmask.extendAliases=function(alias){$.extend(Inputmask.prototype.defaults.aliases,alias)},Inputmask.format=function(value,options,metadata){return Inputmask(options).format(value,metadata)},Inputmask.unmask=function(value,options){return Inputmask(options).unmaskedvalue(value)},Inputmask.isValid=function(value,options){return Inputmask(options).isValid(value)},Inputmask.escapeRegex=function(str){var specials=["/",".","*","+","?","|","(",")","[","]","{","}","\\","$","^"];return str.replace(new RegExp("(\\"+specials.join("|\\")+")","gim"),"\\$1")},Inputmask.keyCode={ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91};var ua=navigator.userAgent,iphone=null!==ua.match(new RegExp("iphone","i")),androidchrome=null!==ua.match(new RegExp("android.*chrome.*","i")),androidfirefox=null!==ua.match(new RegExp("android.*firefox.*","i")),PasteEventType=isInputEventSupported("paste")?"paste":isInputEventSupported("input")?"input":"propertychange";return window.Inputmask=Inputmask,Inputmask}(jQuery),function(b,a){return void 0===b.fn.inputmask&&(b.fn.inputmask=function(e,d){var f,c;if(d=d||{},"string"==typeof e){switch(e){case"mask":return f=new a(d),this.each(function(){f.mask(this)});case"unmaskedvalue":return c=this.jquery&&this.length>0?this[0]:this,c.inputmask?c.inputmask.unmaskedvalue():b(c).val();case"remove":return this.each(function(){this.inputmask&&this.inputmask.remove()});case"getemptymask":return c=this.jquery&&this.length>0?this[0]:this,c.inputmask?c.inputmask.getemptymask():"";case"hasMaskedValue":return c=this.jquery&&this.length>0?this[0]:this,c.inputmask?c.inputmask.hasMaskedValue():!1;case"isComplete":return c=this.jquery&&this.length>0?this[0]:this,c.inputmask?c.inputmask.isComplete():!0;case"getmetadata":return c=this.jquery&&this.length>0?this[0]:this,c.inputmask?c.inputmask.getmetadata():void 0;case"setvalue":c=this.jquery&&this.length>0?this[0]:this,b(c).val(d),void 0!==c.inputmask&&b(c).triggerHandler("setvalue.inputmask");break;case"option":if("string"!=typeof d){return this.each(function(){return void 0!==this.inputmask?this.inputmask.option(d):void 0})}if(c=this.jquery&&this.leng
},error:function(g,e,f){alert(f+" - "+c.url)}}),d=d.sort(function(f,e){return(f.mask||f)<(e.mask||e)?-1:1})},keepStatic:!1,nojumps:!0,nojumpsThreshold:1,onBeforeMask:function(e,d){var c=e.replace(/^0/g,"");return(c.indexOf(d.countrycode)>1||-1===c.indexOf(d.countrycode))&&(c="+"+d.countrycode+c),c}},phonebe:{alias:"phone",url:"phone-codes/phone-be.js",countrycode:"32",nojumpsThreshold:4}}),a}(jQuery,Inputmask),function(b,a){return a.extendAliases({Regex:{mask:"r",greedy:!1,repeat:"*",regex:null,regexTokens:null,tokenizer:/\[\^?]?(?:[^\\\]]+|\\[\S\s]?)*]?|\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9][0-9]*|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Za-z]|[\S\s]?)|\((?:\?[:=!]?)?|(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[()|\\]+|./g,quantifierFilter:/[0-9]+[^,]/,isComplete:function(c,d){return new RegExp(d.regex).test(c.join(""))},definitions:{r:{validator:function(f,o,m,n,c){function k(t,i){this.matches=[],this.isGroup=t||!1,this.isQuantifier=i||!1,this.quantifier={min:1,max:1},this.repeaterPart=void 0}function r(){var z,v,x=new k(),A=[];for(c.regexTokens=[];z=c.tokenizer.exec(c.regex);){switch(v=z[0],v.charAt(0)){case"(":A.push(new k(!0));break;case")":j=A.pop(),A.length>0?A[A.length-1].matches.push(j):x.matches.push(j);break;case"{":case"+":case"*":var i=new k(!1,!0);v=v.replace(/[{}]/g,"");var t=v.split(","),w=isNaN(t[0])?t[0]:parseInt(t[0]),u=1===t.length?w:isNaN(t[1])?t[1]:parseInt(t[1]);if(i.quantifier={min:w,max:u},A.length>0){var y=A[A.length-1].matches;z=y.pop(),z.isGroup||(j=new k(!0),j.matches.push(z),z=j),y.push(z),y.push(i)}else{z=x.matches.pop(),z.isGroup||(j=new k(!0),j.matches.push(z),z=j),x.matches.push(z),x.matches.push(i)}break;default:A.length>0?A[A.length-1].matches.push(v):x.matches.push(v)}}x.matches.length>0&&c.regexTokens.push(x)}function p(z,u){var w=!1;u&&(s+="(",d++);for(var E=0;E<z.matches.length;E++){var F=z.matches[E];if(F.isGroup===!0){w=p(F,!0)}else{if(F.isQuantifier===!0){var x=b.inArray(F,z.matches),v=z.matches[x-1],G=s;if(isNaN(F.quantifier.max)){for(;F.repeaterPart&&F.repeaterPart!==s&&F.repeaterPart.length>s.length&&!(w=p(v,!0));){}w=w||p(v,!0),w&&(F.repeaterPart=s),s=G+F.quantifier.max}else{for(var D=0,I=F.quantifier.max-1;I>D&&!(w=p(v,!0));D++){}s=G+"{"+F.quantifier.min+","+F.quantifier.max+"}"}}else{if(void 0!==F.matches){for(var B=0;B<F.length&&!(w=p(F[B],u));B++){}}else{var t;if("["==F.charAt(0)){t=s,t+=F;for(var C=0;d>C;C++){t+=")"}var A=new RegExp("^("+t+")$");w=A.test(g)}else{for(var y=0,H=F.length;H>y;y++){if("\\"!==F.charAt(y)){t=s,t+=F.substr(0,y+1),t=t.replace(/\|$/,"");for(var C=0;d>C;C++){t+=")"}var A=new RegExp("^("+t+")$");if(w=A.test(g)){break}}}}s+=F}}}if(w){break}}return u&&(s+=")",d--),w}var j,e=o.buffer.slice(),s="",q=!1,d=0;null===c.regexTokens&&r(),e.splice(m,0,f);for(var g=e.join(""),h=0;h<c.regexTokens.length;h++){var l=c.regexTokens[h];if(q=p(l,l.isGroup)){break}}return q},cardinality:1}}}}),a}(jQuery,Inputmask);