1import { show, hide, find } from 'helpers/dom-utils'; 2 3/* eslint-disable no-console, no-undef */ 4const toggleGiftOptions = function () { 5 $('.checkout-buttons').slideToggle(); 6 $('#giftform').slideToggle(); 7 $('#promoform').slideToggle(); 8 $('#autorenewform').slideToggle(); 9 $('#giftdescription').slideToggle(); 10 $('.renewal-confirmation').slideToggle(); 11}; 12 13const setupAutoRenew = () => $('#autorenew').change(function () { 14 const checked = $('#autorenew').is(':checked'); 15 16 if (checked) { 17 hide('#gift-section'); 18 hide('.renewal-confirmation'); 19 hide('.sub-no-renew'); 20 show('.sub-renew'); 21 } else { 22 show('#gift-section'); 23 show('.renewal-confirmation'); 24 show('.sub-no-renew'); 25 hide('.sub-renew'); 26 } 27}); 28 29const setupStripeSession = () => $('#stripe-session-checkout').click(function (e) { 30 e.preventDefault(); 31 32 const $button = $(this); 33 34 const checkoutToken = $button.data('checkoutToken'); 35 36 const csrfToken = document.querySelector("[name='csrf-token']").content; 37 38 return $.ajax({ 39 url: '/basket/stripesession', 40 method: 'POST', 41 headers: { 42 'X-CSRF-Token': csrfToken, 43 'Content-Type': 'application/json', 44 }, 45 data: JSON.stringify({ 46 ct: checkoutToken, 47 ar: $('#autorenew').is(':checked') ? '1' : '0', 48 }), 49 }).done(function (response) { 50 window.location.href = response.url; 51 }).fail((error) => { 52 try { 53 const responseText = JSON.parse(error.responseText); 54 55 if (responseText.error === 'CURRENCY_MISMATCH') { 56 const stripeDiv = find('#stripe-message'); 57 const stripeButton = find('#stripe-session-checkout'); 58 const text = document.createTextNode('Your account can be used with only one currency - please switch to your original currency using the flag icons at the top of the page and try again.'); 59 stripeDiv.appendChild(text); 60 stripeDiv.classList.add('text-danger'); 61 stripeButton.classList.add('mt-2'); 62 stripeButton.classList.add('disabled'); 63 } 64 } catch (error_) { 65 console.error(error_); 66 } 67 68 console.error('Error:', error); 69 }); 70}); 71 72export default function () { 73 // The autorenewal switch requires JS. Don't show it unless JS is enabled. 74 if (find('#autorenewform')) { 75 show('#autorenewform'); 76 77 setupAutoRenew(); 78 } 79 80 if (find('.gift-errors')) { 81 toggleGiftOptions(); 82 } 83 84 if (find('#show-gift-form')) { 85 toggleGiftOptions(); 86 } 87 88 $('.show-gift-options').click(function () { 89 toggleGiftOptions(); 90 return false; 91 }); 92 93 $('#gift-cancel').click(function () { 94 toggleGiftOptions(); 95 return false; 96 }); 97 98 if (find('#stripe-session-checkout')) { 99 return setupStripeSession(); 100 } 101 102 $('.add-to-basket').click(function () { 103 gtag('event', 'add_to_cart', { 104 105 'send_to': 'G-R6F16S00XT', 106 }); 107 }); 108} 109/* eslint-enable no-console, no-undef */
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.