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