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'}).then(function( token ) { 24 document.querySelectorAll( "#g-recaptcha-response" ).forEach( function ( elem ) { elem.value = token } ); 25 }); 26 }); 27 } 28 29 /* 30 * display reCaptcha for others blocks 31 * this part is neccessary because 32 * we have disabled the connection to Google reCaptcha API from other plugins 33 * via plugin`s php-functionality 34 */ 35 if ( 'v2' == gglcptch.options.version || 'invisible' == gglcptch.options.version ) { 36 $( '.g-recaptcha' ).each( function() { 37 /* reCAPTCHA will be generated into the empty block only */ 38 if ( $( this ).html() === '' && $( this ).text() === '' ) { 39 40 /* get element`s ID */ 41 var container = $( this ).attr( 'id' ); 42 43 if ( typeof container == 'undefined' ) { 44 container = get_id(); 45 $( this ).attr( 'id', container ); 46 } 47 48 /* get reCapatcha parameters */ 49 var sitekey = $( this ).attr( 'data-sitekey' ), 50 theme = $( this ).attr( 'data-theme' ), 51 lang = $( this ).attr( 'data-lang' ), 52 size = $( this ).attr( 'data-size' ), 53 type = $( this ).attr( 'data-type' ), 54 tabindex = $( this ).attr( 'data-tabindex' ), 55 callback = $( this ).attr( 'data-callback' ), 56 ex_call = $( this ).attr( 'data-expired-callback' ), 57 stoken = $( this ).attr( 'data-stoken' ), 58 params = []; 59 60 params['sitekey'] = sitekey ? sitekey : gglcptch.options.sitekey; 61 if ( !! theme ) { 62 params['theme'] = theme; 63 } 64 if ( !! lang ) { 65 params['lang'] = lang; 66 } 67 if ( !! size ) { 68 params['size'] = size; 69 } 70 if ( !! type ) { 71 params['type'] = type; 72 } 73 if ( !! tabindex ) { 74 params['tabindex'] = tabindex; 75 } 76 if ( !! callback ) { 77 params['callback'] = callback; 78 } 79 if ( !! ex_call ) { 80 params['expired-callback'] = ex_call; 81 } 82 if ( !! stoken ) { 83 params['stoken'] = stoken; 84 } 85 86 gglcptch.display( container, params ); 87 } 88 } ); 89 90 /* 91 * count the number of reCAPTCHA blocks in the form 92 */ 93 $( 'form' ).each( function() { 94 if ( $( this ).contents().find( 'iframe[title="recaptcha widget"]' ).length > 1 && ! $( this ).children( '.gglcptch_dublicate_error' ).length ) { 95 $( this ).prepend( '<div class="gglcptch_dublicate_error error" style="color: red;">' + gglcptch.options.error + '</div><br />\n' ); 96 } 97 } ); 98 } 99 }; 100 101 gglcptch.display = function( container, params ) { 102 if ( typeof( container ) == 'undefined' || container == '' || typeof( gglcptch.options ) == 'undefined' ) { 103 return; 104 } 105 106 // add attribute disable to the submit 107 if ( 'v2' === gglcptch.options.version && gglcptch.options.disable ) { 108 $( '#' + container ).closest( 'form' ).find( 'input:submit, button' ).prop( 'disabled', true ); 109 } 110 111 function storeEvents( el ) { 112 var target = el, 113 events = $._data( el.get( 0 ), 'events' ); 114 /* restoring events */ 115 if ( typeof events != 'undefined' ) { 116 var storedEvents = {}; 117 $.extend( true, storedEvents, events ); 118 target.off(); 119 target.data( 'storedEvents', storedEvents ); 120 } 121 /* storing and removing onclick action */ 122 if ( 'undefined' != typeof target.attr( 'onclick' ) ) { 123 target.attr( 'gglcptch-onclick', target.attr( 'onclick') ); 124 target.removeAttr( 'onclick' ); 125 } 126 } 127 128 function restoreEvents( el ) { 129 var target = el, 130 events = target.data( 'storedEvents' ); 131 /* restoring events */ 132 if ( typeof events != 'undefined' ) { 133 for ( var event in events ) { 134 for ( var i = 0; i < events[event].length; i++ ) { 135 target.on( event, events[event][i] ); 136 } 137 } 138 } 139 /* reset stored events */ 140 target.removeData( 'storedEvents' ); 141 /* restoring onclick action */ 142 if ( 'undefined' != typeof target.attr( 'gglcptch-onclick' ) ) { 143 target.attr( 'onclick', target.attr( 'gglcptch-onclick' ) ); 144 target.removeAttr( 'gglcptch-onclick' ); 145 } 146 } 147 148 function storeOnSubmit( form, gglcptch_index ) { 149 form.on( 'submit', function( e ) { 150 if ( '' == form.find( '.g-recaptcha-response' ).val() ) { 151 e.preventDefault(); 152 e.stopImmediatePropagation(); 153 targetObject = $( e.target || e.srcElement || e.targetObject ); 154 targetEvent = e.type; 155 grecaptcha.execute( gglcptch_index ); 156 } 157 } ).find( 'input:submit, button' ).on( 'click', function( e ) { 158 if ( '' == form.find( '.g-recaptcha-response' ).val() ) { 159 e.preventDefault(); 160 e.stopImmediatePropagation(); 161 targetObject = $( e.target || e.srcElement || e.targetObject ); 162 targetEvent = e.type; 163 grecaptcha.execute( gglcptch_index ); 164 } 165 } ); 166 } 167 168 var gglcptch_version = gglcptch.options.version; 169 170 if ( 'v2' == gglcptch_version ) { 171 if ( $( '#' + container ).parent().width() <= 300 && $( '#' + container ).parent().width() != 0 || $( window ).width() < 400 ) { 172 var size = 'compact'; 173 } else { 174 var size = 'normal'; 175 } 176 var parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'theme' : gglcptch.options.theme, 'size' : size }, 177 block = $( '#' + container ), 178 form = block.closest( 'form' ); 179 180 /* Callback function works only in frontend */ 181 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) { 182 parameters['callback'] = function() {
183 form.find( 'button, input:submit' ).prop( 'disabled', false ); 184 }; 185 } 186 187 var gglcptch_index = grecaptcha.render( container, parameters ); 188 $( '#' + container ).data( 'gglcptch_index', gglcptch_index ); 189 } else if ( 'invisible' == gglcptch_version ) { 190 var block = $( '#' + container ), 191 form = block.closest( 'form' ), 192 parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'size' : 'invisible', 'tabindex' : 9999 }, 193 targetObject = false, 194 targetEvent = false; 195 196 if ( form.length ) { 197 storeEvents( form ); 198 form.find( 'button, input:submit' ).each( function() { 199 storeEvents( $( this ) ); 200 } ); 201 202 /* Callback function works only in frontend */ 203 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) { 204 parameters['callback'] = function( token ) { 205 form.off(); 206 restoreEvents( form ); 207 form.find( 'button, input:submit' ).off().each( function() { 208 restoreEvents( $( this ) ); 209 } ); 210 if ( targetObject && targetEvent ) { 211 targetObject.trigger( targetEvent ); 212 } 213 form.find( 'button, input:submit' ).each( function() { 214 storeEvents( $( this ) ); 215 } ); 216 storeEvents( form ); 217 storeOnSubmit( form, gglcptch_index ); 218 grecaptcha.reset( gglcptch_index ); 219 }; 220 } 221 222 var gglcptch_index = grecaptcha.render( container, parameters ); 223 block.data( { 'gglcptch_index' : gglcptch_index } ); 224 225 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) { 226 storeOnSubmit( form, gglcptch_index ); 227 } 228 } 229 } 230 }; 231 232 $( document ).ready( function() { 233 var tryCounter = 0, 234 /* launching timer so that the function keeps trying to display the reCAPTCHA again and again until google js api is loaded */ 235 gglcptch_timer = setInterval( function() { 236 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) { 237 try { 238 gglcptch.prepare(); 239 } catch ( e ) { 240 console.log( 'Unexpected error occurred: ', e ); 241 } 242 clearInterval( gglcptch_timer ); 243 } 244 tryCounter++; 245 /* Stop trying after 10 times */ 246 if ( tryCounter >= 10 ) { 247 clearInterval( gglcptch_timer ); 248 } 249 }, 1000 ); 250 251 function gglcptch_prepare() { 252 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) { 253 try { 254 gglcptch.prepare(); 255 } catch ( err ) { 256 console.log( err ); 257 } 258 } 259 } 260 261 $( window ).on( 'load', gglcptch_prepare ); 262 263 $( '.woocommerce' ).on( 'click', '.woocommerce-tabs', gglcptch_prepare ); 264 265 $( '#recaptcha_widget_div' ).on( 'input paste change', '#recaptcha_response_field', cleanError ); 266 } ); 267 268 function cleanError() { 269 $error = $( this ).parents( '#recaptcha_widget_div' ).next( '#gglcptch_error' ); 270 if ( $error.length ) { 271 $error.remove(); 272 } 273 } 274 275 function get_id() { 276 var id = 'gglcptch_recaptcha_' + Math.floor( Math.random() * 1000 ); 277 if ( $( '#' + id ).length ) { 278 id = get_id(); 279 } else { 280 return id; 281 } 282 } 283 284} )( jQuery, gglcptch );
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.