2 lines
6.7 KiB
JavaScript
2 lines
6.7 KiB
JavaScript
// Generated by CoffeeScript 1.4.0
|
|
(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b=[].slice,w=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1},E=this;e=jQuery;e.payment={};e.payment.fn={};e.fn.payment=function(){var t,n;n=arguments[0],t=2<=arguments.length?b.call(arguments,1):[];return e.payment.fn[n].apply(this,t)};i=/(\d{1,4})/g;r=[{type:"maestro",pattern:/^(5018|5020|5038|6304|6759|676[1-3])/,format:i,length:[12,13,14,15,16,17,18,19],cvcLength:[3],luhn:!0},{type:"dinersclub",pattern:/^(36|38|30[0-5])/,format:i,length:[14],cvcLength:[3],luhn:!0},{type:"laser",pattern:/^(6706|6771|6709)/,format:i,length:[16,17,18,19],cvcLength:[3],luhn:!0},{type:"jcb",pattern:/^35/,format:i,length:[16],cvcLength:[3],luhn:!0},{type:"unionpay",pattern:/^62/,format:i,length:[16,17,18,19],cvcLength:[3],luhn:!1},{type:"discover",pattern:/^(6011|65|64[4-9]|622)/,format:i,length:[16],cvcLength:[3],luhn:!0},{type:"mastercard",pattern:/^5[1-5]/,format:i,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:"visa",pattern:/^4/,format:i,length:[13,14,15,16],cvcLength:[3],luhn:!0}];t=function(e){var t,n,i;e=(e+"").replace(/\D/g,"");for(n=0,i=r.length;n<i;n++){t=r[n];if(t.pattern.test(e))return t}};n=function(e){var t,n,i;for(n=0,i=r.length;n<i;n++){t=r[n];if(t.type===e)return t}};h=function(e){var t,n,r,i,s,o;r=!0;i=0;n=(e+"").split("").reverse();for(s=0,o=n.length;s<o;s++){t=n[s];t=parseInt(t,10);if(r=!r)t*=2;t>9&&(t-=9);i+=t}return i%10===0};c=function(e){var t;return e.prop("selectionStart")!=null&&e.prop("selectionStart")!==e.prop("selectionEnd")?!0:(typeof document!="undefined"&&document!==null?(t=document.selection)!=null?typeof t.createRange=="function"?t.createRange().text:void 0:void 0:void 0)?!0:!1};p=function(t){var n=this;return setTimeout(function(){var n,r;n=e(t.currentTarget);r=n.val();r=e.payment.formatCardNumber(r);return n.val(r)})};u=function(n){var r,i,s,o,u,a,f;s=String.fromCharCode(n.which);if(!/^\d+$/.test(s))return;r=e(n.currentTarget);f=r.val();i=t(f+s);o=(f.replace(/\D/g,"")+s).length;a=16;i&&(a=i.length[i.length.length-1]);if(o>=a)return;if(r.prop("selectionStart")!=null&&r.prop("selectionStart")!==f.length)return;i&&i.type==="amex"?u=/^(\d{4}|\d{4}\s\d{6})$/:u=/(?:^|\s)(\d{4})$/;if(u.test(f)){n.preventDefault();return r.val(f+" "+s)}if(u.test(f+s)){n.preventDefault();return r.val(f+s+" ")}};s=function(t){var n,r;n=e(t.currentTarget);r=n.val();if(t.meta)return;if(t.which!==8)return;if(n.prop("selectionStart")!=null&&n.prop("selectionStart")!==r.length)return;if(/\d\s$/.test(r)){t.preventDefault();return n.val(r.replace(/\d\s$/,""))}if(/\s\d?$/.test(r)){t.preventDefault();return n.val(r.replace(/\s\d?$/,""))}};a=function(t){var n,r,i;r=String.fromCharCode(t.which);if(!/^\d+$/.test(r))return;n=e(t.currentTarget);i=n.val()+r;if(/^\d$/.test(i)&&i!=="0"&&i!=="1"){t.preventDefault();return n.val("0"+i+" / ")}if(/^\d\d$/.test(i)){t.preventDefault();return n.val(""+i+" / ")}};f=function(t){var n,r,i;r=String.fromCharCode(t.which);if(!/^\d+$/.test(r))return;n=e(t.currentTarget);i=n.val();if(/^\d\d$/.test(i))return n.val(""+i+" / ")};l=function(t){var n,r,i;r=String.fromCharCode(t.which);if(r!=="/")return;n=e(t.currentTarget);i=n.val();if(/^\d$/.test(i)&&i!=="0")return n.val("0"+i+" / ")};o=function(t){var n,r;if(t.meta)return;n=e(t.currentTarget);r=n.val();if(t.which!==8)return;if(n.prop("selectionStart")!=null&&n.prop("selectionStart")!==r.length)return;if(/\d(\s|\/)+$/.test(r)){t.preventDefault();return n.val(r.replace(/\d(\s|\/)*$/,""))}if(/\s\/\s?\d?$/.test(r)){t.preventDefault();return n.val(r.replace(/\s\/\s?\d?$/,""))}};g=function(e){var t;if(e.metaKey||e.ctrlKey)return!0;if(e.which===32)return!1;if(e.which===0)return!0;if(e.which<33)return!0;t=String.fromCharCode(e.which);return!!/[\d\s]/.test(t)};v=function(n){var r,i,s,o;r=e(n.currentTarget);s=String.fromCharCode(n.which);if(!/^\d+$/.test(s))return;if(c(r))return;o=(r.val()+s).replace(/\D/g,"");i=t(o);return i?o.length<=i.length[i.length.length-1]:o.length<=16};m=function(t){var n,r,i;n=e(t.currentTarget);r=String.fromCharCode(t.which);if(!/^\d+$/.test(r))return;if(c(n))return;i=n.val()+r;i=i.replace(/\D/g,"");if(i.length>6)return!1};d=function(t){var n,r,i;n=e(t.currentTarget);r=String.fromCharCode(t.which);if(!/^\d+$/.test(r))return;i=n.val()+r;return i.length<=4};y=function(t){var n,i,s,o,u;n=e(t.currentTarget);u=n.val();o=e.payment.cardType(u)||"unknown";if(!n.hasClass(o)){i=function(){var e,t,n;n=[];for(e=0,t=r.length;e<t;e++){s=r[e];n.push(s.type)}return n}();n.removeClass("unknown");n.removeClass(i.join(" "));n.addClass(o);n.toggleClass("identified",o!=="unknown");return n.trigger("payment.cardType",o)}};e.payment.fn.formatCardCVC=function(){this.payment("restrictNumeric");this.on("keypress",d);return this};e.payment.fn.formatCardExpiry=function(){this.payment("restrictNumeric");this.on("keypress",m);this.on("keypress",a);this.on("keypress",l);this.on("keypress",f);this.on("keydown",o);return this};e.payment.fn.formatCardNumber=function(){this.payment("restrictNumeric");this.on("keypress",v);this.on("keypress",u);this.on("keydown",s);this.on("keyup",y);this.on("paste",p);return this};e.payment.fn.restrictNumeric=function(){this.on("keypress",g);return this};e.payment.fn.cardExpiryVal=function(){return e.payment.cardExpiryVal(e(this).val())};e.payment.cardExpiryVal=function(e){var t,n,r,i;e=e.replace(/\s/g,"");i=e.split("/",2),t=i[0],r=i[1];if((r!=null?r.length:void 0)===2&&/^\d+$/.test(r)){n=(new Date).getFullYear();n=n.toString().slice(0,2);r=n+r}t=parseInt(t,10);r=parseInt(r,10);return{month:t,year:r}};e.payment.validateCardNumber=function(e){var n,r;e=(e+"").replace(/\s+|-/g,"");if(!/^\d+$/.test(e))return!1;n=t(e);return n?(r=e.length,w.call(n.length,r)>=0)&&(n.luhn===!1||h(e)):!1};e.payment.validateCardExpiry=function(t,n){var r,i,s,o;typeof t=="object"&&"month"in t&&(o=t,t=o.month,n=o.year);if(!t||!n)return!1;t=e.trim(t);n=e.trim(n);if(!/^\d+$/.test(t))return!1;if(!/^\d+$/.test(n))return!1;if(parseInt(t,10)<=12){if(n.length===2){s=(new Date).getFullYear();s=s.toString().slice(0,2);n=s+n}i=new Date(n,t);r=new Date;i.setMonth(i.getMonth()-1);i.setMonth(i.getMonth()+1,1);return i>r}return!1};e.payment.validateCardCVC=function(t,r){var i,s;t=e.trim(t);return/^\d+$/.test(t)?r?(i=t.length,w.call((s=n(r))!=null?s.cvcLength:void 0,i)>=0):t.length>=3&&t.length<=4:!1};e.payment.cardType=function(e){var n;return e?((n=t(e))!=null?n.type:void 0)||null:null};e.payment.formatCardNumber=function(e){var n,r,i,s;n=t(e);if(!n)return e;i=n.length[n.length.length-1];e=e.replace(/\D/g,"");e=e.slice(0,+i+1||9e9);if(n.format.global)return(s=e.match(n.format))!=null?s.join(" "):void 0;r=n.format.exec(e);r!=null&&r.shift();return r!=null?r.join(" "):void 0}}).call(this); |