text: ﻿!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){var c,f=navigator.userAgent,e=/iphone/i.test(f),d=/chrome/i.test(f),b=/android/i.test(f);a.mask={definitions:{"9":"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(g,h){var i;if(0!==this.length&&!this.is(":hidden")){return"number"==typeof g?(h="number"==typeof h?h:g,this.each(function(){this.setSelectionRange?this.setSelectionRange(g,h):this.createTextRange&&(i=this.createTextRange(),i.collapse(!0),i.moveEnd("character",h),i.moveStart("character",g),i.select())})):(this[0].setSelectionRange?(g=this[0].selectionStart,h=this[0].selectionEnd):document.selection&&document.selection.createRange&&(i=document.selection.createRange(),g=0-i.duplicate().moveStart("character",-100000),h=g+i.text.length),{begin:g,end:h})}},unmask:function(){return this.trigger("unmask")},mask:function(m,p){var j,g,q,o,h,k,l,n;if(!m&&this.length>0){j=a(this[0]);var i=j.data(a.mask.dataName);return i?i():void 0}return p=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},p),g=a.mask.definitions,q=[],o=l=m.length,h=null,a.each(m.split(""),function(s,r){"?"==r?(l--,o=s):g[r]?(q.push(new RegExp(g[r])),null===h&&(h=q.length-1),o>s&&(k=q.length-1)):q.push(null)}),this.trigger("unmask").each(function(){function G(){if(p.completed){for(var I=h;k>=I;I++){if(q[I]&&t[I]===y(I)){return}}p.completed.call(z)}}function y(I){return p.placeholder.charAt(I<p.placeholder.length?I:0)}function C(I){for(;++I<l&&!q[I];){}return I}function D(I){for(;--I>=0&&!q[I];){}return I}function E(I,J){var K,L;if(!(0>I)){for(K=I,L=C(J);l>K;K++){if(q[K]){if(!(l>L&&q[K].test(t[L]))){break}t[K]=t[L],t[L]=y(L),L=C(L)}}H(),z.caret(Math.max(h,I))}}function F(L){var J,I,K,M;for(J=L,I=y(L);l>J;J++){if(q[J]){if(K=C(J),M=t[J],t[J]=I,!(l>K&&q[K].test(M))){break}I=M}}}function r(){var I=z.val(),J=z.caret();if(n&&n.length&&n.length>I.length){for(u(!0);J.begin>0&&!q[J.begin-1];){J.begin--}if(0===J.begin){for(;J.begin<h&&!q[J.begin];){J.begin++}}z.caret(J.begin,J.begin)}else{for(u(!0);J.begin<l&&!q[J.begin];){J.begin++}z.caret(J.begin,J.begin)}G()}function s(){u(),z.val()!=x&&z.change()}function A(J){if(!z.prop("readonly")){var M,I,K,L=J.which||J.keyCode;n=z.val(),8===L||46===L||e&&127===L?(M=z.caret(),I=M.begin,K=M.end,K-I===0&&(I=46!==L?D(I):K=C(I-1),K=46===L?C(K):K),v(I,K),E(I,K-1),J.preventDefault()):13===L?s.call(this,J):27===L&&(z.val(x),z.caret(0,u()),J.preventDefault())}}function B(J){if(!z.prop("readonly")){var M,I,L,K=J.which||J.keyCode,N=z.caret();if(!(J.ctrlKey||J.altKey||J.metaKey||32>K)&&K&&13!==K){if(N.end-N.begin!==0&&(v(N.begin,N.end),E(N.begin,N.end-1)),M=C(N.begin-1),l>M&&(I=String.fromCharCode(K),q[M].test(I))){if(F(M),t[M]=I,H(),L=C(M),b){var O=function(){a.proxy(a.fn.caret,z,L)()};setTimeout(O,0)}else{z.caret(L)}N.begin<=k&&G()}J.preventDefault()}}}function v(K,I){var J;for(J=K;I>J&&l>J;J++){q[J]&&(t[J]=y(J))}}function H(){z.val(t.join(""))}function u(I){var K,J,M,N=z.val(),L=-1;for(K=0,M=0;l>K;K++){if(q[K]){for(t[K]=y(K);M++<N.length;){if(J=N.charAt(M-1),q[K].test(J)){t[K]=J,L=K;break}}if(M>N.length){v(K+1,l);break}}else{t[K]===N.charAt(M)&&M++,o>K&&(L=K)}}return I?H():o>L+1?p.autoclear||t.join("")===w?(z.val()&&z.val(""),v(0,l)):H():(H(),z.val(z.val().substring(0,L+1))),o?K:h}var z=a(this),t=a.map(m.split(""),function(I,J){return"?"!=I?g[I]?y(J):I:void 0}),w=t.join(""),x=z.val();z.data(a.mask.dataName,function(){return a.map(t,function(I,J){return q[J]&&I!=y(J)?I:null}).join("")}),z.one("unmask",function(){z.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!z.prop("readonly")){clearTimeout(c);var I;x=z.val(),I=u(),c=setTimeout(function(){z.get(0)===document.activeElement&&(H(),I==m.replace("?","").length?z.caret(0,I):z.caret(I))},10)}}).on("blur.mask",s).on("keydown.mask",A).on("keypress.mask",B).on("input.mask paste.mask",function(){z.prop("readonly")||setTimeout(function(){var I=u(!0);z.caret(I),G()},0)}),d&&b&&z.off("input.mask").on("input.mask",r),u()})}})});