1 line
7.6 KiB
JavaScript
1 line
7.6 KiB
JavaScript
(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v=[].slice,w=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};$=jQuery,$.payment={},$.payment.fn={},$.fn.payment=function(){var a,b;return b=arguments[0],a=2<=arguments.length?v.call(arguments,1):[],$.payment.fn[b].apply(this,a)},d=/(\d{1,4})/g,$.payment.cards=c=[{type:"visaelectron",pattern:/^4(026|17500|405|508|844|91[37])/,format:d,length:[16],cvcLength:[3],luhn:!0},{type:"maestro",pattern:/^(5(018|0[23]|[68])|6(39|7))/,format:d,length:[12,13,14,15,16,17,18,19],cvcLength:[3],luhn:!0},{type:"forbrugsforeningen",pattern:/^600/,format:d,length:[16],cvcLength:[3],luhn:!0},{type:"dankort",pattern:/^5019/,format:d,length:[16],cvcLength:[3],luhn:!0},{type:"visa",pattern:/^4/,format:d,length:[13,16],cvcLength:[3],luhn:!0},{type:"mastercard",pattern:/^5[0-5]/,format:d,length:[16],cvcLength:[3],luhn:!0},{type:"amex",pattern:/^3[47]/,format:/(\d{1,4})(\d{1,6})?(\d{1,5})?/,length:[15],cvcLength:[3,4],luhn:!0},{type:"dinersclub",pattern:/^3[0689]/,format:d,length:[14],cvcLength:[3],luhn:!0},{type:"discover",pattern:/^6([045]|22)/,format:d,length:[16],cvcLength:[3],luhn:!0},{type:"unionpay",pattern:/^(62|88)/,format:d,length:[16,17,18,19],cvcLength:[3],luhn:!1},{type:"jcb",pattern:/^35/,format:d,length:[16],cvcLength:[3],luhn:!0}],a=function(a){var b,d,e;for(a=(a+"").replace(/\D/g,""),d=0,e=c.length;e>d;d++)if(b=c[d],b.pattern.test(a))return b},b=function(a){var b,d,e;for(d=0,e=c.length;e>d;d++)if(b=c[d],b.type===a)return b},l=function(a){var b,c,d,e,f,g;for(d=!0,e=0,c=(a+"").split("").reverse(),f=0,g=c.length;g>f;f++)b=c[f],b=parseInt(b,10),(d=!d)&&(b*=2),b>9&&(b-=9),e+=b;return e%10===0},k=function(a){var b;return null!=a.prop("selectionStart")&&a.prop("selectionStart")!==a.prop("selectionEnd")?!0:null!=("undefined"!=typeof document&&null!==document&&null!=(b=document.selection)?b.createRange:void 0)&&document.selection.createRange().text?!0:!1},p=function(a){return setTimeout(function(){var b,c;return b=$(a.currentTarget),c=b.val(),c=c.replace(/\D/g,""),b.val(c)})},n=function(a){return setTimeout(function(){var b,c;return b=$(a.currentTarget),c=b.val(),c=$.payment.formatCardNumber(c),b.val(c)})},g=function(b){var c,d,e,f,g,h,i;return e=String.fromCharCode(b.which),!/^\d+$/.test(e)||(c=$(b.currentTarget),i=c.val(),d=a(i+e),f=(i.replace(/\D/g,"")+e).length,h=16,d&&(h=d.length[d.length.length-1]),f>=h||null!=c.prop("selectionStart")&&c.prop("selectionStart")!==i.length)?void 0:(g=d&&"amex"===d.type?/^(\d{4}|\d{4}\s\d{6})$/:/(?:^|\s)(\d{4})$/,g.test(i)?(b.preventDefault(),setTimeout(function(){return c.val(i+" "+e)})):g.test(i+e)?(b.preventDefault(),setTimeout(function(){return c.val(i+e+" ")})):void 0)},e=function(a){var b,c;return b=$(a.currentTarget),c=b.val(),8!==a.which||null!=b.prop("selectionStart")&&b.prop("selectionStart")!==c.length?void 0:/\d\s$/.test(c)?(a.preventDefault(),setTimeout(function(){return b.val(c.replace(/\d\s$/,""))})):/\s\d?$/.test(c)?(a.preventDefault(),setTimeout(function(){return b.val(c.replace(/\d$/,""))})):void 0},o=function(a){return setTimeout(function(){var b,c;return b=$(a.currentTarget),c=b.val(),c=$.payment.formatExpiry(c),b.val(c)})},h=function(a){var b,c,d;return c=String.fromCharCode(a.which),/^\d+$/.test(c)?(b=$(a.currentTarget),d=b.val()+c,/^\d$/.test(d)&&"0"!==d&&"1"!==d?(a.preventDefault(),setTimeout(function(){return b.val("0"+d+" / ")})):/^\d\d$/.test(d)?(a.preventDefault(),setTimeout(function(){return b.val(""+d+" / ")})):void 0):void 0},i=function(a){var b,c,d;return c=String.fromCharCode(a.which),/^\d+$/.test(c)?(b=$(a.currentTarget),d=b.val(),/^\d\d$/.test(d)?b.val(""+d+" / "):void 0):void 0},j=function(a){var b,c,d;return d=String.fromCharCode(a.which),"/"===d||" "===d?(b=$(a.currentTarget),c=b.val(),/^\d$/.test(c)&&"0"!==c?b.val("0"+c+" / "):void 0):void 0},f=function(a){var b,c;return b=$(a.currentTarget),c=b.val(),8!==a.which||null!=b.prop("selectionStart")&&b.prop("selectionStart")!==c.length?void 0:/\d\s\/\s$/.test(c)?(a.preventDefault(),setTimeout(function(){return b.val(c.replace(/\d\s\/\s$/,""))})):void 0},m=function(a){return setTimeout(function(){var b,c;return b=$(a.currentTarget),c=b.val(),c=c.replace(/\D/g,"").slice(0,4),b.val(c)})},t=function(a){var b;return a.metaKey||a.ctrlKey?!0:32===a.which?!1:0===a.which?!0:a.which<33?!0:(b=String.fromCharCode(a.which),!!/[\d\s]/.test(b))},r=function(b){var c,d,e,f;return c=$(b.currentTarget),e=String.fromCharCode(b.which),/^\d+$/.test(e)&&!k(c)?(f=(c.val()+e).replace(/\D/g,""),d=a(f),d?f.length<=d.length[d.length.length-1]:f.length<=16):void 0},s=function(a){var b,c,d;return b=$(a.currentTarget),c=String.fromCharCode(a.which),/^\d+$/.test(c)&&!k(b)?(d=b.val()+c,d=d.replace(/\D/g,""),d.length>6?!1:void 0):void 0},q=function(a){var b,c,d;return b=$(a.currentTarget),c=String.fromCharCode(a.which),/^\d+$/.test(c)&&!k(b)?(d=b.val()+c,d.length<=4):void 0},u=function(a){var b,d,e,f,g;return b=$(a.currentTarget),g=b.val(),f=$.payment.cardType(g)||"unknown",b.hasClass(f)?void 0:(d=function(){var a,b,d;for(d=[],a=0,b=c.length;b>a;a++)e=c[a],d.push(e.type);return d}(),b.removeClass("unknown"),b.removeClass(d.join(" ")),b.addClass(f),b.toggleClass("identified","unknown"!==f),b.trigger("payment.cardType",f))},$.payment.fn.formatCardCVC=function(){return this.on("keypress",t),this.on("keypress",q),this.on("paste",m),this.on("change",m),this.on("input",m),this},$.payment.fn.formatCardExpiry=function(){return this.on("keypress",t),this.on("keypress",s),this.on("keypress",h),this.on("keypress",j),this.on("keypress",i),this.on("keydown",f),this.on("change",o),this.on("input",o),this},$.payment.fn.formatCardNumber=function(){return this.on("keypress",t),this.on("keypress",r),this.on("keypress",g),this.on("keydown",e),this.on("keyup",u),this.on("paste",n),this.on("change",n),this.on("input",n),this.on("input",u),this},$.payment.fn.restrictNumeric=function(){return this.on("keypress",t),this.on("paste",p),this.on("change",p),this.on("input",p),this},$.payment.fn.cardExpiryVal=function(){return $.payment.cardExpiryVal($(this).val())},$.payment.cardExpiryVal=function(a){var b,c,d,e;return a=a.replace(/\s/g,""),e=a.split("/",2),b=e[0],d=e[1],2===(null!=d?d.length:void 0)&&/^\d+$/.test(d)&&(c=(new Date).getFullYear(),c=c.toString().slice(0,2),d=c+d),b=parseInt(b,10),d=parseInt(d,10),{month:b,year:d}},$.payment.validateCardNumber=function(b){var c,d;return b=(b+"").replace(/\s+|-/g,""),/^\d+$/.test(b)?(c=a(b),c?(d=b.length,w.call(c.length,d)>=0&&(c.luhn===!1||l(b))):!1):!1},$.payment.validateCardExpiry=function(a,b){var c,d,e;return"object"==typeof a&&"month"in a&&(e=a,a=e.month,b=e.year),a&&b?(a=$.trim(a),b=$.trim(b),/^\d+$/.test(a)&&/^\d+$/.test(b)&&a>=1&&12>=a?(2===b.length&&(b=70>b?"20"+b:"19"+b),4!==b.length?!1:(d=new Date(b,a),c=new Date,d.setMonth(d.getMonth()-1),d.setMonth(d.getMonth()+1,1),d>c)):!1):!1},$.payment.validateCardCVC=function(a,c){var d,e;return a=$.trim(a),/^\d+$/.test(a)?(d=b(c),null!=d?(e=a.length,w.call(d.cvcLength,e)>=0):a.length>=3&&a.length<=4):!1},$.payment.cardType=function(b){var c;return b?(null!=(c=a(b))?c.type:void 0)||null:null},$.payment.formatCardNumber=function(b){var c,d,e,f;return b=b.replace(/\D/g,""),(c=a(b))?(e=c.length[c.length.length-1],b=b.slice(0,e),c.format.global?null!=(f=b.match(c.format))?f.join(" "):void 0:(d=c.format.exec(b),null!=d?(d.shift(),d=$.grep(d,function(a){return a}),d.join(" ")):void 0)):b},$.payment.formatExpiry=function(a){var b,c,d,e;return(c=a.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/))?(b=c[1]||"",d=c[2]||"",e=c[3]||"",(e.length>0||d.length>0&&!/\ \/?\ ?/.test(d))&&(d=" / "),1===b.length&&"0"!==b&&"1"!==b&&(b="0"+b,d=" / "),b+d+e):""}}).call(this); |