1( function () { 2 'use strict'; 3 4 /** 5 * Restore honeypot tabindex after Popup Maker accessibility overrides it. 6 * 7 * Popup Maker stores the original tabindex in jQuery data and sets tabindex="0" 8 * on all [tabindex] elements inside popups for focus management. 9 * 10 * @param {Document|Element} context 11 */ 12 function cf7appsRestoreHoneypotTabindex( context ) { 13 var root = context && context.querySelectorAll ? context : document; 14 15 root.querySelectorAll( '[data-cf7apps-honeypot] input[type="text"]' ).forEach( function ( input ) { 16 var tabindex = input.getAttribute( 'data-cf7apps-tabindex' ); 17 18 if ( ( null === tabindex || '' === tabindex ) && typeof jQuery !== 'undefined' ) { 19 tabindex = jQuery( input ).data( 'tabindex' ); 20 } 21 22 if ( null === tabindex || '' === tabindex ) { 23 tabindex = '-1'; 24 } 25 26 input.setAttribute( 'tabindex', String( tabindex ) ); 27 } ); 28 } 29 30 function cf7appsBindPopupMakerCompatibility() { 31 if ( typeof jQuery === 'undefined' ) { 32 return; 33 } 34 35 jQuery( document ).on( 'pumInit pumAfterOpen', '.pum', function () { 36 var popup = this; 37 38 window.setTimeout( function () { 39 cf7appsRestoreHoneypotTabindex( popup ); 40 }, 0 ); 41 } ); 42 } 43 44 cf7appsBindPopupMakerCompatibility(); 45 46 /** 47 * Apply honeypot refill data to a CF7 form. 48 * 49 * @param {HTMLFormElement} form 50 * @param {Object} honeypotData Keys are CF7 field names. 51 */ 52 function applyHoneypotRefill( form, honeypotData ) { 53 if ( ! form || ! honeypotData || typeof honeypotData !== 'object' ) { 54 return; 55 } 56 57 Object.keys( honeypotData ).forEach( function ( fieldName ) { 58 const token = honeypotData[ fieldName ]; 59 60 if ( ! token || ! token.random_hash || ! token.field_name ) { 61 return; 62 } 63 64 const wrapper = 65 form.querySelector( '[data-cf7apps-honeypot="' + fieldName + '"]' ) || 66 form.querySelector( '.wpcf7-form-control-wrap.' + fieldName + '-wrap' ); 67 68 if ( ! wrapper ) { 69 return; 70 } 71 72 const hashInput = form.querySelector( 73 'input[name="' + fieldName + '-random-hash"]' 74 ); 75 76 if ( hashInput ) { 77 hashInput.value = token.random_hash; 78 } 79 80 const timeTokenInput = form.querySelector( 81 'input[name="' + fieldName + '-time-token"]' 82 ); 83 84 if ( timeTokenInput && token.time_token ) { 85 timeTokenInput.value = token.time_token; 86 } else if ( token.time_token ) { 87 const newTimeInput = document.createElement( 'input' ); 88 newTimeInput.type = 'hidden'; 89 newTimeInput.name = fieldName + '-time-token'; 90 newTimeInput.value = token.time_token; 91 92 if ( wrapper ) { 93 wrapper.appendChild( newTimeInput ); 94 } else if ( hashInput && hashInput.parentNode ) { 95 hashInput.parentNode.appendChild( newTimeInput ); 96 } 97 } 98 99 const honeypotInput = wrapper.querySelector( 100 'input.wpcf7-form-control[type="text"]' 101 ); 102 103 if ( honeypotInput ) { 104 honeypotInput.setAttribute( 'name', token.field_name ); 105 honeypotInput.value = ''; 106 cf7appsRestoreHoneypotTabindex( form ); 107 } 108 } ); 109 } 110 111 /** 112 * Sync honeypot input values before CF7 builds FormData. 113 * 114 * @param {HTMLFormElement} form 115 */ 116 function syncHoneypotInputValues( form ) { 117 if ( ! form ) { 118 return; 119 } 120 121 form.querySelectorAll( '[data-cf7apps-honeypot]' ).forEach( function ( wrapper ) { 122 const honeypotInput = wrapper.querySelector( 123 'input.wpcf7-form-control[type="text"]' 124 ); 125 126 if ( ! honeypotInput ) { 127 return; 128 } 129 130 const attributeValue = honeypotInput.getAttribute( 'value' ); 131 132 if ( attributeValue && ! honeypotInput.value ) { 133 honeypotInput.value = attributeValue; 134 } 135 } ); 136 } 137 138 /** 139 * Bind refill listeners to a single CF7 form. 140 * 141 * @param {HTMLFormElement} form 142 */ 143 function bindHoneypotRefillEvents( form ) { 144 if ( ! form || form.dataset.cf7appsHoneypotBound ) { 145 return; 146 } 147 148 if ( ! form.querySelector( '[data-cf7apps-honeypot]' ) ) { 149 return; 150 } 151 152 form.dataset.cf7appsHoneypotBound = '1'; 153 154 form.addEventListener( 'submit', function () { 155 syncHoneypotInputValues( form ); 156 }, true ); 157 158 form.addEventListener( 'wpcf7reset', function ( event ) { 159 if ( event.detail && event.detail.apiResponse && event.detail.apiResponse.honeypot ) { 160 applyHoneypotRefill( form, event.detail.apiResponse.honeypot ); 161 } 162 } ); 163 164 form.addEventListener( 'wpcf7submit', function ( event ) { 165 if ( event.detail && event.detail.status === 'spam' ) { 166 return; 167 } 168 169 if ( event.detail && event.detail.apiResponse && event.detail.apiResponse.honeypot ) { 170 applyHoneypotRefill( form, event.detail.apiResponse.honeypot ); 171 } 172 } ); 173 } 174 175 /** 176 * Initialize honeypot refill for all CF7 forms on the page. 177 */ 178 function initHoneypotRefill() { 179 if ( typeof wpcf7 === 'undefined' ) { 180 return; 181 } 182 183 if ( typeof wpcf7.submit === 'function' && ! wpcf7.__cf7appsHoneypotSubmitWrapped ) { 184 const originalSubmit = wpcf7.submit; 185 186 wpcf7.submit = function ( form, options ) { 187 if ( form instanceof HTMLFormElement ) { 188 syncHoneypotInputValues( form ); 189 } 190 191 return originalSubmit.call( this, form, options ); 192 }; 193 194 wpcf7.__cf7appsHoneypotSubmitWrapped = true; 195 } 196 197 const forms = document.querySelectorAll( '.wpcf7 > form' ); 198
199 forms.forEach( function ( form ) { 200 bindHoneypotRefillEvents( form ); 201 202 if ( ! form.querySelector( '[data-cf7apps-honeypot]' ) ) { 203 return; 204 } 205 206 const forceRefill = 207 ( typeof wpcf7 !== 'undefined' && wpcf7.cached ) || 208 ( typeof cf7appsHoneypotRefill !== 'undefined' && 209 cf7appsHoneypotRefill.forceRefillOnInit ); 210 211 if ( forceRefill && typeof wpcf7.reset === 'function' ) { 212 wpcf7.reset( form ); 213 } 214 } ); 215 } 216 217 if ( document.readyState === 'loading' ) { 218 document.addEventListener( 'DOMContentLoaded', initHoneypotRefill ); 219 } else { 220 initHoneypotRefill(); 221 } 222} )();
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.