1UAGBForms = { 2 getElement: ( id ) => { 3 // Check if the script has run once already on the given element (required for homepage sidebar usage case). 4 const getJsELement = document.querySelector( `${ id }:not(.uagb-activated-script)` ); 5 if ( ! getJsELement ) return null; 6 7 // Ensures that the script only runs once on the given element (required for homepage sidebar usage case). 8 getJsELement.classList.add( 'uagb-activated-script' ); 9 return getJsELement; 10 }, 11 12 init( attr, id, post_id ) { 13 const scope = UAGBForms.getElement( id ); 14 if ( ! scope ) { 15 return; 16 } 17 18 const form = scope.querySelector( '.uagb-forms-main-form' ); 19 20 const phoneinput = form.querySelectorAll( '.uagb-forms-phone-input' ); 21 22 if ( phoneinput.length !== 0 ) { 23 for ( let i = 0; i < phoneinput.length; i++ ) { 24 phoneinput[ i ].addEventListener( 'keypress', function ( e ) { 25 const charCode = e.which ? e.which : e.keyCode; 26 if ( charCode === 45 ) { 27 return true; 28 } 29 if ( charCode > 31 && ( charCode < 48 || charCode > 57 ) ) { 30 return false; 31 } 32 return true; 33 } ); 34 } 35 } 36 const toggleinput = form.querySelectorAll( '.uagb-forms-toggle-input' ); 37 38 if ( toggleinput.length !== 0 ) { 39 for ( let j = 0; j < toggleinput.length; j++ ) { 40 toggleinput[ j ].addEventListener( 'change', function () { 41 if ( toggleinput[ j ].checked ) { 42 const truestate = toggleinput[ j ].getAttribute( 'data-truestate' ); 43 toggleinput[ j ].setAttribute( 'value', truestate ); 44 } else { 45 const falsestate = toggleinput[ j ].getAttribute( 'data-falsestate' ); 46 toggleinput[ j ].setAttribute( 'value', falsestate ); 47 } 48 } ); 49 } 50 } 51 52 // validation for checkbox if required. 53 const requiredCheckboxes = scope.querySelectorAll( '.uagb-forms-checkbox-wrap' ); 54 if ( requiredCheckboxes.length !== 0 ) { 55 for ( let k = 0; k < requiredCheckboxes.length; k++ ) { 56 const checkboxes = requiredCheckboxes[ k ].querySelectorAll( 'input[type=checkbox]' ); 57 58 if ( checkboxes.length > 0 ) { 59 for ( let l = 0; l < checkboxes.length; l++ ) { 60 checkboxes[ l ].addEventListener( 'change', function () { 61 const isChecked = checkboxes[ l ].checked; 62 const name = checkboxes[ l ].getAttribute( 'name' ); 63 64 const check = document.querySelectorAll( '[name="' + name + '"]' ); 65 for ( let i = 0; i < check.length; i++ ) { 66 if ( isChecked ) { 67 check[ i ].required = false; 68 } else { 69 check[ i ].required = true; 70 } 71 } 72 } ); 73 } 74 } 75 } 76 } 77 78 let reCaptchaSiteKeyV2 = '', 79 reCaptchaSiteKeyV3 = ''; 80 81 //append recaptcha js when enabled. 82 if ( attr.reCaptchaEnable === true && attr.reCaptchaType === 'v2' ) { 83 reCaptchaSiteKeyV2 = uagb_forms_data.recaptcha_site_key_v2; 84 85 if ( reCaptchaSiteKeyV2 ) { 86 if ( null === document.querySelector( '.uagb-forms-field-set' ).getAttribute( 'data-sitekey' ) ) { 87 document.querySelector( '.g-recaptcha ' ).setAttribute( 'data-sitekey', reCaptchaSiteKeyV2 ); 88 } 89 90 const recaptchaLink = document.createElement( 'script' ); 91 recaptchaLink.type = 'text/javascript'; 92 recaptchaLink.src = 'https://www.google.com/recaptcha/api.js'; 93 document.head.appendChild( recaptchaLink ); 94 } 95 } else if ( attr.reCaptchaEnable === true && attr.reCaptchaType === 'v3' ) { 96 reCaptchaSiteKeyV3 = uagb_forms_data.recaptcha_site_key_v3; 97 98 if ( reCaptchaSiteKeyV3 ) { 99 if ( attr.hidereCaptchaBatch ) { 100 setTimeout( function(){ 101 const badge = document.getElementsByClassName( 'grecaptcha-badge' )[0]; 102 if( badge ){ 103 badge.style.visibility = 'hidden'; 104 } 105 }, 500 ); 106 } 107 const api = document.createElement( 'script' ); 108 api.type = 'text/javascript'; 109 api.src = 'https://www.google.com/recaptcha/api.js?render=' + reCaptchaSiteKeyV3; 110 document.head.appendChild( api ); 111 } 112 } 113 114 //Ready Classes. 115 const formscope = document.getElementsByClassName( 'uagb-block-' + attr.block_id ); 116 if ( formscope?.[ 0 ] ) { 117 const formWrapper = formscope[ 0 ].children; 118 const sibling = formWrapper[ 0 ].children; 119 120 for ( let index = 0; index < sibling.length; index++ ) { 121 if ( 122 sibling[ index ].classList.contains( 'uag-col-2' ) && 123 sibling[ index + 1 ].classList.contains( 'uag-col-2' ) 124 ) { 125 const div = document.createElement( 'div' ); 126 div.className = 'uag-col-2-wrap uag-col-wrap-' + index; 127 sibling[ index + 1 ].after( div ); 128 const wrapper_div = formscope[ 0 ].getElementsByClassName( 'uag-col-wrap-' + index ); 129 wrapper_div[ 0 ].appendChild( sibling[ index ] ); 130 wrapper_div[ 0 ].appendChild( sibling[ index ] ); 131 } 132 133 if ( 134 sibling[ index ].classList.contains( 'uag-col-3' ) && 135 sibling[ index + 1 ].classList.contains( 'uag-col-3' ) && 136 sibling[ index + 2 ].classList.contains( 'uag-col-3' ) 137 ) { 138 const div = document.createElement( 'div' ); 139 div.className = 'uag-col-3-wrap uag-col-wrap-' + index; 140 sibling[ index + 2 ].after( div ); 141 const wrapper_div = formscope[ 0 ].getElementsByClassName( 'uag-col-wrap-' + index ); 142 wrapper_div[ 0 ].appendChild( sibling[ index ] ); 143 wrapper_div[ 0 ].appendChild( sibling[ index ] ); 144 wrapper_div[ 0 ].appendChild( sibling[ index ] ); 145 } 146 147 if ( 148 sibling[ index ].classList.contains( 'uag-col-4' ) && 149 sibling[ index + 1 ].classList.contains( 'uag-col-4' ) && 150 sibling[ index + 2 ].classList.contains( 'uag-col-4' ) && 151 sibling[ index + 3 ].classList.contains( 'uag-col-4' ) 152 ) { 153 const div = document.createElement( 'div' ); 154 div.className = 'uag-col-4-wrap uag-col-wrap-' + index; 155 sibling[ index + 3 ].after( div ); 156 const wrapper_div = formscope[ 0 ].getElementsByClassName( 'uag-col-wrap-' + index ); 157 wrapper_div[ 0 ].appendChild( sibling[ index ] ); 158 wrapper_div[ 0 ].appendChild( sibling[ index ] ); 159 wrapper_div[ 0 ].appendChild( sibling[ index ] ); 160 wrapper_div[ 0 ].appendChild( sibling[ index ] ); 161 } 162 } 163 } 164 165 form.addEventListener( 'submit', function ( e ) { 166 e.preventDefault(); 167 if ( attr.reCaptchaEnable === true && attr.reCaptchaType === 'v3' && reCaptchaSiteKeyV3 ) { 168 if ( document.getElementsByClassName( 'grecaptcha-logo' ).length === 0 ) { 169 document.querySelector( '.uagb-form-reacaptcha-error-' + attr.block_id ).innerHTML = 170 '<p style="color:red !important" class="error-captcha">Invalid Google reCAPTCHA Site Key.</p>'; 171 return false;
172 } 173 174 // eslint-disable-next-line no-undef 175 grecaptcha.ready( function () { 176 // eslint-disable-next-line no-undef 177 grecaptcha.execute( reCaptchaSiteKeyV3, { action: 'submit' } ).then( function ( token ) { 178 if ( token ) { 179 if ( document.getElementsByClassName( 'uagb-forms-recaptcha' ).length !== 0 ) { 180 document.getElementById( 'g-recaptcha-response' ).value = token; 181 182 window.UAGBForms._formSubmit( 183 e, 184 form, 185 attr, 186 reCaptchaSiteKeyV2, 187 reCaptchaSiteKeyV3, 188 post_id 189 ); 190 } else { 191 document.querySelector( '.uagb-form-reacaptcha-error-' + attr.block_id ).innerHTML = 192 '<p style="color:red !important" class="error-captcha">Google reCAPTCHA Response not found.</p>'; 193 return false; 194 } 195 } 196 } ); 197 } ); 198 } else { 199 window.UAGBForms._formSubmit( e, this, attr, reCaptchaSiteKeyV2, reCaptchaSiteKeyV3, post_id ); 200 } 201 } ); 202 }, 203 204 _formSubmit( e, form, attr, reCaptchaSiteKeyV2, reCaptchaSiteKeyV3, post_id ) { 205 e.preventDefault(); 206 207 let captcha_response; 208 209 if ( '' === attr.afterSubmitToEmail || null === attr.afterSubmitToEmail ) { 210 const hideForm = document.querySelector( '[name="uagb-form-' + attr.block_id + '"]' ); 211 hideForm.style.display = 'none'; 212 213 const errorMsg = document.querySelector( '.uagb-forms-failed-message-' + attr.block_id ); 214 errorMsg?.classList?.remove( 'uagb-forms-submit-message-hide' ); 215 errorMsg?.classList?.add( 'uagb-forms-failed-message' ); 216 return false; 217 } 218 219 if ( attr.reCaptchaEnable === true ) { 220 if ( attr.reCaptchaType === 'v2' && reCaptchaSiteKeyV2 ) { 221 if ( document.getElementsByClassName( 'uagb-forms-recaptcha' ).length !== 0 ) { 222 captcha_response = document.getElementById( 'g-recaptcha-response' ).value; 223 224 if ( ! captcha_response ) { 225 document.querySelector( '.uagb-form-reacaptcha-error-' + attr.block_id ).innerHTML = 226 '<p style="color:red !important" class="error-captcha">' + attr.captchaMessage + '</p>'; 227 return false; 228 } 229 document.querySelector( '.uagb-form-reacaptcha-error-' + attr.block_id ).innerHTML = ''; 230 } else { 231 document.querySelector( '.uagb-form-reacaptcha-error-' + attr.block_id ).innerHTML = 232 '<p style="color:red !important" class="error-captcha"> Google reCAPTCHA Response not found.</p>'; 233 return false; 234 } 235 } else if ( attr.reCaptchaType === 'v3' && reCaptchaSiteKeyV3 ) { 236 captcha_response = document.getElementById( 'g-recaptcha-response' ).value; 237 } 238 } 239 240 const originalSerialized = window.UAGBForms._serializeIt( form ); 241 242 const postData = {}; 243 postData.id = attr.block_id; 244 for ( let i = 0; i < originalSerialized.length; i++ ) { 245 const inputname = document.getElementById( originalSerialized[ i ].name ); 246 247 if ( originalSerialized[ i ].name.endsWith( '[]' ) ) { 248 const name = originalSerialized[ i ].name.replace( /[\[\]']+/g, '' ); 249 //For checkbox element 250 if ( ! ( name in postData ) ) { 251 postData[ name ] = []; 252 } 253 postData[ name ].push( originalSerialized[ i ].value ); 254 } else if ( inputname !== null ) { 255 postData[ inputname.innerHTML ] = originalSerialized[ i ].value; 256 } 257 258 const hiddenField = document.getElementById( 'hidden' ); 259 260 if ( hiddenField !== null && hiddenField !== undefined ) { 261 postData[ hiddenField.getAttribute( 'name' ) ] = hiddenField.getAttribute( 'value' ); 262 } 263 } 264 265 // eslint-disable-next-line no-undef 266 fetch( uagb_forms_data.ajax_url, { 267 method: 'POST', 268 headers: new Headers( { 'Content-Type': 'application/x-www-form-urlencoded' } ), // eslint-disable-line no-undef 269 body: new URLSearchParams( { 270 action: 'uagb_process_forms', 271 nonce: uagb_forms_data.uagb_forms_ajax_nonce, 272 form_data: JSON.stringify( postData ), 273 sendAfterSubmitEmail: attr.sendAfterSubmitEmail, 274 captcha_version: attr.reCaptchaType, 275 captcha_response, 276 post_id, 277 block_id: attr.block_id, 278 } ), 279 } ) 280 .then( ( resp ) => resp.json() ) 281 .then( function ( data ) { 282 const hideForm = document.querySelector( '[name="uagb-form-' + attr.block_id + '"]' ); 283 hideForm.style.display = 'none'; 284 if ( 200 === data.data ) { 285 if ( 'message' === attr.confirmationType ) { 286 const errorMsg = document.querySelector( '.uagb-forms-success-message-' + attr.block_id ); 287 errorMsg.classList.remove( 'uagb-forms-submit-message-hide' ); 288 errorMsg.classList.add( 'uagb-forms-success-message' ); 289 } 290 291 if ( 'url' === attr.confirmationType ) { 292 window.location.replace( attr.confirmationUrl ); 293 } 294 } else if ( 400 === data.data ) { 295 if ( 'message' === attr.confirmationType ) { 296 const successMsg = document.querySelector( '.uagb-forms-failed-message-' + attr.block_id ); 297 successMsg.classList.remove( 'uagb-forms-submit-message-hide' ); 298 successMsg.classList.add( 'uagb-forms-failed-message' ); 299 } 300 } 301 } ) 302 .catch( function ( error ) { 303 console.log( JSON.stringify( error ) ); // eslint-disable-line no-console 304 } ); 305 }, 306
307 _serializeIt( form ) { 308 return Array.apply( 0, form.elements ) 309 .map( ( x ) => 310 ( ( obj ) => 311 // eslint-disable-next-line no-nested-ternary 312 x.type === 'radio' || x.type === 'checkbox' ? ( x.checked ? obj : null ) : obj )( { 313 name: x.name, 314 value: x.value, 315 } ) 316 ) 317 .filter( ( x ) => x ); 318 }, 319};
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.