philomena/assets/js/captcha.js

21 lines
647 B
JavaScript
Raw Permalink Normal View History

2020-09-12 19:43:16 +02:00
import { delegate, leftClick } from './utils/events';
import { clearEl, makeEl } from './utils/dom';
2019-10-05 02:09:52 +02:00
2020-09-12 19:43:16 +02:00
function insertCaptcha(_event, target) {
const { parentNode, dataset: { sitekey } } = target;
2019-10-05 02:09:52 +02:00
2020-09-12 19:43:16 +02:00
const script = makeEl('script', {src: 'https://hcaptcha.com/1/api.js', async: true, defer: true});
const frame = makeEl('div', {className: 'h-captcha'});
frame.dataset.sitekey = sitekey;
2019-10-05 02:09:52 +02:00
2020-09-12 19:43:16 +02:00
clearEl(parentNode);
parentNode.insertAdjacentElement('beforeend', frame);
parentNode.insertAdjacentElement('beforeend', script);
2019-10-05 02:09:52 +02:00
}
2020-09-12 19:43:16 +02:00
export function bindCaptchaLinks() {
delegate(document, 'click', {'.js-captcha': leftClick(insertCaptcha)});
}