Conditions | 1 |
Paths | 1 |
Total Lines | 41 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /** global: grecaptcha */ |
||
3 | (function (window, document) { |
||
4 | 'use strict'; |
||
5 | |||
6 | function reCaptchaInit() { |
||
7 | var element = document.createElement('script'), |
||
8 | target = document.querySelectorAll('script')[0], |
||
9 | protocol = 'https:' == document.location.protocol ? 'https' : 'http'; |
||
10 | element.type = 'text/javascript'; |
||
11 | element.src = protocol + '://www.google.com/recaptcha/api.js?onload=reCaptchaOnloadCallback&render=explicit&hl='.concat(window.SS_LOCALE); |
||
12 | target.parentNode.insertBefore(element, target); |
||
13 | } |
||
14 | |||
15 | function reCaptchaOnloadCallback() { |
||
16 | var reCaptcha = document.querySelector('.g-recaptcha'); |
||
17 | |||
18 | if (reCaptcha.dataset.size === 'invisible') { |
||
19 | reCaptchaForm().addEventListener('submit', reCaptchaFormOnSubmit); |
||
20 | } |
||
21 | |||
22 | grecaptcha.render(reCaptcha, reCaptcha.dataset); |
||
23 | } |
||
24 | |||
25 | function reCaptchaOnSubmit(token) { |
||
26 | document.querySelector('#'.concat(window.ReCaptchaFormId, ' .g-recaptcha-response')).value = token; |
||
27 | reCaptchaForm().submit(); |
||
28 | } |
||
29 | |||
30 | function reCaptchaForm() { |
||
31 | return document.querySelector('#'.concat(window.ReCaptchaFormId)); |
||
32 | } |
||
33 | |||
34 | function reCaptchaFormOnSubmit(event) { |
||
35 | event.preventDefault(); |
||
36 | grecaptcha.execute(); |
||
37 | } |
||
38 | |||
39 | domReady(reCaptchaInit); |
||
40 | |||
41 | window.reCaptchaOnloadCallback = reCaptchaOnloadCallback; |
||
42 | window.reCaptchaOnSubmit = reCaptchaOnSubmit; |
||
43 | })(window, document); |
||
44 | |||
45 |