woocommerce/assets/js/jquery-payment/jquery.payment.min.js

1 line
8.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

jQuery(function(k){(function(){var l,r,u,t,e,n,a,i,o,s,c,h,p,f,g,v,d,m,y,C,T,w,$,S=[].slice,D=[].indexOf||function(t){for(var e=0,n=this.length;e<n;e++)if(e in this&&this[e]===t)return e;return-1};(k=window.jQuery||window.Zepto||window.$).payment={},k.payment.fn={},k.fn.payment=function(){var t=arguments[0],e=2<=arguments.length?S.call(arguments,1):[];return k.payment.fn[t].apply(this,e)},t=/(\d{1,4})/g,k.payment.cards=u=[{type:"maestro",patterns:[5018,502,503,506,56,58,639,6220,67],format:t,length:[12,13,14,15,16,17,18,19],cvcLength:[3],luhn:!0},{type:"forbrugsforeningen",patterns:[600],format:t,length:[16],cvcLength:[3],luhn:!0},{type:"dankort",patterns:[5019],format:t,length:[16],cvcLength:[3],luhn:!0},{type:"visa",patterns:[4],format:t,length:[13,16],cvcLength:[3],luhn:!0},{type:"mastercard",patterns:[51,52,53,54,55,22,23,24,25,26,27],format:t,length:[16],cvcLength:[3],luhn:!0},{type:"amex",patterns:[34,37],format:/(\d{1,4})(\d{1,6})?(\d{1,5})?/,length:[15],cvcLength:[3,4],luhn:!0},{type:"dinersclub",patterns:[30,36,38,39],format:/(\d{1,4})(\d{1,6})?(\d{1,4})?/,length:[14],cvcLength:[3],luhn:!0},{type:"discover",patterns:[60,64,65,622],format:t,length:[16],cvcLength:[3],luhn:!0},{type:"unionpay",patterns:[62,88],format:t,length:[16,17,18,19],cvcLength:[3],luhn:!1},{type:"jcb",patterns:[35],format:t,length:[16],cvcLength:[3],luhn:!0}],l=function(t){var e,n,r,a,i,o,l;for(t=(t+"").replace(/\D/g,""),r=0,i=u.length;r<i;r++)for(a=0,o=(l=(e=u[r]).patterns).length;a<o;a++)if(n=l[a]+"",t.substr(0,n.length)===n)return e},r=function(t){for(var e,n=0,r=u.length;n<r;n++)if((e=u[n]).type===t)return e},h=function(t){for(var e,n=!0,r=0,a=(t+"").split("").reverse(),i=0,o=a.length;i<o;i++)e=a[i],e=parseInt(e,10),(n=!n)&&(e*=2),9<e&&(e-=9),r+=e;return r%10==0},c=function(t){var e;return null!=t.prop("selectionStart")&&t.prop("selectionStart")!==t.prop("selectionEnd")||!(null==("undefined"!=typeof document&&null!==document&&null!=(e=document.selection)?e.createRange:void 0)||!document.selection.createRange().text)},w=function(t,e){var n,r,a;try{n=e.prop("selectionStart")}catch(i){n=null}if(r=e.val(),e.val(t),null!==n&&e.is(":focus"))return n===r.length&&(n=t.length),r!==t&&(a=r.slice(n-1,+n+1||9e9),r=t.slice(n-1,+n+1||9e9),t=t[n],/\d/.test(t)&&a===t+" "&&r===" "+t&&(n+=1)),e.prop("selectionStart",n),e.prop("selectionEnd",n)},d=function(t){var e,n,r,a,i,o;for(null==t&&(t=""),a="",i=0,o=(e=t.split("")).length;i<o;i++)n=e[i],-1<(r="".indexOf(n))&&(n="0123456789"[r]),a+=n;return a},v=function(t){var e=k(t.currentTarget);return setTimeout(function(){var t=e.val();return t=(t=d(t)).replace(/\D/g,""),w(t,e)})},f=function(t){var e=k(t.currentTarget);return setTimeout(function(){var t=e.val();return t=d(t),t=k.payment.formatCardNumber(t),w(t,e)})},a=function(t){var e,n,r,a,i,o=String.fromCharCode(t.which);if(/^\d+$/.test(o)&&(e=k(t.currentTarget),i=e.val(),r=l(i+o),n=(i.replace(/\D/g,"")+o).length,a=16,r&&(a=r.length[r.length.length-1]),!(a<=n||null!=e.prop("selectionStart")&&e.prop("selectionStart")!==i.length)))return(r=r&&"amex"===r.type?/^(\d{4}|\d{4}\s\d{6})$/:/(?:^|\s)(\d{4})$/).test(i)?(t.preventDefault(),setTimeout(function(){return e.val(i+" "+o)})):r.test(i+o)?(t.preventDefault(),setTimeout(function(){return e.val(i+o+" ")})):void 0},e=function(t){var e=k(t.currentTarget),n=e.val();if(8===t.which&&(null==e.prop("selectionStart")||e.prop("selectionStart")===n.length))return/\d\s$/.test(n)?(t.preventDefault(),setTimeout(function(){return e.val(n.replace(/\d\s$/,""))})):/\s\d?$/.test(n)?(t.preventDefault(),setTimeout(function(){return e.val(n.replace(/\d$/,""))})):void 0},g=function(t){var e=k(t.currentTarget);return setTimeout(function(){var t=e.val();return t=d(t),t=k.payment.formatExpiry(t),w(t,e)})},i=function(t){var n,r,e=String.fromCharCode(t.which);if(/^\d+$/.test(e))return n=k(t.currentTarget),r=n.val()+e,/^\d$/.test(r)&&"0"!==r&&"1"!==r?(t.preventDefault(),setTimeout(function(){return n.val("0"+r+" / ")})):/^\d\d$/.test(r)?(t.preventDefault(),setTimeout(function(){var t=parseInt(r[0],10),e=parseInt(r[1],10);return 2<e&&0!==t?n.val("0"+t+" / "+e):n.val(r+" / ")})):void 0},o=function(t){var e=String.fromCharCode(t.which);if(/^\d+$/.test(e))return t=(e=k(t.currentTarget)).val(),/^\d\d$/.test(t)?e.val(t+" / "):void 0},s=function(t){var e=String.fromCharCode(t.which);if("/"===e||" "===e)return t=(e=k(t.currentTarget)).val(),/^\d$/.test(t)&&"0"!==t?e.val("0"+t+" / "):void 0},n=function(t){var e=k(t.currentTarget),n=e.val();if(8===t.which&&(null==e.prop("selectionStart")||e.prop("selectionStart")===n.length))return/\d\s\/\s$/.test(n)?(t.preventDefault(),setTimeout(function(){return e.val(n.replace(/\d\s\/\s$/,""))})):void 0},p=function(t){var e=k(t.currentTarget);return setTimeout(function(){var t=e.val();return t=(t=d(t)).replace(/\D/g,"").slice(0,4),w(t,e)})},T=function(t){return!(!t.metaKey&&!t.ctrlKey)||32!==t.which&&(0===t.which||(t.which<33||(t=String.fromCharCode(t.which),!!/[\d\s]/.test(t))))},y=function(t){var e=k(t.currentTarget),t=String.fromCharCode(t.which);if(/^\d+$/.test(t)&&!c(e))return e=(e.val()+t).replace(/\D/g,""),(t=l(e))?e.length<=t.length[t.length.length-1]:e.length<=16},C=function(t){var e=k(t.currentTarget),t=String.fromCharCode(t.which);if(/^\d+$/.test(t)&&!c(e))return!(6<(e.val()+t).replace(/\D/g,"").length)&&void 0},m=function(t){var e=k(t.currentTarget),t=String.fromCharCode(t.which);if(/^\d+$/.test(t)&&!c(e))return(e.val()+t).length<=4},$=function(t){var r,e=k(t.currentTarget),n=e.val(),t=k.payment.cardType(n)||"unknown";if(!e.hasClass(t))return n=function(){for(var t=[],e=0,n=u.length;e<n;e++)r=u[e],t.push(r.type);return t}(),e.removeClass("unknown"),e.removeClass(n.join(" ")),e.addClass(t),e.toggleClass("identified","unknown"!==t),e.trigger("payment.cardType",t)},k.payment.fn.formatCardCVC=function(){return this.on("keypress",T),this.on("keypress",m),this.on("paste",p),this.on("change",p),this.on("input",p),this},k.payment.fn.formatCardExpiry=function(){return this.on("keypress",T),this.on("keypress",C),this.on("keypress",i),this.on("keypress",s),this.on("keypress",o),this.on("keydown",n),this.on("change",g),this.on("input",g),this},k.payment.fn.formatCardNumber=function(){return this.on("keypress",T),this.on("keypress",y),this.on("keypress",a),this.on("keydown",e),this.on("keyup",$),this.on("paste",f),this.on("change",f),this.on("input",f),this.on("input",$),this},k.payment.fn.restrictNumeric=function(){return this.on("keypress",T),this.on("paste",v),this.on("change",v),this.on("input",v),this},k.payment.fn.cardExpiryVal=function(){return k.payment.cardExpiryVal(k(this).val())},k.payment.cardExpiryVal=function(t){var e=t.split(/[\s\/]+/,2),t=e[0],e=e[1];return 2===(null!=e?e.length:void 0)&&/^\d+$/.test(e)&&(e=(new Date).getFullYear().toString().slice(0,2)+e),{month:t=parseInt(t,10),year:e=parseInt(e,10)}},k.payment.validateCardNumber=function(t){var e,n;return t=(t+"").replace(/\s+|-/g,""),!!/^\d+$/.test(t)&&(!!(e=l(t))&&(n=t.length,0<=D.call(e.length,n)&&(!1===e.luhn||h(t))))},k.payment.validateCardExpiry=function(t,e){var n;return"object"==typeof t&&"month"in t&&(t=(n=t).month,e=n.year),!(!t||!e)&&(t=t||0==t?t.toString().trim():"",e=e||0==e?e.toString().trim():"",!!/^\d+$/.test(t)&&(!!/^\d+$/.test(e)&&(1<=t&&t<=12&&(2===e.length&&(e=e<70?"20"+e:"19"+e),4===e.length&&(e=new Date(e,t),t=new Date,e.setMonth(e.getMonth()-1),e.setMonth(e.getMonth()+1,1),t<e)))))},k.payment.validateCardCVC=function(t,e){var n;return t=t||0==t?t.toString().trim():"",!!/^\d+$/.test(t)&&(null!=(n=r(e))?(e=t.length,0<=D.call(n.cvcLength,e)):3<=t.length&&t.length<=4)},k.payment.cardType=function(t){return t&&(null!=(t=l(t))?t.type:void 0)||null},k.payment.formatCardNumber=function(t){var e,n;return t=t.replace(/\D/g,""),(e=l(t))?(n=e.length[e.length.length-1],t=t.slice(0,n),e.format.global?null!=(n=t.match(e.format))?n.join(" "):void 0:null!=(e=e.format.exec(t))?(e.shift(),(e=k.grep(e,function(t){return t})).join(" ")):void 0):t},k.payment.formatExpiry=function(t){var e,n=t.match(/^\D*(\d{1,2})(\D+)?(\d{1,4})?/);return n?(e=n[1]||"",t=n[2]||"",0<(n=n[3]||"").length?t=" / ":" /"===t?(e=e.substring(0,1),t=""):2===e.length||0<t.length?t=" / ":1===e.length&&"0"!==e&&"1"!==e&&(e="0"+e,t=" / "),e+t+n):""}}).call(this)});