Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

front-page-payment.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use strict';
  2. document.addEventListener('DOMContentLoaded', function (e) {
  3. // Variables
  4. const billingZipCode = document.querySelector('.billings-zip-code'),
  5. creditCardMask = document.querySelector('.billing-card-mask'),
  6. expiryDateMask = document.querySelector('.billing-expiry-date-mask'),
  7. cvvMask = document.querySelector('.billing-cvv-mask'),
  8. formCheckInputPayment = document.querySelectorAll('.form-check-input-payment');
  9. // Pincode
  10. if (billingZipCode) {
  11. billingZipCode.addEventListener('input', event => {
  12. billingZipCode.value = formatNumeral(event.target.value, {
  13. delimiter: '',
  14. numeral: true
  15. });
  16. });
  17. }
  18. if (creditCardMask) {
  19. creditCardMask.addEventListener('input', event => {
  20. creditCardMask.value = formatCreditCard(event.target.value);
  21. const cleanValue = event.target.value.replace(/\D/g, '');
  22. let cardType = getCreditCardType(cleanValue);
  23. if (cardType && cardType !== 'unknown' && cardType !== 'general') {
  24. document.querySelector('.card-type').innerHTML =
  25. `<img src="${assetsPath}img/icons/payments/${cardType}-cc.png" height="20"/>`;
  26. } else {
  27. document.querySelector('.card-type').innerHTML = '';
  28. }
  29. });
  30. registerCursorTracker({
  31. input: creditCardMask,
  32. delimiter: ' '
  33. });
  34. }
  35. // Expiry Date Mask
  36. if (expiryDateMask) {
  37. expiryDateMask.addEventListener('input', event => {
  38. expiryDateMask.value = formatDate(event.target.value, {
  39. delimiter: '/',
  40. datePattern: ['m', 'y']
  41. });
  42. });
  43. registerCursorTracker({
  44. input: expiryDateMask,
  45. delimiter: '/'
  46. });
  47. }
  48. // CVV
  49. if (cvvMask) {
  50. cvvMask.addEventListener('input', event => {
  51. const cleanValue = event.target.value.replace(/\D/g, '');
  52. cvvMask.value = formatNumeral(cleanValue, {
  53. numeral: true,
  54. numeralPositiveOnly: true
  55. });
  56. });
  57. }
  58. // Toggle CC Payment Method based on selected option
  59. if (formCheckInputPayment) {
  60. formCheckInputPayment.forEach(function (paymentInput) {
  61. paymentInput.addEventListener('change', function (e) {
  62. const paymentInputValue = e.target.value;
  63. if (paymentInputValue === 'credit-card') {
  64. document.querySelector('#form-credit-card').classList.remove('d-none');
  65. } else {
  66. document.querySelector('#form-credit-card').classList.add('d-none');
  67. }
  68. });
  69. });
  70. }
  71. });