1( function( $, gglcptch ) { 2 gglcptch = gglcptch || {}; 3 4 gglcptch.prepare = function() { 5 /* 6 * display reCaptcha for plugin`s block 7 */ 8 $( '.gglcptch_v2, .gglcptch_invisible' ).each( function() { 9 10 var container = $( this ).find( '.gglcptch_recaptcha' ); 11 12 if ( 13 container.is( ':empty' ) && 14 ( gglcptch.vars.visibility || $( this ).is( ':visible' ) === $( this ).is( ':not(:hidden)' ) ) 15 ) { 16 var containerId = container.attr( 'id' ); 17 gglcptch.display( containerId ); 18 } 19 } ); 20 21 if ( 'v3' == gglcptch.options.version ) { 22 grecaptcha.ready( function() { 23 grecaptcha.execute( gglcptch.options.sitekey, {action: 'BWS_reCaptcha_pro'}).then(function( token ) { 24 document.querySelectorAll( "#g-recaptcha-response" ).forEach( function ( elem ) { elem.value = token } ); 25 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) { 26 var gglcptchTimeout = setTimeout( function(){ 27 $( '.gglcptch_error_text' ).each( function(){ 28 if ( 0 == $( this ).parents( '.et_pb_newsletter_form').length && 0 == $( this ).parents( '.et_pb_contact_form').length ) { 29 $( this ).show(); 30 } 31 clearTimeout( gglcptchTimeout ); 32 }); 33 }, 180000 ); 34 } 35 }); 36 }); 37 } 38 39 /* 40 * display reCaptcha for others blocks 41 * this part is neccessary because 42 * we have disabled the connection to Google reCaptcha API from other plugins 43 * via plugin`s php-functionality 44 */ 45 if ( 'v2' == gglcptch.options.version || 'invisible' == gglcptch.options.version ) { 46 $( '.g-recaptcha' ).each( function() { 47 /* reCAPTCHA will be generated into the empty block only */ 48 if ( $( this ).html() === '' && $( this ).text() === '' ) { 49 50 /* get element`s ID */ 51 var container = $( this ).attr( 'id' ); 52 53 if ( typeof container == 'undefined' ) { 54 container = get_id(); 55 $( this ).attr( 'id', container ); 56 } 57 58 /* get reCapatcha parameters */ 59 var sitekey = $( this ).attr( 'data-sitekey' ), 60 theme = $( this ).attr( 'data-theme' ), 61 lang = $( this ).attr( 'data-lang' ), 62 size = $( this ).attr( 'data-size' ), 63 type = $( this ).attr( 'data-type' ), 64 tabindex = $( this ).attr( 'data-tabindex' ), 65 callback = $( this ).attr( 'data-callback' ), 66 ex_call = $( this ).attr( 'data-expired-callback' ), 67 stoken = $( this ).attr( 'data-stoken' ), 68 params = []; 69 70 params['sitekey'] = sitekey ? sitekey : gglcptch.options.sitekey; 71 if ( !! theme ) { 72 params['theme'] = theme; 73 } 74 if ( !! lang ) { 75 params['lang'] = lang; 76 } 77 if ( !! size ) { 78 params['size'] = size; 79 } 80 if ( !! type ) { 81 params['type'] = type; 82 } 83 if ( !! tabindex ) { 84 params['tabindex'] = tabindex; 85 } 86 if ( !! callback ) { 87 params['callback'] = callback; 88 } 89 if ( !! ex_call ) { 90 params['expired-callback'] = ex_call; 91 } 92 if ( !! stoken ) { 93 params['stoken'] = stoken; 94 } 95 96 gglcptch.display( container, params ); 97 } 98 } ); 99 100 /* 101 * count the number of reCAPTCHA blocks in the form 102 */ 103 $( 'form' ).each( function() { 104 if ( $( this ).contents().find( 'iframe[title="recaptcha widget"]' ).length > 1 && ! $( this ).children( '.gglcptch_dublicate_error' ).length ) { 105 $( this ).prepend( '<div class="gglcptch_dublicate_error error" style="color: red;">' + gglcptch.options.error + '</div><br />\n' ); 106 } 107 } ); 108 } 109 }; 110 111 gglcptch.display = function( container, params ) { 112 if ( typeof( container ) == 'undefined' || container == '' || typeof( gglcptch.options ) == 'undefined' ) { 113 return; 114 } 115 116 // add attribute disable to the submit 117 if ( 'v2' === gglcptch.options.version && gglcptch.options.disable ) { 118 let form = $( '#' + container ).closest( 'form' );
119 form.find( 'input:submit, input:button, button:not(.wp-hide-pw)' ).prop( 'disabled', true ); 120 } 121 122 function storeEvents( el ) { 123 var target = el, 124 events = $._data( el.get( 0 ), 'events' ); 125 /* restoring events */ 126 if ( typeof events != 'undefined' ) { 127 var storedEvents = {}; 128 $.extend( true, storedEvents, events ); 129 delete events.submit; 130 target.off(events); 131 target.data( 'storedEvents', storedEvents ); 132 } 133 /* storing and removing onclick action */ 134 if ( 'undefined' != typeof target.attr( 'onclick' ) ) { 135 target.attr( 'gglcptch-onclick', target.attr( 'onclick') ); 136 target.removeAttr( 'onclick' ); 137 } 138 } 139 140 function restoreEvents( el ) { 141 var target = el, 142 events = target.data( 'storedEvents' ); 143 /* restoring events */ 144 if ( typeof events != 'undefined' ) { 145 for ( var event in events ) { 146 for ( var i = 0; i < events[event].length; i++ ) { 147 target.on( event, events[event][i] ); 148 } 149 } 150 } 151 /* reset stored events */ 152 target.removeData( 'storedEvents' ); 153 /* restoring onclick action */ 154 if ( 'undefined' != typeof target.attr( 'gglcptch-onclick' ) ) { 155 target.attr( 'onclick', target.attr( 'gglcptch-onclick' ) ); 156 target.removeAttr( 'gglcptch-onclick' ); 157 } 158 } 159 160 function storeOnSubmit( form, gglcptch_index ) { 161 if ( typeof Backbone != "undefined" ) { 162 //Backbone.Radio.channel( 'bwsrecaptcha' ).request( 'update:execute', gglcptch_index ); 163 } 164 165 form.on( 'submit', function( e ) { 166 if ( '' == form.find( '.g-recaptcha-response' ).val() ) { 167 e.preventDefault(); 168 e.stopImmediatePropagation(); 169 targetObject = $( e.target || e.srcElement || e.targetObject ); 170 targetEvent = e.type; 171 grecaptcha.execute( gglcptch_index ); 172 } 173 } ).find( 'input:submit, button:not(.wp-hide-pw)' ).on( 'click', function( e ) { 174 if ( '' == form.find( '.g-recaptcha-response' ).val() ) { 175 e.preventDefault(); 176 e.stopImmediatePropagation(); 177 targetObject = $( e.target || e.srcElement || e.targetObject ); 178 targetEvent = e.type; 179 grecaptcha.execute( gglcptch_index ); 180 } 181 } ); 182 } 183 184 var gglcptch_version = gglcptch.options.version; 185 186 if ( 'v2' == gglcptch_version ) { 187 if ( 'normal' == gglcptch.options.size ) { 188 if ( $( '#' + container ).parent().width() <= 300 && $( '#' + container ).parent().width() != 0 || 189 /* This check is used for WP Foro Add Topic form */ 190 $( '#' + container ).parent().is(':hidden') && $( window ).width() < 400 || 191 /* This check is used for Elementor Form */ 192 $( '#' + container ).parent( 'div[class*="elementor-form"]' ).width() <= 300 ) { 193 var size = 'compact'; 194 } else { 195 var size = 'normal'; 196 } 197 } else { 198 var size = gglcptch.options.size; 199 } 200 var parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'theme' : gglcptch.options.theme, 'size' : size }, 201 block = $( '#' + container ), 202 form = block.closest( 'form' ); 203 204 /* Callback function works only in frontend */ 205 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) { 206 parameters['callback'] = function() {
207 form.find( 'input:submit, input:button, button:not(.wp-hide-pw)' ).prop( 'disabled', false ); 208 form.find( '.gglcptch_recaptcha' ).removeClass('et_contact_error'); 209 }; 210 } 211 212 gglcptch_index = grecaptcha.render( container, parameters ); 213 $( '#' + container ).data( 'gglcptch_index', gglcptch_index ); 214 } else if ( 'invisible' == gglcptch_version ) { 215 var block = $( '#' + container ), 216 form = block.closest( 'form' ), 217 parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'size' : gglcptch.options.size, 'tabindex' : 9999 }, 218 targetObject = false, 219 targetEvent = false; 220 221 if ( form.length ) { 222 storeEvents( form ); 223 form.find( 'button:not(.wp-hide-pw), input:submit' ).each( function() { 224 storeEvents( $( this ) ); 225 } ); 226 227 /* Callback function works only in frontend */ 228 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) { 229 parameters['callback'] = function( token ) { 230 if ( typeof token == 'string' ) { 231 document.getElementById('g-recaptcha-response').value=token; 232 document.getElementById('gglcptch').value=token; 233 } 234 form.off(); 235 restoreEvents( form ); 236 form.find( 'button:not(.wp-hide-pw), input:submit' ).off().each( function() { 237 restoreEvents( $( this ) ); 238 } ); 239 if ( targetObject && targetEvent ) { 240 targetObject.trigger( targetEvent ); 241 } 242 form.find( 'button:not(.wp-hide-pw), input:submit' ).each( function() { 243 storeEvents( $( this ) ); 244 } ); 245 storeEvents( form ); 246 storeOnSubmit( form, gglcptch_index ); 247 /* Condition for Ninja forms */ 248 if ( typeof Marionette == "undefined" ) { 249 grecaptcha.reset( gglcptch_index ); 250 } 251 }; 252 } 253 254 255 var gglcptch_index = grecaptcha.render( container, parameters ); 256 block.data( { 'gglcptch_index' : gglcptch_index } ); 257 258 if ( typeof Marionette != "undefined" && typeof nfRadio != "undefined" ) { 259 grecaptcha.execute( gglcptch_index ); 260 } 261 262 if ( $( '#ppc-button-ppcp-gateway' ).length > 0 ){ 263 grecaptcha.execute( gglcptch_index ).then(function(token) { 264 document.querySelectorAll( "#g-recaptcha-response" ).forEach( function ( elem ) { elem.value = token } ); 265 }); 266 } 267 268 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) { 269 storeOnSubmit( form, gglcptch_index ); 270 } 271 } 272 } 273 }; 274 275 $( document ).ready( function() { 276 var tryCounter = 0, 277 /* launching timer so that the function keeps trying to display the reCAPTCHA again and again until google js api is loaded */ 278 gglcptch_timer = setInterval( function() { 279 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) { 280 try { 281 gglcptch.prepare(); 282 } catch ( e ) { 283 //console.log( 'Unexpected error occurred: ', e ); 284 } 285 clearInterval( gglcptch_timer ); 286 } 287 tryCounter++; 288 /* Stop trying after 10 times */ 289 if ( tryCounter >= 10 ) { 290 clearInterval( gglcptch_timer ); 291 } 292 }, 1000 ); 293 294 function gglcptch_prepare() { 295 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) { 296 try { 297 gglcptch.prepare(); 298 } catch ( err ) { 299 //console.log( err ); 300 } 301 } 302 } 303 304 $( window ).on( 'load', gglcptch_prepare ); 305 306 /** 307 * WooCommerce compatibility: 308 * Generate the reCAPTCHA into previously hidden tabs content. 309 */ 310 $( '.woocommerce' ).on( 'click', '.woocommerce-tabs', gglcptch_prepare ); 311 $( 'body' ).on( 'updated_checkout', function(){ 312 if ( 'v2' === gglcptch.options.version || 'invisible' === gglcptch.options.version ) { 313 gglcptch.prepare(); 314 } 315 }); 316 317 /** 318 * WooCommerce compatibility: 319 * Reload the reCAPTCHA in case if the checkout form was not submitted. 320 */ 321 $( document.body ).on( 'checkout_error', function() { 322 if ( 'v3' === gglcptch.options.version ) { 323 grecaptcha.ready(function() { 324 grecaptcha.execute( get_site_key(), {action: 'BWS_reCaptcha_pro'}).then(function(token) { 325 document.querySelectorAll( "#g-recaptcha-response" ).forEach( function ( elem ) { elem.value = token } ); 326 }); 327 }); 328 } else { 329 console.log('checkout_error'); 330 grecaptcha.reset(); 331 332 if ( 'v2' === gglcptch.options.version && gglcptch.options.disable ) { 333 $("form").find( 'input:submit, button:not(.wp-hide-pw)' ).prop( 'disabled', true ); 334 } 335 } 336 } ); 337 338 /** 339 * WooCommerce compatibility:
340 * Loading the reCaptcha after ajax request from WooCommerce 341 */ 342 if ( $( "form" ).is( ".woocommerce-checkout" ) ) { 343 tryCounter = 0; 344 var gglcptch_time_custom = setInterval( function() { 345 $(".woocommerce-checkout input[name='_wp_http_referer']").each( function(){ 346 if ( $( this ).val().match( /wc-ajax/ ) ) { 347 gglcptch.prepare(); 348 clearInterval( gglcptch_time_custom ); 349 350 if ( 'v2' === gglcptch.options.version && gglcptch.options.disable ) { 351 $("form").find( 'input:submit, button:not(.wp-hide-pw)' ).prop( 'disabled', true ); 352 } 353 } 354 }); 355 356 tryCounter++; 357 /* Stop trying after 10 times */ 358 if ( tryCounter >= 10 ) { 359 clearInterval( gglcptch_time_custom ); 360 } 361 }, 1000 ); 362 } 363 364 /** 365 * wpForo compatibility: 366 * Loading the reCaptcha after ajax request from wpForo 367 */ 368 $( '.add_wpftopic' ).on( 'click', function() { 369 wpf_captcha_prepare(); 370 } ); 371 $( 'select.wpf-topic-form-forumid' ).on( 'change', function() { 372 wpf_captcha_prepare(); 373 } ); 374 375 $( '#recaptcha_widget_div' ).on( 'input paste change', '#recaptcha_response_field', cleanError ); 376 377 /* Reload recaptcha on CF7 */ 378 if ( MutationObserver && 0 < $( 'form.wpcf7-form .wpcf7-response-output' ).length ) { 379 var targetNode = $( 'form.wpcf7-form .wpcf7-response-output' )[0]; 380 var config = { attributes: true, childList: true, subtree: true }; 381 var observer = new MutationObserver( function( gglcptch ) { 382 if ( $( this ).text() != '' ) { 383 var gglcptch = $( this ).parent( 'form' ).find( '.gglcptch' ); 384 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) { 385 if ( gglcptch.length > 0 ) { 386 if ( gglcptch.hasClass( 'gglcptch_v3' ) ) { 387 grecaptcha.ready(function() { 388 grecaptcha.execute( get_site_key(), {action: 'BWS_reCaptcha_pro'}).then(function(token) { 389 document.querySelectorAll( "#g-recaptcha-response" ).forEach( function ( elem ) { elem.value = token } ); 390 }); 391 }); 392 } else { 393 grecaptcha.reset( gglcptch.find( '.gglcptch_recaptcha' ).data( 'gglcptch_index' ) ); 394 } 395 } 396 } 397 } 398 } ); 399 observer.observe( targetNode, config ); 400 } else if ( 0 < $( 'form.wpcf7-form .wpcf7-response-output' ).length ) { 401 $( document ).on( "DOMSubtreeModified", 'form.wpcf7-form .wpcf7-response-output', function( gglcptch ) { 402 if ( $( this ).text() != '' ) { 403 var gglcptch = $( this ).parent( 'form' ).find( '.gglcptch' ); 404 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) { 405 if ( gglcptch.length > 0 ) { 406 if ( gglcptch.hasClass( 'gglcptch_v3' ) ) { 407 grecaptcha.ready(function() { 408 grecaptcha.execute( get_site_key(), {action: 'BWS_reCaptcha_pro'}).then(function(token) { 409 document.querySelectorAll( "#g-recaptcha-response" ).forEach( function ( elem ) { elem.value = token } ); 410 }); 411 }); 412 } else { 413 grecaptcha.reset( gglcptch.find( '.gglcptch_recaptcha' ).data( 'gglcptch_index' ) ); 414 } 415 } 416 } 417 } 418 } ); 419 } 420 421 if ( false == gglcptch.options.allowlisted && 1 == gglcptch.options.divi_contact_form ) { 422 var form_divi_builder = $('.et_pb_contact_form'); 423 424 if ( 0 < form_divi_builder.length ) { 425 gglcptch_validate_divi_form( form_divi_builder, '.et-pb-contact-message' ); 426 } 427 } 428 429 if ( false == gglcptch.options.allowlisted && 1 == gglcptch.options.divi_login ) { 430 var form_login_divi_builder = $('.et_pb_newsletter_form').find('form'); 431 432 if ( 0 < form_login_divi_builder.length ) { 433 gglcptch_validate_divi_form( form_login_divi_builder, '.gglcptch_et_pb_login_message' ); 434 } 435 } 436 } ); 437 438 if ( $( '.forminator-button-submit' ).length > 0 ) { 439 var form = $( '.forminator-button-submit' ).parents( 'form' ); 440 if ( form.find( '#g-recaptcha-response' ).length > 0 ) { 441 form.find( '#g-recaptcha-response' ).appendTo( form ); 442 } 443 $( '.forminator-button-submit' ).click( function( e ){ 444 grecaptcha.execute( gglcptch.options.sitekey, {action: 'BWS_reCaptcha_pro'}).then(function( token ) { 445 form.find( '#g-recaptcha-response' ).val( token ); 446 }); 447 }); 448 } 449 450 $(window).on('load', function () { 451 $('#gglcptch-nf').on( 'focusin', function() { 452 var resp = grecaptcha.getResponse(); 453 var fieldID = jQuery( this ).data( 'id' ); 454 Backbone.Radio.channel( 'bwsrecaptcha' ).request( 'update:response', resp, fieldID ); 455 }); 456 if( $('.elementor-popup-modal').length == 0 ) { 457 setTimeout(function(){ 458 gglcptch.prepare(); 459 }, 3000); 460 } 461 }); 462 463 /* WpForo compatibility */ 464 function wpf_captcha_prepare() { 465 tryCounter = 0; 466 gglcptch_time_custom = setInterval( function() { 467 if ( $( 'form' ).is( '.wpforoeditor' ) ) { 468 gglcptch.prepare(); 469 clearInterval( gglcptch_time_custom ); 470 } 471 tryCounter++; 472 /* Stop trying after 10 times */ 473 if ( tryCounter >= 10 ) { 474 clearInterval( gglcptch_time_custom ); 475 } 476 }, 1000 ); 477 } 478 479 function cleanError() { 480 $error = $( this ).parents( '#recaptcha_widget_div' ).next( '#gglcptch_error' ); 481 if ( $error.length ) { 482 $error.remove(); 483 } 484 } 485 486 function get_id() { 487 var id = 'gglcptch_recaptcha_' + Math.floor( Math.random() * 1000 ); 488 if ( $( '#' + id ).length ) { 489 id = get_id(); 490 } else { 491 return id; 492 } 493 } 494 495 function get_site_key() { 496 return gglcptch.options.sitekey; 497 } 498 499 function gglcptch_validate_divi_form( form, messageClass ) { 500 if( 'v2' == gglcptch.options.version && '.et-pb-contact-message' == messageClass && form.find('.g-recaptcha-response').text() == '' ) { 501 setTimeout( function(){
502 form.find( 'input:submit, input:button, button:not(.wp-hide-pw)' ).prop( 'disabled', true ); 503 form.find( '.gglcptch_recaptcha' ).addClass('et_contact_error'); 504 }, 1000); 505 } 506 form.submit( function (e) { 507 let g_recaptcha_response = $( this ).find('.g-recaptcha-response'); 508 509 if ( 'v3' === gglcptch.options.version ) { 510 grecaptcha.ready(function () { 511 grecaptcha.execute(gglcptch.options.sitekey, {action: 'BWS_reCaptcha_pro'}).then(function ( token ) { 512 $( this ).find('#g-recaptcha-response').val( token ); 513 }); 514 }); 515 } 516 517 var currentForm = $( this ); 518 $.ajax({ 519 async: false, 520 cache: false, 521 type: 'POST', 522 url: gglcptch.ajax_url, 523 headers: { 524 'Content-Type': 'application/x-www-form-urlencoded' 525 }, 526 data: { 527 action: 'gglcptch_captcha_check_for_divi', 528 recaptcha_challenge_field: currentForm.find('#recaptcha_challenge_field').val(), 529 recaptcha_response_field: currentForm.find('#recaptcha_response_field').val(), 530 'g-recaptcha-response': g_recaptcha_response.val(), 531 }, 532 success: function ( data ) { 533 if ( '.et-pb-contact-message' == messageClass ) { 534 if ( 'v2' == gglcptch.options.version || 'invisible' == gglcptch.options.version ) { 535 if ( 'success' === data ) { 536 currentForm.data( 'submitted', false ); 537 g_recaptcha_response.removeAttr( 'id' ); 538 g_recaptcha_response.attr( 'name', 'g-recaptcha-response_0' ); 539 } else { 540 grecaptcha.reset() 541 currentForm.find( messageClass ).html( data ); 542 currentForm.data( 'submitted', true ); 543 } 544 } 545 } else { 546 if ( 'success' !== data ) { 547 grecaptcha.reset() 548 currentForm.find( messageClass ).html( data ); 549 e.preventDefault(); 550 } 551 } 552 } 553 }); 554 }); 555 } 556 557 558 559})( jQuery, gglcptch ); 560 561/*For Ninja Forms*/ 562if ( typeof Marionette != "undefined" && typeof nfRadio != "undefined" ) { 563 var bwsrecaptchaFieldController = Marionette.Object.extend({ 564 fieldType: 'bwsrecaptcha', 565 initialize: function() { 566 Backbone.Radio.channel( this.fieldType ).reply( 'get:submitData', this.getSubmitData ); 567 this.listenTo( nfRadio.channel( this.fieldType ), 'init:model', this.initRecaptcha ); 568 this.listenTo( nfRadio.channel( 'form' ), 'render:view', this.renderCaptcha ); 569 }, 570 getSubmitData: function( fieldData ) { 571 fieldData.value = document.getElementById('g-recaptcha-response').value; 572 return fieldData; 573 }, 574 initRecaptcha: function ( model ) { 575 if ( model.attributes['recaptcha_version'] == 'v3'|| model.attributes['recaptcha_version'] == 'invisible' ){ 576 model.set( 'label_pos', 'hidden' ); 577 } 578 nfRadio.channel( this.fieldType ).reply( 'update:response', this.updateResponse, this, model.id ); 579 nfRadio.channel( this.fieldType ).reply( 'update:execute', this.updateExecute, 0 ); 580 }, 581 updateResponse: function( response, fieldID ) { 582 var model = nfRadio.channel( 'fields' ).request( 'get:field', fieldID ); 583 model.set( 'value', response ); 584 nfRadio.channel( 'fields' ).request( 'remove:error', model.id , 'required-error' ); 585 }, 586 renderCaptcha: function() { 587 var public_key = jQuery( '#gglcptch-nf' ).data( 'publickey' ); 588 if ( 'v3' == jQuery( '#gglcptch-nf' ).data( 'version' ) ) { 589 grecaptcha.ready(function() { 590 grecaptcha.execute( public_key, {action: 'BWS_reCaptcha_pro'}).then(function(token) { 591 document.getElementById('g-recaptcha-response').value=token; 592 document.getElementById('gglcptch').value=token; 593 }); 594 }); 595 } 596 }, 597 updateExecute: function ( gglcptch_index ) { 598 grecaptcha.execute( gglcptch_index ); 599 } 600 }); 601 602 new bwsrecaptchaFieldController(); 603} 604
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.