1( function( window, document, undefined ) { 2 3 'use strict'; 4 5 /** 6 * Initialize recaptcha. 7 * 8 * @return {void} 9 */ 10 function initRecaptcha() { 11 wpcf7_recaptcha = { 12 ...( wpcf7_recaptcha ?? {} ) 13 }; 14 15 const siteKey = wpcf7_recaptcha.sitekey; 16 const { homepage, contactform } = wpcf7_recaptcha.actions; 17 18 const execute = options => { 19 const { action, func, params } = options; 20 21 grecaptcha.execute( siteKey, { 22 action, 23 } ).then( token => { 24 const event = new CustomEvent( 'wpcf7grecaptchaexecuted', { 25 detail: { 26 action, 27 token 28 } 29 } ); 30 31 document.dispatchEvent( event ); 32 } ).then( () => { 33 if ( typeof func === 'function' ) { 34 func( ...params ); 35 } 36 } ).catch( error => console.error( error ) ); 37 }; 38 39 grecaptcha.ready( () => { 40 execute( { 41 action: homepage 42 } ); 43 } ); 44 45 document.addEventListener( 'change', event => { 46 execute( { 47 action: contactform 48 } ); 49 } ); 50 51 if ( typeof wpcf7 !== 'undefined' && typeof wpcf7.submit === 'function' ) { 52 const submit = wpcf7.submit; 53 54 wpcf7.submit = ( form, options = {} ) => { 55 execute( { 56 action: contactform, 57 func: submit, 58 params: [ form, options ] 59 } ); 60 }; 61 } 62 63 document.addEventListener( 'wpcf7grecaptchaexecuted', event => { 64 const fields = document.querySelectorAll( 'form.wpcf7-form input[name="_wpcf7_recaptcha_response"]' ); 65 66 for ( let i = 0; i < fields.length; i++ ) { 67 let field = fields[ i ]; 68 69 field.setAttribute( 'value', event.detail.token ); 70 } 71 } ); 72 } 73 74 /** 75 * Handle cookies-unblocked event. 76 * 77 * @return {void} 78 */ 79 document.addEventListener( 'cookies-unblocked.hu', function( e ) { 80 e.detail.data.scripts.forEach( function( script ) { 81 // find google recaptcha in valid category 82 if ( script.id === 'google-recaptcha-js' && e.detail.categories[script.dataset.huCategory] === true ) { 83 script.onload = initRecaptcha; 84 script.onreadystatechange = initRecaptcha; 85 } 86 } ); 87 }, false ); 88 89} )( window, document );
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.