1/** 2 * Frontend button handler 3 * 4 * Converted from jQuery to vanilla JS so the file does not depend on 5 * jQuery 6 * 7 */ 8(function () { 9 'use strict'; 10 11 function init() { 12 // Delegated click handler, equivalent to: 13 // jQuery(document).on('click', '.wpedon-stripe-button', ...) 14 document.addEventListener('click', function (e) { 15 var button = e.target.closest ? e.target.closest('.wpedon-stripe-button') : null; 16 if (!button) return; 17 18 // Equivalent of jQuery handler returning false: 19 // prevent default action and stop propagation. 20 e.preventDefault(); 21 e.stopPropagation(); 22 23 var form = button.closest('form'); 24 var message = form ? form.querySelector('.wpedon-stripe-message') : null; 25 26 if (button.classList.contains('processing')) return false; 27 button.classList.add('processing'); 28 29 if (message) message.innerHTML = ''; 30 31 function setMessage(html) { 32 if (message) message.innerHTML = html; 33 } 34 35 function failHandler() { 36 setMessage('<span class="stripe-error">An unexpected error occurred. Please try again.</span>'); 37 button.classList.remove('processing'); 38 } 39 40 // Mirror $form.serialize(): URL-encoded form payload of successful controls. 41 var formSerialized = form 42 ? new URLSearchParams(new FormData(form)).toString() 43 : ''; 44 45 // Mirror $.post payload: application/x-www-form-urlencoded body. 46 var body = new URLSearchParams({ 47 action: 'wpedon_stripe_checkout_session', 48 nonce: wpedon.nonce, 49 data: formSerialized, 50 location: window.location.href 51 }); 52 53 fetch(wpedon.ajaxUrl, { 54 method: 'POST', 55 credentials: 'same-origin', 56 headers: { 57 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 58 'Accept': 'application/json, text/javascript, */*; q=0.01', 59 'X-Requested-With': 'XMLHttpRequest' 60 }, 61 body: body.toString() 62 }).then(function (resp) { 63 // jQuery's .fail() fires on non-2xx, so emulate that here. 64 if (!resp.ok) { 65 throw new Error('HTTP ' + resp.status); 66 } 67 return resp.json(); 68 }).then(function (response) { 69 if (response.success) { 70 if (wpedon.opens == '1') { 71 try { 72 var stripe = Stripe(response.data.stripeKey, { 73 stripeAccount: response.data.accountId 74 }); 75 stripe.redirectToCheckout({ 76 sessionId: response.data.sessionId 77 }); 78 } catch (error) { 79 setMessage('<span class="stripe-error">' + error + '</span>'); 80 button.classList.remove('processing'); 81 } 82 } else { 83 button.classList.remove('processing'); 84 85 var siteUrl = location.protocol + '//' + location.host + location.pathname; 86 87 var params = new URLSearchParams(location.search); 88 params.delete('wpedon_stripe_success'); 89 params = params.toString(); 90 91 var url = siteUrl + '?' + new URLSearchParams({ 92 'wpedon-stripe-checkout-redirect': 1, 93 'sk': response.data.stripeKey, 94 'ai': response.data.accountId, 95 'si': response.data.sessionId, 96 'rf': siteUrl + (params.length ? '?' + params : '') 97 }); 98 window.open(url, '_blank').focus(); 99 } 100 } else { 101 setMessage('<span class="stripe-error">' + response.data.message + '</span>'); 102 button.classList.remove('processing'); 103 } 104 }).catch(failHandler); 105 106 return false;
107 }); 108 } 109 110 if (document.readyState === 'loading') { 111 document.addEventListener('DOMContentLoaded', init); 112 } else { 113 init(); 114 } 115})();
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.