PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.55
reCaptcha by BestWebSoft v1.55
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 6 years ago pre-api-script.js 6 years ago script.js 6 years ago
script.js
285 lines
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
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( 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, false, 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, v1_add_to_last_element, 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 v1_add_to_last_element = v1_add_to_last_element || false;
170
171 if ( 'v2' == gglcptch_version ) {
172 if ( $( '#' + container ).parent().width() <= 300 && $( '#' + container ).parent().width() != 0 || $( window ).width() < 400 ) {
173 var size = 'compact';
174 } else {
175 var size = 'normal';
176 }
177 var parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'theme' : gglcptch.options.theme, 'size' : size },
178 block = $( '#' + container ),
179 form = block.closest( 'form' );
180
181 /* Callback function works only in frontend */
182 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) {
183 parameters['callback'] = function() {
184 form.find( 'button, input:submit' ).prop( 'disabled', false );
185 };
186 }
187
188 var gglcptch_index = grecaptcha.render( container, parameters );
189 $( '#' + container ).data( 'gglcptch_index', gglcptch_index );
190 } else if ( 'invisible' == gglcptch_version ) {
191 var block = $( '#' + container ),
192 form = block.closest( 'form' ),
193 parameters = params ? params : { 'sitekey' : gglcptch.options.sitekey, 'size' : 'invisible', 'tabindex' : 9999 },
194 targetObject = false,
195 targetEvent = false;
196
197 if ( form.length ) {
198 storeEvents( form );
199 form.find( 'button, input:submit' ).each( function() {
200 storeEvents( $( this ) );
201 } );
202
203 /* Callback function works only in frontend */
204 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) {
205 parameters['callback'] = function( token ) {
206 form.off();
207 restoreEvents( form );
208 form.find( 'button, input:submit' ).off().each( function() {
209 restoreEvents( $( this ) );
210 } );
211 if ( targetObject && targetEvent ) {
212 targetObject.trigger( targetEvent );
213 }
214 form.find( 'button, input:submit' ).each( function() {
215 storeEvents( $( this ) );
216 } );
217 storeEvents( form );
218 storeOnSubmit( form, gglcptch_index );
219 grecaptcha.reset( gglcptch_index );
220 };
221 }
222
223 var gglcptch_index = grecaptcha.render( container, parameters );
224 block.data( { 'gglcptch_index' : gglcptch_index } );
225
226 if ( ! $( 'body' ).hasClass( 'wp-admin' ) ) {
227 storeOnSubmit( form, gglcptch_index );
228 }
229 }
230 }
231 };
232
233 $( document ).ready( function() {
234 var tryCounter = 0,
235 /* launching timer so that the function keeps trying to display the reCAPTCHA again and again until google js api is loaded */
236 gglcptch_timer = setInterval( function() {
237 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) {
238 try {
239 gglcptch.prepare();
240 } catch ( e ) {
241 console.log( 'Unexpected error occurred: ', e );
242 }
243 clearInterval( gglcptch_timer );
244 }
245 tryCounter++;
246 /* Stop trying after 10 times */
247 if ( tryCounter >= 10 ) {
248 clearInterval( gglcptch_timer );
249 }
250 }, 1000 );
251
252 function gglcptch_prepare() {
253 if ( typeof Recaptcha != "undefined" || typeof grecaptcha != "undefined" ) {
254 try {
255 gglcptch.prepare();
256 } catch ( err ) {
257 console.log( err );
258 }
259 }
260 }
261
262 $( window ).on( 'load', gglcptch_prepare );
263
264 $( '.woocommerce' ).on( 'click', '.woocommerce-tabs', gglcptch_prepare );
265
266 $( '#recaptcha_widget_div' ).on( 'input paste change', '#recaptcha_response_field', cleanError );
267 } );
268
269 function cleanError() {
270 $error = $( this ).parents( '#recaptcha_widget_div' ).next( '#gglcptch_error' );
271 if ( $error.length ) {
272 $error.remove();
273 }
274 }
275
276 function get_id() {
277 var id = 'gglcptch_recaptcha_' + Math.floor( Math.random() * 1000 );
278 if ( $( '#' + id ).length ) {
279 id = get_id();
280 } else {
281 return id;
282 }
283 }
284
285 } )( jQuery, gglcptch );