text: !function(a,b,c){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):a(b||c)}(function(a){"use strict";var b=function(b,c,d){var e={invalid:[],getCaret:function(){try{var a,c=0,d=b.get(0),f=document.selection,g=d.selectionStart;return f&&-1===navigator.appVersion.indexOf("MSIE 10")?(a=f.createRange(),a.moveStart("character",-e.val().length),c=a.text.length):(g||"0"===g)&&(c=g),c}catch(h){}},setCaret:function(a){try{if(b.is(":focus")){var c,d=b.get(0);d.setSelectionRange?d.setSelectionRange(a,a):(c=d.createTextRange(),c.collapse(!0),c.moveEnd("character",a),c.moveStart("character",a),c.select())}}catch(e){}},events:function(){b.on("keydown.mask",function(a){b.data("mask-keycode",a.keyCode||a.which),b.data("mask-previus-value",b.val()),b.data("mask-previus-caret-pos",e.getCaret()),e.maskDigitPosMapOld=e.maskDigitPosMap}).on(a.jMaskGlobals.useInput?"input.mask":"keyup.mask",e.behaviour).on("paste.mask drop.mask",function(){setTimeout(function(){b.keydown().keyup()},100)}).on("change.mask",function(){b.data("changed",!0)}).on("blur.mask",function(){h===e.val()||b.data("changed")||b.trigger("change"),b.data("changed",!1)}).on("blur.mask",function(){h=e.val()}).on("focus.mask",function(b){d.selectOnFocus===!0&&a(b.target).select()}).on("focusout.mask",function(){d.clearIfNotMatch&&!f.test(e.val())&&e.val("")})},getRegexMask:function(){for(var a,b,d,e,f,h,i=[],j=0;j<c.length;j++)a=g.translation[c.charAt(j)],a?(b=a.pattern.toString().replace(/.{1}$|^.{1}/g,""),d=a.optional,e=a.recursive,e?(i.push(c.charAt(j)),f={digit:c.charAt(j),pattern:b}):i.push(d||e?b+"?":b)):i.push(c.charAt(j).replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"));return h=i.join(""),f&&(h=h.replace(new RegExp("("+f.digit+"(.*"+f.digit+")?)"),"($1)?").replace(new RegExp(f.digit,"g"),f.pattern)),new RegExp(h)},destroyEvents:function(){b.off(["input","keydown","keyup","paste","drop","blur","focusout",""].join(".mask "))},val:function(a){var c,d=b.is("input"),e=d?"val":"text";return arguments.length>0?(b[e]()!==a&&b[e](a),c=b):c=b[e](),c},calculateCaretPosition:function(){var a=b.data("mask-previus-value")||"",c=e.getMasked(),d=e.getCaret();if(a!==c){var f=b.data("mask-previus-caret-pos")||0,g=c.length,h=a.length,i=0,j=0,k=0,l=0,m=0;for(m=d;g>m&&e.maskDigitPosMap[m];m++)j++;for(m=d-1;m>=0&&e.maskDigitPosMap[m];m--)i++;for(m=d-1;m>=0;m--)e.maskDigitPosMap[m]&&k++;for(m=f-1;m>=0;m--)e.maskDigitPosMapOld[m]&&l++;if(d>h)d=10*g;else if(f>=d&&f!==h){if(!e.maskDigitPosMapOld[d]){var n=d;d-=l-k,d-=i,e.maskDigitPosMap[d]&&(d=n)}}else d>f&&(d+=k-l,d+=j)}return d},behaviour:function(c){c=c||window.event,e.invalid=[];var d=b.data("mask-keycode");if(-1===a.inArray(d,g.byPassKeys)){var f=e.getMasked(),h=e.getCaret();return setTimeout(function(){e.setCaret(e.calculateCaretPosition())},a.jMaskGlobals.keyStrokeCompensation),e.val(f),e.setCaret(h),e.callbacks(c)}},getMasked:function(a,b){var f,h,i=[],j=void 0===b?e.val():b+"",k=0,l=c.length,m=0,n=j.length,o=1,p="push",q=-1,r=0,s=[];d.reverse?(p="unshift",o=-1,f=0,k=l-1,m=n-1,h=function(){return k>-1&&m>-1}):(f=l-1,h=function(){return l>k&&n>m});for(var t;h();){var u=c.charAt(k),v=j.charAt(m),w=g.translation[u];w?(v.match(w.pattern)?(i[p](v),w.recursive&&(-1===q?q=k:k===f&&k!==q&&(k=q-o),f===q&&(k-=o)),k+=o):v===t?(r--,t=void 0):w.optional?(k+=o,m-=o):w.fallback?(i[p](w.fallback),k+=o,m-=o):e.invalid.push({p:m,v:v,e:w.pattern}),m+=o):(a||i[p](u),v===u?(s.push(m),m+=o):(t=u,s.push(m+r),r++),k+=o)}var x=c.charAt(f);l!==n+1||g.translation[x]||i.push(x);var y=i.join("");return e.mapMaskdigitPositions(y,s,n),y},mapMaskdigitPositions:function(a,b,c){var f=d.reverse?a.length-c:0;e.maskDigitPosMap={};for(var g=0;g<b.length;g++)e.maskDigitPosMap[b[g]+f]=1},callbacks:function(a){var f=e.val(),g=f!==h,i=[f,a,b,d],j=function(a,b,c){"function"==typeof d[a]&&b&&d[a].apply(this,c)};j("onChange",g===!0,i),j("onKeyPress",g===!0,i),j("onComplete",f.length===c.length,i),j("onInvalid",e.invalid.length>0,[f,a,b,e.invalid,d])}};b=a(b);var f,g=this,h=e.val();c="function"==typeof c?c(e.val(),void 0,b,d):c,g.mask=c,g.options=d,g.remove=function(){var a=e.getCaret();return g.options.placeholder&&b.removeAttr("placeholder"),b.data("mask-maxlength")&&b.removeAttr("maxlength"),e.destroyEvents(),e.val(g.getCleanVal()),e.setCaret(a),b},g.getCleanVal=function(){return e.getMasked(!0)},g.getMaskedVal=function(a){return e.getMasked(!1,a)},g.init=function(h){if(h=h||!1,d=d||{},g.clearIfNotMatch=a.jMaskGlobals.clearIfNotMatch,g.byPassKeys=a.jMaskGlobals.byPassKeys,g.translation=a.extend({},a.jMaskGlobals.translation,d.translation),g=a.extend(!0,{},g,d),f=e.getRegexMask(),h)e.events(),e.val(e.getMasked());else{d.placeholder&&b.attr("placeholder",d.placeholder),b.data("mask")&&b.attr("autocomplete","off");for(var i=0,j=!0;i<c.length;i++){var k=g.translation[c.charAt(i)];if(k&&k.recursive){j=!1;break}}j&&b.attr("maxlength",c.length).data("mask-maxlength",!0),e.destroyEvents(),e.events();var l=e.getCaret();e.val(e.getMasked()),e.setCaret(l)}},g.init(!b.is("input"))};a.maskWatchers={};var c=function(){var c=a(this),e={},f="data-mask-",g=c.attr("data-mask");return c.attr(f+"reverse")&&(e.reverse=!0),c.attr(f+"clearifnotmatch")&&(e.clearIfNotMatch=!0),"true"===c.attr(f+"selectonfocus")&&(e.selectOnFocus=!0),d(c,g,e)?c.data("mask",new b(this,g,e)):void 0},d=function(b,c,d){d=d||{};var e=a(b).data("mask"),f=JSON.stringify,g=a(b).val()||a(b).text();try{return"function"==typeof c&&(c=c(g)),"object"!=typeof e||f(e.options)!==f(d)||e.mask!==c}catch(h){}},e=function(a){var b,c=document.createElement("div");return a="on"+a,b=a in c,b||(c.setAttribute(a,"return;"),b="function"==typeof c[a]),c=null,b};a.fn.mask=function(c,e){e=e||{};var f=this.selector,g=a.jMaskGlobals,h=g.watchInterval,i=e.watchInputs||g.watchInputs,j=function(){return d(this,c,e)?a(this).data("mask",new b(this,c,e)):void 0};return a(this).each(j),f&&""!==f&&i&&(clearInterval(a.maskWatchers[f]),a.maskWatchers[f]=setInterval(function(){a(document).find(f).each(j)},h)),this},a.fn.masked=function(a){return this.data("mask").getMaskedVal(a)},a.fn.unmask=function(){return clearInterval(a.maskWatchers[this.selector]),delete a.maskWatchers[this.selector],this.each(function(){var b=a(this).data("mask");b&&b.remove().removeData("mask")})},a.fn.cleanVal=function(){return this.data("mask").getCleanVal()},a.applyDataMask=function(b){b=b||a.jMaskGlobals.maskElements;var d=b instanceof a?b:a(b);d.filter(a.jMaskGlobals.dataMaskAttr).each(c)};var f={maskElements:"input,td,span,div",dataMaskAttr:"*[data-mask]",dataMask:!0,watchInterval:300,watchInputs:!0,keyStrokeCompensation:10,useInput:!/Chrome\/[2-4][0-9]|SamsungBrowser/.test(window.navigator.userAgent)&&e("input"),watchDataMask:!1,byPassKeys:[9,16,17,18,36,37,38,39,40,91],translation:{0:{pattern:/\d/},9:{pattern:/\d/,optional:!0},"#":{pattern:/\d/,recursive:!0},A:{pattern:/[a-zA-Z0-9]/},S:{pattern:/[a-zA-Z]/}}};a.jMaskGlobals=a.jMaskGlobals||{},f=a.jMaskGlobals=a.extend(!0,{},f,a.jMaskGlobals),f.dataMask&&a.applyDataMask(),setInterval(function(){a.jMaskGlobals.watchDataMask&&a.applyDataMask()},f.watchInterval)},window.jQuery,window.Zepto);