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