1//var ITM_SendpressSignup = window.ITM_SendpressSignup || {}; 2console.log('sendpress.signup.js file loaded.....'); 3 4;(function ( $, window, document, undefined ) { 5 //as usual way for simple page load sites. 6 $(document).ready(function($) { 7 console.log('sendpress.signup.js >> document ready >> readyFn_SendpressSignup'); 8 //WPB-3776 9 readyFn_SendpressSignup( $ , 'document.ready'); 10 }); 11 12}).call( window.sendpress=window.sendpress || {}, jQuery, window, document ); 13 14var readyFn_signupCalled = false; 15 16 //------------------------------------------------------- 17 //put outside it. pjax site. WPB-3763 + WPB-3776 18 function readyFn_SendpressSignup( $ , flagCheck = '') { 19 20 if (readyFn_signupCalled) { 21 //alert('already called >> readyFn_SendpressSignup'); 22 console.log('already called return to stop second time calling >> readyFn_SendpressSignup >> '+flagCheck); 23 if (flagCheck == 'document.ready') { 24 console.log('return here.....'); 25 // return; //WPB-4363 - comented because form not submitted 26 } 27 } 28 29 //alert('readyFn_SendpressSignup : '+flagCheck); 30 console.log('Now called >> readyFn_SendpressSignup >> '+flagCheck); 31 32 if (flagCheck == 'popup') { // /vipclub/classes/sc/class-sendpress-sc-forms.php 33 readyFn_signupCalled = true; 34 setTimeout(popup_recaptcha, 200); 35 } 36 37 var $signups = $('.sendpress-signup'); 38 $signups.each(function(){ 39 $form = $(this), 40 $error = $form.find('#error'), 41 $thanks = $form.find('#thanks'); 42 43 $error.hide(); 44 $thanks.hide(); 45 }); 46 47 //same into common_functions.js file. 48 function isDateCheck(txtDate) { 49 var currVal = txtDate; 50 if(currVal == '') 51 return false; 52 53 //Declare Regex 54 var rxDatePattern = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/; 55 var dtArray = currVal.match(rxDatePattern); // is format OK? 56 57 if (dtArray == null) 58 return false; 59 60 //Checks for mm/dd/yyyy format. 61 dtMonth = dtArray[1]; 62 dtDay= dtArray[3]; 63 dtYear = dtArray[5]; 64 65 if (dtMonth < 1 || dtMonth > 12) 66 return false; 67 else if (dtDay < 1 || dtDay> 31) 68 return false; 69 else if ((dtMonth==4 || dtMonth==6 || dtMonth==9 || dtMonth==11) && dtDay ==31) 70 return false; 71 else if (dtMonth == 2) { 72 var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0)); 73 if (dtDay> 29 || (dtDay ==29 && !isleap)) 74 return false; 75 } 76 return true; 77 }//End of function isDateCheck 78 79 //common fun to check required fields validation for "VIP Club Forms" 80 function checkRequiredValidation(formObj, fieldName, messageVal, signupField) { 81 var submit_ok_return = true; 82 try { 83 if(formObj.find('.'+fieldName)){ //object found then only check. 84 if( signupField.length === 0 ){ 85 $isRequiredSpanElt = formObj.find('.'+fieldName).parent().find( "label" ).find( "span" ); 86 var isRequiredSpanColor = $isRequiredSpanElt.css( "color" ); 87 if (isRequiredSpanColor && isRequiredSpanColor != 'undefined') { 88 $error.show(); 89 $error.html('<div class="item">*'+messageVal+'.</div>'); 90 submit_ok_return = false; 91 return submit_ok_return; 92 } else if('sp_howcanyouhelp_response' == fieldName) {//WPB-109 93 $error.show(); 94 $error.html('<div class="item">*'+messageVal+'.</div>'); 95 submit_ok_return = false; 96 return submit_ok_return; 97 } 98 }//End of if( signupField.length === 0 ) 99 } 100 } 101 catch(e) { } 102 return submit_ok_return; 103 }//End of function checkRequiredValidation 104 105 $signups.submit(function(e){ 106 console.log('sendpress.signup.js submit.....'); 107 //alert('class-sendpress-sc-forms.php OR class-sendpress-sc-signup.php'); //return false;
108 e.preventDefault(); 109 110 // Initialize form variables first to avoid scope issues 111 var $form = $(this); 112 var $error = $form.find('#error'); 113 var $thanks = $form.find('#thanks'); 114 var $formwrap = $form.find('#form-wrap'); 115 var $submit = $form.find('#submit'); 116 var $ajaxInd = $form.find('.ajaxloader'); 117 118 // For reCAPTCHA validation 119 var isRecaptchaValid = false; 120 121 // First check: if submit button is enabled, reCAPTCHA was likely completed 122 var $submitButton = $form.find('.sendpress-submit'); 123 if (!$submitButton.prop('disabled')) { 124 isRecaptchaValid = true; 125 } else { 126 // Second check: try to get response from grecaptcha API 127 try { 128 if (typeof grecaptcha !== 'undefined' && typeof grecaptcha.getResponse === 'function') { 129 var recaptchaResponse = grecaptcha.getResponse(); 130 if (recaptchaResponse && recaptchaResponse.length > 0) { 131 isRecaptchaValid = true; 132 } 133 } 134 } catch (error) { 135 console.log('Error checking reCAPTCHA response:', error); 136 } 137 138 // Third check: look for g-recaptcha-response hidden field 139 var $recaptchaResponse = $form.find('[name="g-recaptcha-response"]'); 140 if ($recaptchaResponse.length > 0 && $recaptchaResponse.val() && $recaptchaResponse.val().length > 0) { 141 isRecaptchaValid = true; 142 } 143 } 144 145 // If not valid, show message 146 if (!isRecaptchaValid) { 147 alert('Please check the "I am not a robot" checkbox.'); 148 return false; 149 } 150 151 var signup = {}, 152 submit_ok = true, 153 submit_ok_return_val = true, 154 emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,10})?$/; 155 alphabetReg = /^[a-zA-Z !@#$%^&*)(_+\-=\[\]{};':"\\|,.<>\/?]*$/ ; 156 regZip = /^[0-9 !@#$%^&*)(_+\-=\[\]{};':"\\|,.<>\/?]*$/; 157 //regCell = /^[0-9 !@#$%^&*)(_+\-=\[\]{};':"\\|,.<>\/?]*$/; 158 159 //wpb-315 160 try { 161 var $gdpr_div = $form.find('.gdpr_html_div_class'); 162 var gdpr_chk_id = $gdpr_div.find('.gdpr_chk_box').attr('id'); 163 if (gdpr_chk_id && gdpr_chk_id != 'undefined') { //if found gdpr checkbox then only. 164 var chk_error_text = gdpr_chk_error_msg; 165 if ($gdpr_div.find('.gdpr_chk_box').is(':checked')) { 166 //if terms gdpr checked then allow below code as usual. 167 } 168 else { 169 alert(chk_error_text); 170 return false; 171 } 172 } 173 }catch(e) {} 174 175 $error.hide(); 176 $ajaxInd.show(); 177 178 signup['first'] = $form.find('.sp_firstname').val(); 179 signup['last'] = $form.find('.sp_lastname').val(); 180 signup['email'] = $form.find('.sp_email').val(); 181 signup['address1'] = $form.find('.sp_address1').val(); 182 signup['address2'] = $form.find('.sp_address2').val(); 183 signup['city'] = $form.find('.sp_city').val(); 184 signup['state'] = $form.find('.sp_state').val(); 185 signup['country'] = $form.find('.sp_country').val(); 186 signup['zip'] = $form.find('.sp_zip').val(); 187 signup['cell'] = $form.find('.sp_cell').val(); 188 signup['birthday'] = $form.find('.sp_birthday').val(); 189 signup['gender'] = $form.find('.sp_gender:checked').val(); 190 signup['facebook'] = $form.find('.sp_facebook').val(); 191 signup['twitter'] = $form.find('.sp_twitter').val(); 192 signup['instagram'] = $form.find('.sp_instagram').val(); 193 signup['pinterest'] = $form.find('.sp_pinterest').val(); 194 signup['canwetextyou'] = $form.find('.sp_canwetextyou:checked').val();//WPB-109 195 signup['willyouvolunteer'] = $form.find('.sp_willyouvolunteer:checked').val();//WPB-109 196 signup['g-recaptcha-response'] = recaptchaResponse; 197 198 //WPB-109 199 if( $form.find('.sp_howcanyouhelp') ){ 200 var howcanyouhelp = []; 201 $('.sp_howcanyouhelp:checked').each(function(){ 202 howcanyouhelp.push($(this).val()); 203 }); 204 if ($('#sp_howcanyouhelp_other').is(':checked')) { 205 signup['howcanyouhelp_response'] = $form.find('#sp_howcanyouhelp_response').val();//WPB-109 206 try { 207 submit_ok_return_val = checkRequiredValidation($form, 'sp_howcanyouhelp_response', 'Please enter other response.', signup.howcanyouhelp_response); 208 if (!submit_ok_return_val) { 209 submit_ok = false;
210 } 211 } 212 catch(e) {} 213 } 214 } 215 //console.log("canwetextyou-"+signup['canwetextyou']); 216 signup['howcanyouhelp'] = howcanyouhelp ;//WPB-109 217 218 signup['listid'] = "";//$form.find('.sp_list').val(); 219 220 $form.find("input:checkbox.sp_list:checked").each(function(){ 221 signup['listid'] += $(this).val() +","; 222 }); 223 if(signup['listid'] === ""){ 224 signup['listid'] = $form.find('.sp_list').val(); 225 } 226 227 $form.find('.custom-field').each(function(){ 228 var $obj = $(this); 229 signup[$obj.attr('id')] = $obj.val(); 230 }); 231 232 signup['action'] = 'sendpress_subscribe_to_list'; 233 234 //Validations code........ 235//------------------------------------------------------------------------------------------------------------- 236 // Start WPB-109 237 if( $form.find('.sp_howcanyouhelp') ){ 238 if ($('#sp_howcanyouhelp_other').is(':checked')) { 239 try { 240 submit_ok_return_val = checkRequiredValidation($form, 'sp_howcanyouhelp_response', 'Please enter other response.', signup.howcanyouhelp_response); 241 if (!submit_ok_return_val) { 242 submit_ok = false; 243 } 244 } 245 catch(e) {} 246 } 247 } 248 try { 249 submit_ok_return_val = checkRequiredValidation($form, 'sp_howcanyouhelp', 'Please select at least one How can you help option.', signup.howcanyouhelp); 250 if (!submit_ok_return_val) { 251 submit_ok = false; 252 } 253 } 254 catch(e) {} 255 // End WPB-109 256 try { 257 submit_ok_return_val = checkRequiredValidation($form, 'sp_pinterest', 'Pinterest Name can not be empty', signup.pinterest); 258 if (!submit_ok_return_val) { 259 submit_ok = false; 260 } 261 } 262 catch(e) {} 263 try { 264 submit_ok_return_val = checkRequiredValidation($form, 'sp_pinterest', 'Pinterest Name can not be empty', signup.pinterest); 265 if (!submit_ok_return_val) { 266 submit_ok = false; 267 } 268 } 269 catch(e) {} 270 try { 271 submit_ok_return_val = checkRequiredValidation($form, 'sp_instagram', 'Instagram Name can not be empty', signup.instagram); 272 if (!submit_ok_return_val) { 273 submit_ok = false; 274 } 275 } 276 catch(e) {} 277 try { 278 submit_ok_return_val = checkRequiredValidation($form, 'sp_twitter', 'Twitter Name can not be empty', signup.twitter); 279 if (!submit_ok_return_val) { 280 submit_ok = false; 281 } 282 } 283 catch(e) {} 284 try { 285 submit_ok_return_val = checkRequiredValidation($form, 'sp_facebook', 'Facebook Name can not be empty', signup.facebook); 286 if (!submit_ok_return_val) { 287 submit_ok = false; 288 } 289 } 290 catch(e) {} 291 try { 292 submit_ok_return_val = checkRequiredValidation($form, 'sp_country', 'Country can not be empty', signup.country); 293 if (!submit_ok_return_val) { 294 submit_ok = false; 295 } 296 } 297 catch(e) {} 298 try { 299 submit_ok_return_val = checkRequiredValidation($form, 'sp_state', 'State can not be empty', signup.state); 300 if (!submit_ok_return_val) { 301 submit_ok = false; 302 } 303 } 304 catch(e) {} 305 try { 306 submit_ok_return_val = checkRequiredValidation($form, 'sp_city', 'City can not be empty', signup.city); 307 if (!submit_ok_return_val) { 308 submit_ok = false;
309 } 310 } 311 catch(e) {} 312 try { 313 submit_ok_return_val = checkRequiredValidation($form, 'sp_address2', 'Address 2 can not be empty', signup.address2); 314 if (!submit_ok_return_val) { 315 submit_ok = false; 316 } 317 } 318 catch(e) {} 319 try { 320 submit_ok_return_val = checkRequiredValidation($form, 'sp_address1', 'Address 1 can not be empty', signup.address1); 321 if (!submit_ok_return_val) { 322 submit_ok = false; 323 } 324 } 325 catch(e) {} 326 try { 327 submit_ok_return_val = checkRequiredValidation($form, 'sp_cell', sendpress.missingcellnumber, signup.cell); 328 if (!submit_ok_return_val) { 329 submit_ok = false; 330 } 331 } 332 catch(e) {} 333 if(signup.cell){ 334 if ( signup.cell.length > 0 && !regZip.test(signup.cell)) { 335 $error.show(); 336 $error.html('<div class="item">'+sendpress.invalidcellnumber+'.</div>'); 337 submit_ok = false; 338 } 339 } 340 //check is required zip. 341 try { 342 submit_ok_return_val = checkRequiredValidation($form, 'sp_zip', sendpress.missingzip, signup.zip); 343 if (!submit_ok_return_val) { 344 submit_ok = false; 345 } 346 } 347 catch(e) {} 348 if(signup.zip){ 349 if(signup.zip.length > 0 && !regZip.test(signup.zip)) { 350 $error.show(); 351 $error.html('<div class="item">'+sendpress.invalidzip+'.</div>'); 352 submit_ok = false; 353 } 354 } 355 try { 356 submit_ok_return_val = checkRequiredValidation($form, 'sp_birthday', 'Birthday can not be empty', signup.birthday); 357 if (!submit_ok_return_val) { 358 submit_ok = false; 359 } 360 } 361 catch(e) {} 362 363 //var currentDate = Date.now(); 364 //console.log(currentDate); 365 366 var currentDate_new = new Date(); 367 //let day_chk = currentDate_new.getDate(); 368 let day_chk = String(currentDate_new.getDate()).padStart(2, '0'); 369 //let month_chk = currentDate_new.getMonth() + 1; 370 let month_chk = String(currentDate_new.getMonth()+1).padStart(2,'0'); 371 let year_chk = currentDate_new.getFullYear(); 372 373 let currentDate_chk = `${month_chk}/${day_chk}/${year_chk}`; //mm/dd/yyyy 374 //console.log(currentDate_chk); 375 376 try { 377 if(signup.birthday){ 378 if(signup.birthday.length > 0) { 379 380 //if (Date.parse(signup.birthday)) { 381 if(isDateCheck(signup.birthday)) { 382 //proper date format mm/dd/yyyy and also months and days proper way. 22/22/2222 is invalidate date as month value is 22. 383 384 // WPB-5775 -- vipclub/classes/sc/class-sendpress-sc-forms.php 385 var birthdayDate = new Date(signup.birthday); 386 var currentDateTime = new Date(currentDate_chk); 387 var ageInYears = currentDateTime.getFullYear() - birthdayDate.getFullYear(); 388 var monthDiff = currentDateTime.getMonth() - birthdayDate.getMonth(); 389 if (monthDiff < 0 || (monthDiff === 0 && currentDateTime.getDate() < birthdayDate.getDate())) { 390 ageInYears--; 391 } 392 console.log(ageInYears); 393 if (ageInYears <= 12) { 394 $error.show(); 395 $error.html('<div class="item">Oops! Looks like you\'re not quite old enough to sign up. We only allow users aged 13 and above to provide their information on this website. Hang in there, and we hope to see you back when you\'re a bit older!</div>'); 396 submit_ok = false;
397 } 398 } 399 else { 400 $error.show(); 401 $error.html('<div class="item">Invalid birthday date.</div>'); 402 submit_ok = false; 403 } 404 } 405 } 406 } 407 catch(e) {} 408 //check is required last name. 409 try { 410 submit_ok_return_val = checkRequiredValidation($form, 'sp_lastname', sendpress.missinglastname, signup.last); 411 if (!submit_ok_return_val) { 412 submit_ok = false; 413 } 414 } 415 catch(e) {} 416 417 if(signup.last){ 418 if(signup.last.length > 0 && !alphabetReg.test(signup.last)) { 419 $error.show(); 420 $error.html('<div class="item>'+sendpress.invalidlastName+'.</div>'); 421 submit_ok = false; 422 } 423 } 424 425 //check is required first name. 426 try { 427 //instead of individual code, used common func checkRequiredValidation() 428 submit_ok_return_val = checkRequiredValidation($form, 'sp_firstname', sendpress.missingfirstname, signup.first); 429 if (!submit_ok_return_val) { 430 submit_ok = false; 431 } 432 } 433 catch(e) {} 434 435 if(signup.first){ 436 if(signup.first.length > 0 && !alphabetReg.test(signup.first)) { 437 $error.show(); 438 $error.html('<div class="item">'+sendpress.invalidfirstName+'.</div>'); 439 submit_ok = false; 440 } 441 } 442 443 //must required filed. so, must check. 444 if( signup.email.length === 0 ){ 445 $error.show(); 446 $error.html('<div class="item">*'+sendpress.missingemail+'.</div>'); 447 submit_ok = false; 448 } 449 if (signup.email.length > 0 && !emailReg.test(signup.email)) { 450 $error.show(); 451 $error.html('<div class="item">'+sendpress.invalidemail+'.</div>'); 452 submit_ok = false; 453 } 454 455 456//------------------------------------------------------------------------------------------------------------- 457 if(submit_ok){ 458 $submit.attr("disabled", "disabled"); 459 jQuery.post(sendpress.ajaxurl, signup, function(response){ 460 try { 461 response = JSON.parse(response); 462 } catch (err) { 463 // Invalid JSON. 464 $submit.removeAttr("disabled"); 465 if(!jQuery.trim(response).length) { 466 response = { error: 'Server returned empty response during charge attempt'}; 467 } else { 468 response = {error: 'Server returned invalid response:<br /><br />' + response}; 469 } 470 } 471 if(response['success']){ 472 $error.hide(); 473 $formwrap.hide(); 474 $("#vip-form-header-message").hide(); // use for wabc model box header 475 $thanks.show(); 476 $ajaxInd.hide(); 477 }else{ 478 //possibly display an error here 479 $ajaxInd.hide(); 480 } 481 }); 482 483 }else{ 484 $ajaxInd.hide(); 485 } 486 return false; 487 }); 488 489 $('.sendpress-signup input').bind('focus blur',function(e){ 490 var $obj = $(this), 491 $value = $obj.val(), 492 $orig = $obj.attr('orig'); 493 if(e.type === "focus"){ 494 if($value === $orig){ 495 $obj.val(''); 496 } 497 }else{ 498 if($value === ''){ 499 $obj.val($orig); 500 } 501 } 502 }); 503 504 $('.sendpress-signup .post-notifications-list').on('click', function(e){ 505 var $obj = $(this), 506 $form = $obj.closest('form.sendpress-signup'), 507 type = $obj.data('type'), 508 hidden = "<input class='post-notifications custom-field' type='hidden' value='"+type+"' name='post_notifications' id='post_notifications'/>"; 509 if($obj.is(':checked')){
510 $form.append(hidden); 511 }else{ 512 $form.find('.post-notifications').remove(); 513 } 514 }); 515 516 try { 517 518 // birthday 519 $('.sp_birthday').datepicker({ 520 changeMonth: true, 521 changeYear: true, 522 dateFormat: 'mm/dd/yy', 523 minDate: new Date(1930, 2 - 1, 26), //WPB-3683 524 maxDate: 'today', /* maxDate: "+1D", */ 525 //WPB-3683 526 yearRange: "-100:+0" /* yearRange: '1930:2022' */ 527 }); 528 529 } 530 catch(e){ 531 console.log("opps! catch : datepicker sendpress.signup.js....."); 532 } 533 534 //}); //End of $(document).ready(function($) 535 536 }//End of function readyFn_SendpressSignup 537 //------------------------------------------------------- 538 539//}).call( window.sendpress=window.sendpress || {}, jQuery, window, document ); 540//no need here. moved above. 541 542function checkForMember(){ 543 if(jQuery('#showSignup').length>0){ 544 jQuery("#vipSignupForm").modal({'backdrop':'static', 'show':true}); 545 jQuery("body").append('<div class="wpb-ugc vip-member-backdrop"><div class="modal-backdrop fade in"></div></div>'); 546 jQuery('#refreshAfterSignup').hide(); 547 } 548 else if(jQuery('#checkMember').length>0){ 549 var isMember = getCookie("vipclubMemberOnly"); 550 if (isMember == null) { 551 jQuery("#vipSignupForm").modal('hide'); 552 jQuery("#vipLoginForm").modal({'backdrop':'static', 'show':true}); 553 jQuery("body").append('<div class="wpb-ugc vip-member-backdrop"><div class="modal-backdrop fade in"></div></div>'); 554 document.querySelector("body").style.overflow = 'hidden'; 555 jQuery("#vipSignupForm").modal('hide'); 556 } 557 }else{ 558 jQuery(".vip-member-backdrop").remove(); 559 document.querySelector("body").style.overflow = 'visible'; 560 } 561} 562 563 564if (typeof readyFn_recaptcha === "undefined") { 565 // Track which reCAPTCHA elements have been rendered 566 function readyFn_recaptcha(){ 567 jQuery.getScript("https://www.google.com/recaptcha/api.js"); 568 jQuery(".g-recaptcha").each(function () { 569 grecaptcha.render(this, { 570 'sitekey': jQuery( this ).attr( 'data-sitekey' ), 571 }); 572 }); 573 } 574} 575 576 577var renderedCaptchas = []; 578function popup_recaptcha(){ 579 // Store the current reCAPTCHA elements before removing them 580 var captchaElements = []; 581 jQuery('.g-recaptcha').each(function() { 582 captchaElements.push({ 583 id: jQuery(this).attr('id'), 584 sitekey: jQuery(this).attr('data-sitekey'), 585 callback: jQuery(this).attr('data-callback') 586 }); 587 }); 588 589 // First, completely clean up any existing reCAPTCHA elements 590 // This is more thorough than just removing iframes 591 jQuery('.g-recaptcha').each(function() { 592 // Keep only the container with its ID, remove everything else 593 var $this = jQuery(this); 594 var id = $this.attr('id'); 595 var sitekey = $this.attr('data-sitekey'); 596 var callback = $this.attr('data-callback'); 597 var className = $this.attr('class'); 598 599 // Replace with a clean element 600 var newElement = jQuery('<div>', { 601 'id': id, 602 'class': className, 603 'data-sitekey': sitekey, 604 'data-callback': callback 605 }); 606 607 $this.replaceWith(newElement); 608 }); 609 610 // Reset any existing reCAPTCHA instances 611 if (typeof grecaptcha !== 'undefined') { 612 try { 613 if (typeof grecaptcha.reset === 'function') { 614 grecaptcha.reset(); 615 } 616 617 // Try to clean up any leftover reCAPTCHA state 618 if (typeof window.___grecaptcha_cfg !== 'undefined') { 619 // This is an internal reCAPTCHA object that can cause issues if not reset 620 try { 621 // Reset the count of rendered elements 622 if (window.___grecaptcha_cfg.count) { 623 window.___grecaptcha_cfg.count = 0; 624 } 625 // Clean up rendered elements 626 if (window.___grecaptcha_cfg.clients) { 627 window.___grecaptcha_cfg.clients = {}; 628 } 629 } catch (e) { 630 // Ignore errors in cleanup 631 } 632 } 633 } catch (e) { 634 // Ignore errors during reset 635 } 636 } 637 638 // Load the reCAPTCHA script 639 jQuery.getScript("https://www.google.com/recaptcha/api.js", function() { 640 // Small delay to ensure API is fully loaded 641 setTimeout(function() { 642 // Check if grecaptcha is available 643 if (typeof grecaptcha === 'undefined' || typeof grecaptcha.render !== 'function') { 644 setTimeout(function() { 645 renderCaptchas(captchaElements); 646 }, 500); 647 return; 648 } 649 650 renderCaptchas(captchaElements); 651 }, 200); 652 }); 653} 654 655// Separate function to render captchas 656function renderCaptchas(captchaElements) { 657 // If captchaElements is provided, use that instead of scanning the DOM 658 var elementsToRender = captchaElements || []; 659 660 // If no elements were provided, find them in the DOM 661 if (!elementsToRender.length) { 662 jQuery(".g-recaptcha").each(function() { 663 var $this = jQuery(this); 664 elementsToRender.push({ 665 element: this, 666 id: $this.attr('id'), 667 sitekey: $this.attr('data-sitekey'), 668 callback: $this.attr('data-callback') 669 }); 670 }); 671 } 672 673 // Render each captcha element 674 for (var i = 0; i < elementsToRender.length; i++) { 675 var item = elementsToRender[i]; 676 var element = item.element || document.getElementById(item.id); 677 678 // Skip if element doesn't exist 679 if (!element) continue; 680 681 // Skip if already rendered 682 if (renderedCaptchas.indexOf(item.id) !== -1) continue; 683 684 try {
685 // Completely empty the element - remove all content and attributes except ID 686 var elementId = jQuery(element).attr('id'); 687 var elementClass = jQuery(element).attr('class'); 688 var parentElement = jQuery(element).parent(); 689 690 // Create a new empty element with the same ID 691 var newElement = jQuery('<div>', { 692 'id': elementId, 693 'class': elementClass, 694 'data-sitekey': item.sitekey 695 }); 696 697 // Replace the old element with the new one 698 jQuery(element).replaceWith(newElement); 699 700 // Update our reference to point to the new element 701 element = document.getElementById(elementId); 702 703 // Create config object 704 var config = { 705 'sitekey': item.sitekey 706 }; 707 708 // Add callback if exists 709 if (item.callback) { 710 config.callback = item.callback; 711 newElement.attr('data-callback', item.callback); 712 } 713 714 // Render the captcha on the new clean element 715 var widgetId = grecaptcha.render(elementId, config); 716 717 // Store widget ID in a data attribute for future reference 718 newElement.attr('data-widget-id', widgetId); 719 720 // Mark as rendered 721 renderedCaptchas.push(item.id); 722 } catch (error) { 723 // Handle errors 724 if (error.message && error.message.indexOf('already been rendered') !== -1) { 725 if (item.id && renderedCaptchas.indexOf(item.id) === -1) { 726 renderedCaptchas.push(item.id); 727 } 728 } 729 } 730 } 731}
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.