PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.72
reCaptcha by BestWebSoft v1.72
1.79 1.80 1.82 1.83 1.84 1.85 1.86 1.87 trunk 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.35 1.36 1.37 1.38 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.57 1.58 1.59 1.60 1.61 1.62 1.63 1.64 1.65 1.66 1.67 1.68 1.70 1.71 1.72 1.73 1.74 1.75 1.78
google-captcha / js / script.js
google-captcha / js Last commit date
admin_script.js 3 years ago pre-api-script.js 3 years ago script.js 3 years ago
script.js
298 lines
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 var gglcptchTimeout = setTimeout( function(){
26 $( '.gglcptch_error_text' ).each( function(){
27 $( this ).show();
28 clearTimeout( gglcptchTimeout );
29 });
30 }, 180000 );
31 });
32 });
33 }
34
35 /*
36 * display reCaptcha for others blocks
37 * this part is neccessary because
38 * we have disabled the connection to Google reCaptcha API from other plugins
39 * via plugin`s php-functionality
40 */
41 if ( 'v2' == gglcptch.options.version || 'invisible' == gglcptch.options.version ) {
42 $( '.g-recaptcha' ).each( function() {
43 /* reCAPTCHA will be generated into the empty block only */
44 if ( $( this ).html() === '' && $( this ).text() === '' ) {
45
46 /* get element`s ID */
47 var container = $( this ).attr( 'id' );
48
49 if ( typeof container == 'undefined' ) {
50 container = get_id();
51 $( this ).attr( 'id', container );
52 }
53
54 /* get reCapatcha parameters */
55 var sitekey = $( this ).attr( 'data-sitekey' ),
56 theme = $( this ).attr( 'data-theme' ),
57 lang = $( this ).attr( 'data-lang' ),
58 size = $( this ).attr( 'data-size' ),
59 type = $( this ).attr( 'data-type' ),
60 tabindex = $( this ).attr( 'data-tabindex' ),
61 callback = $( this ).attr( 'data-callback' ),
62 ex_call = $( this ).attr( 'data-expired-callback' ),
63 stoken = $( this ).attr( 'data-stoken' ),
64 params = [];
65
66 params['sitekey'] = sitekey ? sitekey : gglcptch.options.sitekey;
67 if ( !! theme ) {
68 params['theme'] = theme;
69 }
70 if ( !! lang ) {
71 params['lang'] = lang;
72 }
73 if ( !! size ) {
74 params['size'] = size;
75 }
76 if ( !! type ) {
77 params['type'] = type;
78 }
79 if ( !! tabindex ) {
80 params['tabindex'] = tabindex;
81 }
82 if ( !! callback ) {
83 params['callback'] = callback;
84 }
85 if ( !! ex_call ) {
86 params['expired-callback'] = ex_call;
87 }
88 if ( !! stoken ) {
89 params['stoken'] = stoken;
90 }
91
92 gglcptch.display( container, params );
93 }
94 } );
95
96 /*
97 * count the number of reCAPTCHA blocks in the form
98 */
99 $( 'form' ).each( function() {
100 if ( $( this ).contents().find( 'iframe[title="recaptcha widget"]' ).length > 1 && ! $( this ).children( '.gglcptch_dublicate_error' ).length ) {
101 $( this ).prepend( '<div class="gglcptch_dublicate_error error" style="color: red;">' + gglcptch.options.error + '</div><br />\n' );
102 }
103 } );
104 }
105 };
106
107 gglcptch.display = function( container, params ) {
108 if ( typeof( container ) == 'undefined' || container == '' || typeof( gglcptch.options ) == 'undefined' ) {
109 return;
110 }
111
112 // add attribute disable to the submit
113 if ( 'v2' === gglcptch.options.version && gglcptch.options.disable ) {
114 $( '#' + container ).closest( 'form' ).find( 'input:submit, button' ).prop( 'disabled', true );
115 if ( 'setupform' === $( '#' + container ).closest( 'form' ).attr( 'id' ) ) {
116 setTimeout(
117 function(){
118 $( '#' + container ).closest( 'form' ).find( 'input:submit, button' ).prop( 'disabled', true );
119 },
120 200
121 );
122 }
123 }
124
125 function storeEvents( el ) {
126 var target = el,
127 events = $._data( el.get( 0 ), 'events' );
128 /* restoring events */
129 if ( typeof events != 'undefined' ) {
130 var storedEvents = {};
131 $.extend( true, storedEvents, events );
132 target.off();
133 target.data( 'storedEvents', storedEvents );
134 }
135 /* storing and removing onclick action */
136 if ( 'undefined' != typeof target.attr( 'onclick' ) ) {
137 target.attr( 'gglcptch-onclick', target.attr( 'onclick') );
138 target.removeAttr( 'onclick' );
139 }
140 }
141
142 function restoreEvents( el ) {
143 var target = el,
144 events = target.data( 'storedEvents' );
145 /* restoring events */
146 if ( typeof events != 'undefined' ) {
147 for ( var event in events ) {
148 for ( var i = 0; i < events[event].length; i++ ) {
149 target.on( event, events[event][i] );
150 }
151 }
152 }
153 /* reset stored events */
154 target.removeData( 'storedEvents' );
155 /* restoring onclick action */
156 if ( 'undefined' != typeof target.attr( 'gglcptch-onclick' ) ) {
157 target.attr( 'onclick', target.attr( 'gglcptch-onclick' ) );
158 target.removeAttr( 'gglcptch-onclick' );
159 }
160 }
161
162 function storeOnSubmit( form, gglcptch_index ) {
163 form.on( 'submit', function( e ) {
164 if ( '' == form.find( '.g-recaptcha-response' ).val() ) {
165 e.preventDefault();
166 e.stopImmediatePropagation();
167 targetObject = $( e.target || e.srcElement || e.targetObject );
168 targetEvent = e.type;
169 grecaptcha.execute( gglcptch_index );
170 }
171 } ).find( 'input:submit, button' ).on( 'click', function( e ) {
172 if ( '' == form.find( '.g-recaptcha-response' ).val() ) {
173 e.preventDefault();
174 e.stopImmediatePropagation();
175 targetObject = $( e.target || e.srcElement || e.targetObject );
176 targetEvent = e.type;
177 grecaptcha.execute( gglcptch_index );
178 }
179 } );
180 }
181
182 var gglcptch_version = gglcptch.options.version;
183
184 if ( 'v2' == gglcptch_version ) {
185 if ( $( '#' + container ).parent().width() <= 300 && $( '#' + container ).parent().width() != 0 || $( window ).width() < 400 ) {
186 var size = 'compact';
187 } else {
188 var size = 'normal';
189 }
190 var parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'theme' : gglcptch.options.theme, 'size' : size },
191 block = $( '#' + container ),
192 form = block.closest( 'form' );
193
194 /* Callback function works only in frontend */
195 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) {
196 parameters['callback'] = function() {
197 form.find( 'button, input:submit' ).prop( 'disabled', false );
198 };
199 }
200
201 var gglcptch_index = grecaptcha.render( container, parameters );
202 $( '#' + container ).data( 'gglcptch_index', gglcptch_index );
203 } else if ( 'invisible' == gglcptch_version ) {
204 var block = $( '#' + container ),
205 form = block.closest( 'form' ),
206 parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'size' : 'invisible', 'tabindex' : 9999 },
207 targetObject = false,
208 targetEvent = false;
209
210 if ( form.length ) {
211 storeEvents( form );
212 form.find( 'button, input:submit' ).each( function() {
213 storeEvents( $( this ) );
214 } );
215
216 /* Callback function works only in frontend */
217 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) {
218 parameters['callback'] = function( token ) {
219 form.off();
220 restoreEvents( form );
221 form.find( 'button, input:submit' ).off().each( function() {
222 restoreEvents( $( this ) );
223 } );
224 if ( targetObject && targetEvent ) {
225 targetObject.trigger( targetEvent );
226 }
227 form.find( 'button, input:submit' ).each( function() {
228 storeEvents( $( this ) );
229 } );
230 storeEvents( form );
231 storeOnSubmit( form, gglcptch_index );
232 grecaptcha.reset( gglcptch_index );
233 };
234 }
235
236 var gglcptch_index = grecaptcha.render( container, parameters );
237 block.data( { 'gglcptch_index' : gglcptch_index } );
238
239 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) {
240 storeOnSubmit( form, gglcptch_index );
241 }
242 }
243 }
244 };
245
246 $( document ).ready( function() {
247 var tryCounter = 0,
248 /* launching timer so that the function keeps trying to display the reCAPTCHA again and again until google js api is loaded */
249 gglcptch_timer = setInterval( function() {
250 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) {
251 try {
252 gglcptch.prepare();
253 } catch ( e ) {
254 console.log( 'Unexpected error occurred: ', e );
255 }
256 clearInterval( gglcptch_timer );
257 }
258 tryCounter++;
259 /* Stop trying after 10 times */
260 if ( tryCounter >= 10 ) {
261 clearInterval( gglcptch_timer );
262 }
263 }, 1000 );
264
265 function gglcptch_prepare() {
266 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) {
267 try {
268 gglcptch.prepare();
269 } catch ( err ) {
270 console.log( err );
271 }
272 }
273 }
274
275 $( window ).on( 'load', gglcptch_prepare );
276
277 $( '.woocommerce' ).on( 'click', '.woocommerce-tabs', gglcptch_prepare );
278
279 $( '#recaptcha_widget_div' ).on( 'input paste change', '#recaptcha_response_field', cleanError );
280 } );
281
282 function cleanError() {
283 $error = $( this ).parents( '#recaptcha_widget_div' ).next( '#gglcptch_error' );
284 if ( $error.length ) {
285 $error.remove();
286 }
287 }
288
289 function get_id() {
290 var id = 'gglcptch_recaptcha_' + Math.floor( Math.random() * 1000 );
291 if ( $( '#' + id ).length ) {
292 id = get_id();
293 } else {
294 return id;
295 }
296 }
297
298 } )( jQuery, gglcptch );