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