(function(n,t,i){typeof define=="function"&&define.amd?define(["jquery"],n):typeof exports=="object"&&typeof Meteor=="undefined"?module.exports=n(require("jquery")):n(t||i)})(function(n){"use strict";var i=function(t,i,r){var u={invalid:[],getCaret:function(){try{var n,i=0,e=t.get(0),f=document.selection,r=e.selectionStart;return f&&navigator.appVersion.indexOf("MSIE 10")===-1?(n=f.createRange(),n.moveStart("character",-u.val().length),i=n.text.length):(r||r==="0")&&(i=r),i}catch(o){}},setCaret:function(n){try{if(t.is(":focus")){var i,r=t.get(0);r.setSelectionRange?r.setSelectionRange(n,n):(i=r.createTextRange(),i.collapse(!0),i.moveEnd("character",n),i.moveStart("character",n),i.select())}}catch(u){}},events:function(){t.on("keydown.mask",function(n){t.data("mask-keycode",n.keyCode||n.which);t.data("mask-previus-value",t.val());t.data("mask-previus-caret-pos",u.getCaret());u.maskDigitPosMapOld=u.maskDigitPosMap}).on(n.jMaskGlobals.useInput?"input.mask":"keyup.mask",u.behaviour).on("paste.mask drop.mask",function(){setTimeout(function(){t.keydown().keyup()},100)}).on("change.mask",function(){t.data("changed",!0)}).on("blur.mask",function(){e===u.val()||t.data("changed")||t.trigger("change");t.data("changed",!1)}).on("blur.mask",function(){e=u.val()}).on("focus.mask",function(t){r.selectOnFocus===!0&&n(t.target).select()}).on("focusout.mask",function(){r.clearIfNotMatch&&!o.test(u.val())&&u.val("")})},getRegexMask:function(){for(var u=[],r,e,h,s,n,o,t=0;t0?(t[i]()!==n&&t[i](n),r=t):r=t[i](),r},calculateCaretPosition:function(n){var s=u.getMasked(),i=u.getCaret(),v;if(n!==s){for(var f=t.data("mask-previus-caret-pos")||0,h=s.length,c=n.length,l=0,a=0,e=0,o=0,r=0,r=i;r=0;r--){if(!u.maskDigitPosMap[r])break;l++}for(r=i-1;r>=0;r--)u.maskDigitPosMap[r]&&e++;for(r=f-1;r>=0;r--)u.maskDigitPosMapOld[r]&&o++;i>c?i=h*10:f>=i&&f!==c?u.maskDigitPosMapOld[i]||(v=i,i-=o-e,i-=l,u.maskDigitPosMap[i]&&(i=v)):i>f&&(i+=e-o,i+=a)}return i},behaviour:function(i){var r;if(i=i||window.event,u.invalid=[],r=t.data("mask-keycode"),n.inArray(r,f.byPassKeys)===-1){var e=u.getMasked(),o=u.getCaret(),s=t.data("mask-previus-value")||"";return setTimeout(function(){u.setCaret(u.calculateCaretPosition(s))},n.jMaskGlobals.keyStrokeCompensation),u.val(e),u.setCaret(o),u.callbacks(i)}},getMasked:function(n,t){var c=[],rt=t===undefined?u.val():t+"",e=0,y=i.length,o=0,p=rt.length,s=1,w="push",l=-1,k=0,d=[],a,g,nt,tt,it;for(r.reverse?(w="unshift",s=-1,a=0,e=y-1,o=p-1,g=function(){return e>-1&&o>-1}):(a=y-1,g=function(){return e0,[f,n,t,u.invalid,r])}},f,e,o;t=n(t);f=this;e=u.val();i=typeof i=="function"?i(u.val(),undefined,t,r):i;f.mask=i;f.options=r;f.remove=function(){var n=u.getCaret();return f.options.placeholder&&t.removeAttr("placeholder"),t.data("mask-maxlength")&&t.removeAttr("maxlength"),u.destroyEvents(),u.val(f.getCleanVal()),u.setCaret(n),t};f.getCleanVal=function(){return u.getMasked(!0)};f.getMaskedVal=function(n){return u.getMasked(!1,n)};f.init=function(e){var s,h,c,l;if(e=e||!1,r=r||{},f.clearIfNotMatch=n.jMaskGlobals.clearIfNotMatch,f.byPassKeys=n.jMaskGlobals.byPassKeys,f.translation=n.extend({},n.jMaskGlobals.translation,r.translation),f=n.extend(!0,{},f,r),o=u.getRegexMask(),e)u.events(),u.val(u.getMasked());else{for(r.placeholder&&t.attr("placeholder",r.placeholder),t.data("mask")&&t.attr("autocomplete","off"),s=0,h=!0;s-1&&(n=n.replace("-",""),i="-"),n.indexOf(t.prefix)>-1&&(n=n.replace(t.prefix,"")),n.indexOf(t.suffix)>-1&&(n=n.replace(t.suffix,"")),i+t.prefix+n+t.suffix}function i(n,t){return t.allowEmpty&&""===n?"":t.reverse?o(n,t):e(n,t)}function e(n,i){var f,e,o,s=n.indexOf("-")>-1&&i.allowNegative?"-":"",r=n.replace(/[^0-9]/g,"");return f=u(r.slice(0,r.length-i.precision),s,i),i.precision>0&&(e=r.slice(r.length-i.precision),o=new Array(i.precision+1-e.length).join(0),f+=i.decimal+o+e),t(f,i)}function o(n,i){var r,c=n.indexOf("-")>-1&&i.allowNegative?"-":"",s=n.replace(i.prefix,"").replace(i.suffix,""),f=s.split(i.decimal)[0],e="",o,h;return(""===f&&(f="0"),r=u(f,c,i),i.precision>0)&&(o=s.split(i.decimal),o.length>1&&(e=o[1]),r+=i.decimal+e,h=Number.parseFloat(f+"."+e).toFixed(i.precision).toString().split(i.decimal)[1],r=r.split(i.decimal)[0]+"."+h),t(r,i)}function u(n,t,i){return n=n.replace(/^0*/g,""),""===(n=n.replace(/\B(?=(\d{3})+(?!\d))/g,i.thousands))&&(n="0"),t+n}n.browser||(n.browser={},n.browser.mozilla=/mozilla/.test(navigator.userAgent.toLowerCase())&&!/webkit/.test(navigator.userAgent.toLowerCase()),n.browser.webkit=/webkit/.test(navigator.userAgent.toLowerCase()),n.browser.opera=/opera/.test(navigator.userAgent.toLowerCase()),n.browser.msie=/msie/.test(navigator.userAgent.toLowerCase()),n.browser.device=/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));var f={prefix:"",suffix:"",affixesStay:!0,thousands:",",decimal:".",precision:2,allowZero:!1,allowNegative:!1,doubleClickSelection:!0,allowEmpty:!1,bringCaretAtEndOnFocus:!0},r={destroy:function(){return n(this).unbind(".maskMoney"),n.browser.msie&&(this.onpaste=null),this},applyMask:function(t){return i(t,n(this).data("settings"))},mask:function(t){return this.each(function(){var i=n(this);return"number"==typeof t&&i.val(t),i.trigger("mask")})},unmasked:function(){return this.map(function(){var i,t=n(this).val()||"0",r=-1!==t.indexOf("-");return n(t.split(/\D/).reverse()).each(function(n,t){if(t)return i=t,!1}),t=t.replace(/\D/g,""),t=t.replace(new RegExp(i+"$"),"."+i),r&&(t="-"+t),parseFloat(t)})},unmaskedWithOptions:function(){return this.map(function(){var t=n(this).val()||"0",i=n(this).data("settings")||f,r=new RegExp(i.thousandsForUnmasked||i.thousands,"g");return t=t.replace(r,""),parseFloat(t)})},init:function(r){return r=n.extend(n.extend({},f),r),this.each(function(){function e(){var e,o,r,f,s,n=u.get(0),i=0,t=0;return"number"==typeof n.selectionStart&&"number"==typeof n.selectionEnd?(i=n.selectionStart,t=n.selectionEnd):(o=document.selection.createRange())&&o.parentElement()===n&&(f=n.value.length,e=n.value.replace(/\r\n/g,"\n"),(r=n.createTextRange()).moveToBookmark(o.getBookmark()),(s=n.createTextRange()).collapse(!1),r.compareEndPoints("StartToEnd",s)>-1?i=t=f:(i=-r.moveStart("character",-f),i+=e.slice(0,i).split("\n").length-1,r.compareEndPoints("EndToEnd",s)>-1?t=f:(t=-r.moveEnd("character",-f),t+=e.slice(0,t).split("\n").length-1))),{start:i,end:t}}function p(){var t=!(u.val().length>=u.attr("maxlength")&&u.attr("maxlength")>=0),n=e(),i=n.start,r=n.end,f=!(n.start===n.end||!u.val().substring(i,r).match(/\d/)),o="0"===u.val().substring(0,1);return t||f||o}function w(n){f.formatOnBlur||u.each(function(t,i){if(i.setSelectionRange)i.focus(),i.setSelectionRange(n,n);else if(i.createTextRange){var r=i.createTextRange();r.collapse(!0);r.moveEnd("character",n);r.moveStart("character",n);r.select()}})}function l(n){var t,r=u.val().length;u.val(i(u.val(),f));t=u.val().length;f.reverse||(n-=r-t);w(n)}function o(){var n=u.val(),t,e,r;f.allowEmpty&&""===n||(t=n.indexOf(f.decimal),f.precision>0?t<0?n+=f.decimal+new Array(f.precision+1).join(0):(e=n.slice(0,t),r=n.slice(t+1),n=e+f.decimal+r+new Array(f.precision+1-r.length).join(0)):t>0&&(n=n.slice(0,t)),u.val(i(n,f)))}function b(){var n=u.val();return f.allowNegative?""!==n&&"-"===n.charAt(0)?n.replace("-",""):"-"+n:n}function s(n){n.preventDefault?n.preventDefault():n.returnValue=!1}function a(n){var t=(n=n||window.event).which||n.charCode||n.keyCode,i=f.decimal.charCodeAt(0);return void 0!==t&&(!(t<48||t>57)||t===i&&f.reverse?!!p()&&(t!==i||!k())&&(!!f.formatOnBlur||(s(n),v(n),!1)):nt(t,n))}function k(){return!d()&&g()}function d(){var t=u.val().length,n=e();return 0===n.start&&n.end===t}function g(){return u.val().indexOf(f.decimal)>-1}function v(n){var f,i,o,t,r=(n=n||window.event).which||n.charCode||n.keyCode,s="";r>=48&&r<=57&&(s=String.fromCharCode(r));i=(f=e()).start;o=f.end;t=u.val();u.val(t.substring(0,i)+s+t.substring(o,t.length));l(i+1)}function nt(t,i){return 45===t?(u.val(b()),!1):43===t?(u.val(u.val().replace("-","")),!1):13===t||9===t||!(!n.browser.mozilla||37!==t&&39!==t||0!==i.charCode)||(s(i),!0)}function y(){setTimeout(function(){o()},0)}function h(){return(parseFloat("0")/Math.pow(10,f.precision)).toFixed(f.precision).replace(new RegExp("\\.","g"),f.decimal)}var f,c,u=n(this);f=n.extend({},r);f=n.extend(f,u.data());u.data("settings",f);n.browser.device&&u.attr("type","tel");u.unbind(".maskMoney");u.bind("keypress.maskMoney",a);u.bind("keydown.maskMoney",function(n){var h,t,r,i,c,o=(n=n||window.event).which||n.charCode||n.keyCode;return void 0!==o&&(h=e(),t=h.start,r=h.end,8!==o&&46!==o&&63272!==o||(s(n),i=u.val(),t===r&&(8===o?""===f.suffix?t-=1:(c=i.split("").reverse().join("").search(/\d/),r=1+(t=i.length-c-1)):r+=1),u.val(i.substring(0,t)+i.substring(r,i.length)),l(t),!1))});u.bind("blur.maskMoney",function(i){if(n.browser.msie&&a(i),f.formatOnBlur&&u.val()!==c&&v(i),""===u.val()&&f.allowEmpty)u.val("");else if(""===u.val()||u.val()===t(h(),f))f.allowZero?f.affixesStay?u.val(t(h(),f)):u.val(h()):u.val("");else if(!f.affixesStay){var r=u.val().replace(f.prefix,"").replace(f.suffix,"");u.val(r)}u.val()!==c&&u.change()});u.bind("focus.maskMoney",function(){c=u.val();o();var t,n=u.get(0);f.selectAllOnFocus?n.select():n.createTextRange&&f.bringCaretAtEndOnFocus&&((t=n.createTextRange()).collapse(!1),t.select())});u.bind("click.maskMoney",function(){var n,t=u.get(0);f.selectAllOnFocus||(t.setSelectionRange&&f.bringCaretAtEndOnFocus?(n=u.val().length,t.setSelectionRange(n,n)):u.val(u.val()))});u.bind("dblclick.maskMoney",function(){var t,n,i=u.get(0);i.setSelectionRange&&f.bringCaretAtEndOnFocus?(n=u.val().length,t=f.doubleClickSelection?0:n,i.setSelectionRange(t,n)):u.val(u.val())});u.bind("cut.maskMoney",y);u.bind("paste.maskMoney",y);u.bind("mask.maskMoney",o)})}};n.fn.maskMoney=function(t){return r[t]?r[t].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof t&&t?void n.error("Method "+t+" does not exist on jQuery.maskMoney"):r.init.apply(this,arguments)}}(window.jQuery||window.Zepto)