PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.70
reCaptcha by BestWebSoft v1.70
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
292 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 });
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 if ( 'setupform' === $( '#' + container ).closest( 'form' ).attr( 'id' ) ) {
110 setTimeout(
111 function(){
112 $( '#' + container ).closest( 'form' ).find( 'input:submit, button' ).prop( 'disabled', true );
113 },
114 200
115 );
116 }
117 }
118
119 function storeEvents( el ) {
120 var target = el,
121 events = $._data( el.get( 0 ), 'events' );
122 /* restoring events */
123 if ( typeof events != 'undefined' ) {
124 var storedEvents = {};
125 $.extend( true, storedEvents, events );
126 target.off();
127 target.data( 'storedEvents', storedEvents );
128 }
129 /* storing and removing onclick action */
130 if ( 'undefined' != typeof target.attr( 'onclick' ) ) {
131 target.attr( 'gglcptch-onclick', target.attr( 'onclick') );
132 target.removeAttr( 'onclick' );
133 }
134 }
135
136 function restoreEvents( el ) {
137 var target = el,
138 events = target.data( 'storedEvents' );
139 /* restoring events */
140 if ( typeof events != 'undefined' ) {
141 for ( var event in events ) {
142 for ( var i = 0; i < events[event].length; i++ ) {
143 target.on( event, events[event][i] );
144 }
145 }
146 }
147 /* reset stored events */
148 target.removeData( 'storedEvents' );
149 /* restoring onclick action */
150 if ( 'undefined' != typeof target.attr( 'gglcptch-onclick' ) ) {
151 target.attr( 'onclick', target.attr( 'gglcptch-onclick' ) );
152 target.removeAttr( 'gglcptch-onclick' );
153 }
154 }
155
156 function storeOnSubmit( form, gglcptch_index ) {
157 form.on( 'submit', 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 } ).find( 'input:submit, button' ).on( 'click', 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 } );
174 }
175
176 var gglcptch_version = gglcptch.options.version;
177
178 if ( 'v2' == gglcptch_version ) {
179 if ( $( '#' + container ).parent().width() <= 300 && $( '#' + container ).parent().width() != 0 || $( window ).width() < 400 ) {
180 var size = 'compact';
181 } else {
182 var size = 'normal';
183 }
184 var parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'theme' : gglcptch.options.theme, 'size' : size },
185 block = $( '#' + container ),
186 form = block.closest( 'form' );
187
188 /* Callback function works only in frontend */
189 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) {
190 parameters['callback'] = function() {
191 form.find( 'button, input:submit' ).prop( 'disabled', false );
192 };
193 }
194
195 var gglcptch_index = grecaptcha.render( container, parameters );
196 $( '#' + container ).data( 'gglcptch_index', gglcptch_index );
197 } else if ( 'invisible' == gglcptch_version ) {
198 var block = $( '#' + container ),
199 form = block.closest( 'form' ),
200 parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'size' : 'invisible', 'tabindex' : 9999 },
201 targetObject = false,
202 targetEvent = false;
203
204 if ( form.length ) {
205 storeEvents( form );
206 form.find( 'button, input:submit' ).each( function() {
207 storeEvents( $( this ) );
208 } );
209
210 /* Callback function works only in frontend */
211 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) {
212 parameters['callback'] = function( token ) {
213 form.off();
214 restoreEvents( form );
215 form.find( 'button, input:submit' ).off().each( function() {
216 restoreEvents( $( this ) );
217 } );
218 if ( targetObject && targetEvent ) {
219 targetObject.trigger( targetEvent );
220 }
221 form.find( 'button, input:submit' ).each( function() {
222 storeEvents( $( this ) );
223 } );
224 storeEvents( form );
225 storeOnSubmit( form, gglcptch_index );
226 grecaptcha.reset( gglcptch_index );
227 };
228 }
229
230 var gglcptch_index = grecaptcha.render( container, parameters );
231 block.data( { 'gglcptch_index' : gglcptch_index } );
232
233 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) {
234 storeOnSubmit( form, gglcptch_index );
235 }
236 }
237 }
238 };
239
240 $( document ).ready( function() {
241 var tryCounter = 0,
242 /* launching timer so that the function keeps trying to display the reCAPTCHA again and again until google js api is loaded */
243 gglcptch_timer = setInterval( function() {
244 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) {
245 try {
246 gglcptch.prepare();
247 } catch ( e ) {
248 console.log( 'Unexpected error occurred: ', e );
249 }
250 clearInterval( gglcptch_timer );
251 }
252 tryCounter++;
253 /* Stop trying after 10 times */
254 if ( tryCounter >= 10 ) {
255 clearInterval( gglcptch_timer );
256 }
257 }, 1000 );
258
259 function gglcptch_prepare() {
260 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) {
261 try {
262 gglcptch.prepare();
263 } catch ( err ) {
264 console.log( err );
265 }
266 }
267 }
268
269 $( window ).on( 'load', gglcptch_prepare );
270
271 $( '.woocommerce' ).on( 'click', '.woocommerce-tabs', gglcptch_prepare );
272
273 $( '#recaptcha_widget_div' ).on( 'input paste change', '#recaptcha_response_field', cleanError );
274 } );
275
276 function cleanError() {
277 $error = $( this ).parents( '#recaptcha_widget_div' ).next( '#gglcptch_error' );
278 if ( $error.length ) {
279 $error.remove();
280 }
281 }
282
283 function get_id() {
284 var id = 'gglcptch_recaptcha_' + Math.floor( Math.random() * 1000 );
285 if ( $( '#' + id ).length ) {
286 id = get_id();
287 } else {
288 return id;
289 }
290 }
291
292 } )( jQuery, gglcptch );