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