1/* 2 * Callback that is executed when Google's reCaptcha script loads 3 * 4 */ 5pms_recaptcha_callback = function() { 6 7 if( typeof window.pmsRecaptchaCallbackExecuted == "undefined" ){//see if we executed this before 8 9 if( window.pms_recaptcha && window.pms_recaptcha.pms_recaptcha_target_forms && window.pms_recaptcha.pms_recaptcha_target_forms.length > 0 ) 10 jQuery(document).off('submit', window.pms_recaptcha.pms_recaptcha_target_forms ); 11 12 jQuery( jQuery( ".pms-recaptcha" ).closest("form") ).each(function() { 13 14 this.addEventListener("submit", pms_initialize_recaptcha_v3 ); 15 16 }); 17 window.pmsRecaptchaCallbackExecuted = true; // we use this to make sure we only run the callback once 18 } 19 20}; 21 22async function pms_initialize_recaptcha_v3( event = null, current_form = null ){ 23 24 if( event ){ 25 event.preventDefault(); 26 event.stopPropagation(); 27 } 28 29 let currentForm = this 30 31 if( current_form != null && current_form && current_form[0] ){ 32 currentForm = current_form[0] 33 } 34 35 /* Call the disable_form_submit_button function before submitting the form */ 36 if (typeof disable_form_submit_button === "function") { 37 disable_form_submit_button(currentForm); 38 } 39 40 return new Promise((resolve) => { 41 grecaptcha.ready(async function() { 42 43 var recaptcha_field = jQuery('.pms-recaptcha', currentForm ) 44 45 if( !recaptcha_field[0] || !recaptcha_field[0]['dataset'] || !recaptcha_field[0]['dataset']['sitekey'] ){ 46 if( event ) 47 currentForm.submit(); 48 else 49 return true; 50 } 51 52 var sitekey = recaptcha_field[0]['dataset']['sitekey']; 53 54 let token = await grecaptcha.execute(sitekey, {action: "submit"}).then(function(token) { 55 56 let recaptchaResponse = currentForm.elements["g-recaptcha-response"]; 57 jQuery(recaptchaResponse).val(token); // Set the recaptcha response 58 59 if( token === false ){ 60 if( event ) 61 return pmsRecaptchaInitializationError(); 62 else 63 return false; 64 } 65 66 var submitForm = true 67 68 /* don't submit form if PMS gateway is Stripe */ 69 if( jQuery(".pms_pay_gate[type=radio]").length > 0 ){ 70 jQuery(".pms_pay_gate").each( function(){ 71 if( jQuery(this).is(":checked") && !jQuery(this).is(":disabled") && ( jQuery(this).val() == "stripe_connect" || jQuery(this).val() == "stripe_intents" || jQuery(this).val() == "stripe" || jQuery(this).val() == "paypal_connect" || jQuery(this).val() == "authorize_net" ) ) 72 submitForm = false 73 }) 74 } else if( jQuery(".pms_pay_gate[type=hidden]").length > 0 ) { 75 76 if( !jQuery(".pms_pay_gate[type=hidden]").is(":disabled") && ( jQuery(".pms_pay_gate[type=hidden]").val() == "stripe_connect" || jQuery(".pms_pay_gate[type=hidden]").val() == "stripe_intents" || jQuery(".pms_pay_gate[type=hidden]").val() == "stripe" || jQuery(".pms_pay_gate[type=hidden]").val() == "paypal_connect" || jQuery(".pms_pay_gate[type=hidden]").val() == "authorize_net" ) ) 77 submitForm = false 78 } 79 80 if( submitForm ){ 81 82 /* make sure the data we use to identify the default wp-login form is also submitted */ 83 if ( currentForm['wp-submit'] && currentForm['wp-submit'].value !== 0 ){ 84 var input = document.createElement("input"); 85 input.setAttribute('type', 'hidden'); 86 input.setAttribute('name', 'wp-submit'); 87 input.setAttribute('value', currentForm['wp-submit']['value'] ?? '' ); 88 89 currentForm.appendChild(input); 90 } 91 92 currentForm.submit(); 93 } else { 94 // jQuery(document).trigger( "pms_v3_recaptcha_success", jQuery( ".pms-form-submit input[type=\'submit\']", recaptchaResponse.closest("form") ) ); 95 jQuery(document).trigger( "pms_v3_recaptcha_success", currentForm.elements["pms_register"] ); 96 // return true; 97 } 98 99 resolve( token ); 100 101 }); 102 103 }); 104 }); 105 106} 107 108/* the callback function for when the captcha does not load propperly, maybe network problem or wrong keys */ 109function pmsRecaptchaInitializationError(){ 110 111 window.pmsRecaptchaInitError = true; 112 113 var nonce = jQuery( ".pms-recaptcha" )[0]['dataset']['nonce']; 114 115 //add a captcha field so we do not just let the form submit if we do not have a captcha response 116 jQuery( ".pms-recaptcha" ).after( '<input type="hidden" id="pms_recaptcha_load_error" name="pms_recaptcha_load_error" value=' + nonce + '/>' ); 117 118 /* make sure that if the invisible recaptcha did not load properly ( network error or wrong keys ) we can still submit the form */ 119 jQuery("input[type=\'submit\']", jQuery( ".pms-recaptcha" ).closest("form") ).on("click", function(e){ 120 jQuery(this).closest("form").submit(); 121 }); 122 123} 124 125jQuery( window ).on( "load", function () { 126 127 // Initialize with a delay 128 setTimeout(function() { 129 pms_recaptcha_callback(); 130 }, 500); 131 132} );
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.