-
Notifications
You must be signed in to change notification settings - Fork 16
/
recaptcha.ajax.js
49 lines (39 loc) · 1.1 KB
/
recaptcha.ajax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* This file is part of the ReCaptchaControl package
*
* @license MIT
* @author Petr Kessler (https://kesspess.cz)
* @link https://github.com/uestla/ReCaptchaControl
*/
;(function (window, $) {
if (!$ || typeof $.nette === 'undefined') {
console.error('nette.ajax.js library is required, please load it.');
}
// renders all recaptcha elements on page
var renderAll = function () {
$('.g-recaptcha').each(function () {
var el = $(this);
if (el.children().length) { // already rendered -> skip
return ;
}
grecaptcha.render(this, {}, true);
});
};
// set global onload callback (used in library loading below)
var callbackName = 'g_onRecaptchaLoad';
window[callbackName] = function () {
renderAll();
$.nette.ext('recaptcha', {
load: function () {
renderAll();
}
});
};
// load official library with explicit rendering
$('<script />', {
src: 'https://www.google.com/recaptcha/api.js'
+ '?onload=' + callbackName
+ '&render=explicit'
+ '&hl=' + ($('html').attr('lang') || 'en')
}).insertBefore('script:first');
})(window, window.jQuery || false);