initial
This commit is contained in:
@@ -0,0 +1,316 @@
|
||||
/******/ (function() { // webpackBootstrap
|
||||
/*!****************************!*\
|
||||
!*** ./js/src/frontend.js ***!
|
||||
\****************************/
|
||||
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
||||
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
||||
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
||||
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
||||
/* global gform, gforms_recaptcha_recaptcha_strings, grecaptcha */
|
||||
(function (gform, grecaptcha, strings) {
|
||||
var initScore = function initScore() {
|
||||
var isInitialized = false;
|
||||
document.addEventListener('gform/post_render', function (event) {
|
||||
// Abort if already initialized.
|
||||
if (isInitialized) {
|
||||
return;
|
||||
}
|
||||
isInitialized = true;
|
||||
|
||||
// Executing on AJAX validation.
|
||||
gform.utils.addAsyncFilter('gform/ajax/pre_ajax_validation', /*#__PURE__*/function () {
|
||||
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(data) {
|
||||
return _regenerator().w(function (_context) {
|
||||
while (1) switch (_context.n) {
|
||||
case 0:
|
||||
_context.n = 1;
|
||||
return execute(data.form);
|
||||
case 1:
|
||||
return _context.a(2, data);
|
||||
}
|
||||
}, _callee);
|
||||
}));
|
||||
return function (_x) {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}());
|
||||
|
||||
// Executing recaptcha on form submission or Next button click.
|
||||
gform.utils.addAsyncFilter('gform/submission/pre_submission', /*#__PURE__*/function () {
|
||||
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(data) {
|
||||
var recaptchaRequired;
|
||||
return _regenerator().w(function (_context2) {
|
||||
while (1) switch (_context2.n) {
|
||||
case 0:
|
||||
recaptchaRequired = data.submissionType === gform.submission.SUBMISSION_TYPE_SUBMIT || data.submissionType === gform.submission.SUBMISSION_TYPE_NEXT;
|
||||
if (!(recaptchaRequired && !data.abort)) {
|
||||
_context2.n = 1;
|
||||
break;
|
||||
}
|
||||
_context2.n = 1;
|
||||
return execute(data.form);
|
||||
case 1:
|
||||
return _context2.a(2, data);
|
||||
}
|
||||
}, _callee2);
|
||||
}));
|
||||
return function (_x2) {
|
||||
return _ref2.apply(this, arguments);
|
||||
};
|
||||
}());
|
||||
});
|
||||
maybeDisableBadge();
|
||||
};
|
||||
var initCheckbox = function initCheckbox() {
|
||||
document.addEventListener('gform/post_render', function (event) {
|
||||
renderCheckboxes(event.detail.formId);
|
||||
});
|
||||
document.addEventListener('gfcf/conversational/navigate/next', function (event) {
|
||||
if (!event.detail.target.classList.contains('gfield--type-recaptcha_checkbox')) {
|
||||
return;
|
||||
}
|
||||
var container = event.detail.target.querySelector('.g-recaptcha');
|
||||
renderCheckbox(container);
|
||||
});
|
||||
gform.addAction('gform_post_conditional_logic_field_action', function (formId, action, targetId, defaultValues, isInit) {
|
||||
if (action !== 'show') {
|
||||
return;
|
||||
}
|
||||
var field = gform.utils.getNode(targetId, document, true);
|
||||
if (!field || !field.classList.contains('gfield--type-recaptcha_checkbox')) {
|
||||
return;
|
||||
}
|
||||
var container = field.querySelector('.g-recaptcha');
|
||||
renderCheckbox(container, isInit);
|
||||
});
|
||||
gform.utils.addAsyncFilter('gform/ajax/post_ajax_submission', function (data) {
|
||||
var _data$submissionResul;
|
||||
if (!((_data$submissionResul = data.submissionResult) !== null && _data$submissionResul !== void 0 && (_data$submissionResul = _data$submissionResul.data) !== null && _data$submissionResul !== void 0 && _data$submissionResul.recaptcha_checkbox_response)) {
|
||||
return data;
|
||||
}
|
||||
var input = gform.utils.getNode('input.gfield_recaptcha_response', data.form, true);
|
||||
if (input) {
|
||||
input.value = data.submissionResult.data.recaptcha_checkbox_response;
|
||||
}
|
||||
return data;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @function execute
|
||||
* @description Execute standard or enterprise reCAPTCHA depending on the connection type.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @param {HTMLFormElement} form The form element.
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
var execute = /*#__PURE__*/function () {
|
||||
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(form) {
|
||||
return _regenerator().w(function (_context3) {
|
||||
while (1) switch (_context3.n) {
|
||||
case 0:
|
||||
if (form) {
|
||||
_context3.n = 1;
|
||||
break;
|
||||
}
|
||||
return _context3.a(2);
|
||||
case 1:
|
||||
if (!((strings === null || strings === void 0 ? void 0 : strings.key_type) === 'CHECKBOX')) {
|
||||
_context3.n = 2;
|
||||
break;
|
||||
}
|
||||
return _context3.a(2);
|
||||
case 2:
|
||||
if (!(strings.connection_type === 'enterprise')) {
|
||||
_context3.n = 4;
|
||||
break;
|
||||
}
|
||||
_context3.n = 3;
|
||||
return executeEnterpriseRecaptcha(form);
|
||||
case 3:
|
||||
_context3.n = 5;
|
||||
break;
|
||||
case 4:
|
||||
_context3.n = 5;
|
||||
return executeRecaptcha(form);
|
||||
case 5:
|
||||
return _context3.a(2);
|
||||
}
|
||||
}, _callee3);
|
||||
}));
|
||||
return function execute(_x3) {
|
||||
return _ref3.apply(this, arguments);
|
||||
};
|
||||
}();
|
||||
|
||||
/**
|
||||
* @function executeRecaptcha
|
||||
* @description Execute standard reCAPTCHA, setting the token to the hidden input field.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @param {HTMLFormElement} form The form element.
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
var executeRecaptcha = /*#__PURE__*/function () {
|
||||
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(form) {
|
||||
var dataInput, token;
|
||||
return _regenerator().w(function (_context4) {
|
||||
while (1) switch (_context4.n) {
|
||||
case 0:
|
||||
dataInput = form.querySelector('.ginput_recaptchav3 .gfield_recaptcha_response'); // If reCAPTCHA fields can't be found, or recaptcha response is already set, don't execute reCAPTCHA.
|
||||
if (!(!dataInput || dataInput.value.length)) {
|
||||
_context4.n = 1;
|
||||
break;
|
||||
}
|
||||
return _context4.a(2);
|
||||
case 1:
|
||||
_context4.n = 2;
|
||||
return grecaptcha.execute(strings.site_key, {
|
||||
action: 'submit'
|
||||
});
|
||||
case 2:
|
||||
token = _context4.v;
|
||||
if (token.length && typeof token === 'string') {
|
||||
dataInput.value = token;
|
||||
}
|
||||
case 3:
|
||||
return _context4.a(2);
|
||||
}
|
||||
}, _callee4);
|
||||
}));
|
||||
return function executeRecaptcha(_x4) {
|
||||
return _ref4.apply(this, arguments);
|
||||
};
|
||||
}();
|
||||
|
||||
/**
|
||||
* @function executeEnterpriseRecaptcha
|
||||
* @description Execute enterprise reCAPTCHA, setting the token to the hidden input field.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @param {HTMLFormElement} form The form element.
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
var executeEnterpriseRecaptcha = /*#__PURE__*/function () {
|
||||
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(form) {
|
||||
var dataInput, token, _t;
|
||||
return _regenerator().w(function (_context5) {
|
||||
while (1) switch (_context5.p = _context5.n) {
|
||||
case 0:
|
||||
dataInput = form.querySelector('.ginput_recaptchav3 .gfield_recaptcha_response'); // If reCAPTCHA fields can't be found, or recaptcha response is already set, don't execute reCAPTCHA.
|
||||
if (!(!dataInput || dataInput.value.length)) {
|
||||
_context5.n = 1;
|
||||
break;
|
||||
}
|
||||
return _context5.a(2);
|
||||
case 1:
|
||||
_context5.p = 1;
|
||||
_context5.n = 2;
|
||||
return grecaptcha.enterprise.execute(strings.site_key, {
|
||||
action: 'submit'
|
||||
});
|
||||
case 2:
|
||||
token = _context5.v;
|
||||
if (token.length && typeof token === 'string') {
|
||||
dataInput.value = token;
|
||||
}
|
||||
_context5.n = 4;
|
||||
break;
|
||||
case 3:
|
||||
_context5.p = 3;
|
||||
_t = _context5.v;
|
||||
return _context5.a(2);
|
||||
case 4:
|
||||
return _context5.a(2);
|
||||
}
|
||||
}, _callee5, null, [[1, 3]]);
|
||||
}));
|
||||
return function executeEnterpriseRecaptcha(_x5) {
|
||||
return _ref5.apply(this, arguments);
|
||||
};
|
||||
}();
|
||||
maybeDisableBadge = function maybeDisableBadge() {
|
||||
if (strings.connection_type === 'enterprise') {
|
||||
grecaptcha.enterprise.ready(function () {
|
||||
hideBadge();
|
||||
});
|
||||
} else {
|
||||
grecaptcha.ready(function () {
|
||||
hideBadge();
|
||||
});
|
||||
}
|
||||
};
|
||||
hideBadge = function hideBadge() {
|
||||
if (strings.disable_badge) {
|
||||
var badge = document.querySelector('.grecaptcha-badge');
|
||||
if (badge) {
|
||||
badge.style.visibility = 'hidden';
|
||||
}
|
||||
}
|
||||
};
|
||||
var renderCheckboxes = function renderCheckboxes() {
|
||||
var formId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
||||
var prefix = formId ? "#gform_".concat(formId) : '.gform_wrapper';
|
||||
var containers = document.querySelectorAll("".concat(prefix, " .ginput_container_recaptcha_checkbox .g-recaptcha"));
|
||||
if (!containers) {
|
||||
return;
|
||||
}
|
||||
containers.forEach(renderCheckbox);
|
||||
};
|
||||
var renderCheckbox = function renderCheckbox(container) {
|
||||
var _grecaptcha$enterpris;
|
||||
var isLogicInit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||
if (!(grecaptcha !== null && grecaptcha !== void 0 && (_grecaptcha$enterpris = grecaptcha.enterprise) !== null && _grecaptcha$enterpris !== void 0 && _grecaptcha$enterpris.render) || !container || container.dataset.initialized === 'true' || container.dataset.widgetid || !isLogicInit && isContainerHiddenByParent(container)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the iframe is present on the container, something else has already rendered it.
|
||||
if (container.querySelector('iframe')) {
|
||||
container.dataset.initialized = 'true';
|
||||
return;
|
||||
}
|
||||
var widgetId = grecaptcha.enterprise.render(container);
|
||||
if (!Number.isInteger(widgetId)) {
|
||||
return;
|
||||
}
|
||||
container.dataset.initialized = 'true';
|
||||
container.dataset.widgetid = widgetId;
|
||||
};
|
||||
var isContainerHiddenByParent = function isContainerHiddenByParent(container) {
|
||||
// Walk up the DOM from the container to the document root.
|
||||
var node = container.parentElement;
|
||||
while (node) {
|
||||
try {
|
||||
var style = getComputedStyle(node);
|
||||
if ((style === null || style === void 0 ? void 0 : style.display) === 'none') {
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
// Some environments may throw for detached nodes; ignore and continue.
|
||||
}
|
||||
node = node.parentElement;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
window.gform = gform;
|
||||
window.gform.recaptchaV3 = {
|
||||
execute: execute
|
||||
};
|
||||
|
||||
// Google requires a simple global function name for the onload callback. It looks like they call using array syntax: i.e. window['gravityformsrecaptchaRenderCheckboxes']();
|
||||
window.gravityformsrecaptchaRenderCheckboxes = renderCheckboxes;
|
||||
if ((strings === null || strings === void 0 ? void 0 : strings.key_type) === 'CHECKBOX') {
|
||||
initCheckbox();
|
||||
} else {
|
||||
initScore();
|
||||
}
|
||||
})(window.gform || {}, window.grecaptcha || {}, gforms_recaptcha_recaptcha_strings);
|
||||
/******/ })()
|
||||
;
|
||||
//# sourceMappingURL=frontend.js.map
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
||||
@@ -0,0 +1,588 @@
|
||||
/******/ (function() { // webpackBootstrap
|
||||
/*!***********************************!*\
|
||||
!*** ./js/src/plugin_settings.js ***!
|
||||
\***********************************/
|
||||
/* global jQuery, gform, grecaptcha, gforms_recaptcha_recaptcha_strings */
|
||||
|
||||
(function ($) {
|
||||
/**
|
||||
* Handles reCAPTCHA v2 plugin settings validation.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
var recaptchaV2Settings = function recaptchaV2Settings() {
|
||||
var v2Settings = {};
|
||||
|
||||
/**
|
||||
* Initialize reCAPTCHA v2 settings.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v2Settings.init = function () {
|
||||
v2Settings.cacheElements();
|
||||
v2Settings.addEventListeners();
|
||||
};
|
||||
|
||||
/**
|
||||
* Cache the fields used by this handler.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v2Settings.cacheElements = function () {
|
||||
v2Settings.container = $('div[id="gform_setting_reset_v2"]');
|
||||
v2Settings.fields = {
|
||||
siteKey: $('input[name="_gform_setting_site_key_v2"]'),
|
||||
secretKey: $('input[name="_gform_setting_secret_key_v2"]'),
|
||||
reset: $('input[name="_gform_setting_reset_v2"]'),
|
||||
type: $('input[name="_gform_setting_type_v2"]')
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Add event listeners for this handler.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v2Settings.addEventListeners = function () {
|
||||
v2Settings.fields.siteKey.on('change', window.loadRecaptcha);
|
||||
v2Settings.fields.secretKey.on('change', window.loadRecaptcha);
|
||||
v2Settings.fields.type.on('change', function () {
|
||||
return window.loadRecaptcha();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles showing and hiding the reCAPTCHA itself.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
window.loadRecaptcha = function () {
|
||||
var self = {};
|
||||
|
||||
/**
|
||||
* Initialize the reCAPTCHA rendering process.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
self.init = function () {
|
||||
v2Settings.recaptcha = $('#recaptcha');
|
||||
v2Settings.save = $('#gform-settings-save');
|
||||
self.flushExistingState();
|
||||
|
||||
// Reset key status.
|
||||
// Note: recaptcha is misspelled here for legacy reasons.
|
||||
$('#recpatcha .gform-settings-field__feedback').remove();
|
||||
|
||||
// If no public or private key is provided, exit.
|
||||
if (!self.canBeDisplayed()) {
|
||||
self.hideRecaptcha();
|
||||
return;
|
||||
}
|
||||
self.showSelectedRecaptcha();
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders the v2 reCAPTCHA.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param {string} typeValue The selected type to render.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
self.render = function (typeValue) {
|
||||
// Render reCAPTCHA.
|
||||
grecaptcha.render('recaptcha', {
|
||||
sitekey: v2Settings.fields.siteKey.val().trim(),
|
||||
size: typeValue === 'invisible' ? typeValue : '',
|
||||
badge: 'inline',
|
||||
'error-callback': function errorCallback() {},
|
||||
callback: function callback() {
|
||||
return v2Settings.save.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Flush the existing state of the reCAPTCHA handler.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
self.flushExistingState = function () {
|
||||
window.___grecaptcha_cfg.clients = {};
|
||||
window.___grecaptcha_cfg.count = 0;
|
||||
v2Settings.recaptcha.html('');
|
||||
v2Settings.fields.reset.val('1');
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether the reCAPTCHA can be shown.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {boolean} Whether the reCAPTCHA can be shown.
|
||||
*/
|
||||
self.canBeDisplayed = function () {
|
||||
return v2Settings.fields.siteKey.val() && v2Settings.fields.secretKey.val();
|
||||
};
|
||||
|
||||
/**
|
||||
* Hides the reCAPTCHA element.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
self.hideRecaptcha = function () {
|
||||
v2Settings.save.prop('disabled', false);
|
||||
v2Settings.container.hide();
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the selected reCAPTCHA type.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
self.showSelectedRecaptcha = function () {
|
||||
var typeValue = $('input[name="_gform_setting_type_v2"]:checked').val();
|
||||
if (!typeValue) {
|
||||
return;
|
||||
}
|
||||
self.render(typeValue);
|
||||
switch (typeValue) {
|
||||
case 'checkbox':
|
||||
$('#gforms_checkbox_recaptcha_message, label[for="reset"]').show();
|
||||
break;
|
||||
case 'invisible':
|
||||
$('#gforms_checkbox_recaptcha_message, label[for="reset"]').hide();
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unexpected type selected.');
|
||||
}
|
||||
v2Settings.container.show();
|
||||
if (typeValue === 'invisible') {
|
||||
grecaptcha.execute();
|
||||
}
|
||||
};
|
||||
self.init();
|
||||
};
|
||||
v2Settings.init();
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles reCAPTCHA v3 plugin settings validation.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
var recaptchaV3Settings = function recaptchaV3Settings() {
|
||||
var v3Settings = {};
|
||||
|
||||
/**
|
||||
* Initializes the reCAPTCHA v3 settings handler.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v3Settings.init = function () {
|
||||
v3Settings.token = '';
|
||||
v3Settings.strings = gforms_recaptcha_recaptcha_strings;
|
||||
v3Settings.cacheElements();
|
||||
v3Settings.validateKeysV3();
|
||||
v3Settings.addEventListeners();
|
||||
};
|
||||
|
||||
/**
|
||||
* Cache HTML elements for the v3 reCAPTCHA settings.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v3Settings.cacheElements = function () {
|
||||
v3Settings.fields = {
|
||||
siteKey: '#site_key_v3',
|
||||
secretKey: '#secret_key_v3',
|
||||
threshold: '#score_threshold_v3',
|
||||
disableBadge: '#disable_badge_v3',
|
||||
keysStatus: '#gform_setting_recaptcha_keys_status_v3'
|
||||
};
|
||||
v3Settings.cache = {
|
||||
siteKey: $(v3Settings.fields.siteKey),
|
||||
secretKey: $(v3Settings.fields.secretKey),
|
||||
keysStatus: $(v3Settings.fields.keysStatus),
|
||||
save: $('#gform-settings-save')
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Setup event listeners for field validation.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v3Settings.addEventListeners = function () {
|
||||
if (!v3Settings.strings.site_key.length) {
|
||||
return;
|
||||
}
|
||||
$(v3Settings.fields.siteKey).on('keyup', function () {
|
||||
return v3Settings.clearValidationFeedback();
|
||||
});
|
||||
$(v3Settings.fields.secretKey).on('keyup', function () {
|
||||
return v3Settings.clearValidationFeedback();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Empty out the validation feedback if the fields are modified, as we can't yet know the status.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v3Settings.clearValidationFeedback = function () {
|
||||
v3Settings.unsetValid(v3Settings.cache.siteKey.closest('.gform-settings-input__container'));
|
||||
v3Settings.unsetValid(v3Settings.cache.secretKey.closest('.gform-settings-input__container'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles validation of the v3 site key.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {Promise<unknown>} Returns a promise so this can be verified synchronously if checking the secret key.
|
||||
*/
|
||||
v3Settings.getRecaptchaToken = function () {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var siteKeyContainer = v3Settings.cache.siteKey.closest('.gform-settings-input__container');
|
||||
try {
|
||||
var siteKey = v3Settings.cache.siteKey;
|
||||
var siteKeyValue = siteKey.val().trim();
|
||||
if (0 === siteKeyValue.length) {
|
||||
v3Settings.unsetValid(siteKeyContainer);
|
||||
v3Settings.unsetValid(v3Settings.cache.keysStatus.closest('.gform-settings-input__container'));
|
||||
$(v3Settings.fields.keysStatus).find('input').val('0');
|
||||
return;
|
||||
}
|
||||
grecaptcha.ready(function () {
|
||||
try {
|
||||
grecaptcha.execute(siteKeyValue, {
|
||||
action: 'submit'
|
||||
}).then(function (token) {
|
||||
resolve(token);
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles validation of the v3 site and secret keys.
|
||||
*
|
||||
* On page load, attempt to generate a reCAPTCHA token and immediately validate it on the server. If it's good,
|
||||
* we'll update the presentation of the keys to indicate success or failure.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v3Settings.validateKeysV3 = function () {
|
||||
var siteKeyContainer = v3Settings.cache.siteKey.closest('.gform-settings-input__container');
|
||||
var secretKeyContainer = v3Settings.cache.secretKey.closest('.gform-settings-input__container');
|
||||
var keysStatusInput = $(v3Settings.fields.keysStatus).find('input');
|
||||
if (!$(v3Settings.fields.siteKey).val().trim().length) {
|
||||
v3Settings.unsetValid(siteKeyContainer);
|
||||
v3Settings.unsetValid(secretKeyContainer);
|
||||
keysStatusInput.val('0');
|
||||
return;
|
||||
}
|
||||
v3Settings.getRecaptchaToken().then(function (token) {
|
||||
v3Settings.token = token;
|
||||
}).catch(function () {
|
||||
v3Settings.setInvalid(siteKeyContainer);
|
||||
v3Settings.setInvalid(secretKeyContainer);
|
||||
keysStatusInput.val('0');
|
||||
}).finally(function () {
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'JSON',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'verify_secret_key',
|
||||
nonce: v3Settings.strings.nonce,
|
||||
token: v3Settings.token,
|
||||
site_key_v3: $(v3Settings.fields.siteKey).val(),
|
||||
secret_key_v3: $(v3Settings.fields.secretKey).val()
|
||||
}
|
||||
}).then(function (response) {
|
||||
switch (response.data.keys_status) {
|
||||
case '1':
|
||||
v3Settings.setValid(siteKeyContainer);
|
||||
v3Settings.setValid(secretKeyContainer);
|
||||
keysStatusInput.val('1');
|
||||
break;
|
||||
case '0':
|
||||
v3Settings.setInvalid(siteKeyContainer);
|
||||
v3Settings.setInvalid(secretKeyContainer);
|
||||
keysStatusInput.val('0');
|
||||
break;
|
||||
default:
|
||||
v3Settings.unsetValid(siteKeyContainer);
|
||||
v3Settings.unsetValid(secretKeyContainer);
|
||||
keysStatusInput.val('0');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the text field to display no feedback.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param {Object} el The jQuery element.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v3Settings.unsetValid = function (el) {
|
||||
el.removeClass('gform-settings-input__container--feedback-success');
|
||||
el.removeClass('gform-settings-input__container--feedback-error');
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the text field to display the successful feedback.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param {Object} el The jQuery element.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v3Settings.setValid = function (el) {
|
||||
el.addClass('gform-settings-input__container--feedback-success');
|
||||
el.removeClass('gform-settings-input__container--feedback-error');
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the text field to display the error feedback.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param {Object} el The jQuery element.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
v3Settings.setInvalid = function (el) {
|
||||
el.removeClass('gform-settings-input__container--feedback-success');
|
||||
el.addClass('gform-settings-input__container--feedback-error');
|
||||
};
|
||||
v3Settings.init();
|
||||
};
|
||||
$(document).ready(function () {
|
||||
var $form = $('#gform-settings');
|
||||
var $action = $form.find('input[name="gf_recaptcha_action"]');
|
||||
if ('gf_recaptcha_v3_classic' === $action.val()) {
|
||||
recaptchaV3Settings();
|
||||
} else if ('gf_recaptcha_v2' === $action.val()) {
|
||||
recaptchaV2Settings();
|
||||
}
|
||||
if (gforms_recaptcha_recaptcha_strings.disable_badge) {
|
||||
var badge = document.querySelector('.grecaptcha-badge');
|
||||
if (badge) {
|
||||
badge.style.visibility = 'hidden';
|
||||
}
|
||||
}
|
||||
|
||||
// Handle disconnects from the admin.
|
||||
var $disconnect = $('.gfrecaptcha-disconnect');
|
||||
if ($disconnect.length > 0) {
|
||||
$disconnect.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// check if we have any saved settings that are going to be deleted
|
||||
var $site_key_v3 = $('#site_key_v3');
|
||||
var $site_key_v2 = $('#site_key_v2');
|
||||
var hasSavedSettings = false;
|
||||
if ($site_key_v3.length > 0 && $site_key_v3.val() !== '') {
|
||||
hasSavedSettings = true;
|
||||
}
|
||||
if ($site_key_v2.length > 0 && $site_key_v2.val() !== '') {
|
||||
hasSavedSettings = true;
|
||||
}
|
||||
|
||||
// Confirm deleting settings if you change connection type or disconnect
|
||||
if (hasSavedSettings || $disconnect.hasClass('gfrecaptcha-disconnect')) {
|
||||
if ($disconnect.hasClass('gfrecaptcha-disconnect')) {
|
||||
var title = gforms_recaptcha_recaptcha_strings.disconnect_title;
|
||||
var message = gforms_recaptcha_recaptcha_strings.disconnect_message;
|
||||
} else {
|
||||
var title = gforms_recaptcha_recaptcha_strings.change_connection_type_title;
|
||||
var message = gforms_recaptcha_recaptcha_strings.change_connection_type_message;
|
||||
}
|
||||
if (typeof gform.instances.dialogConfirmAsync !== 'function') {
|
||||
if (!confirm(message)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
gform.instances.dialogConfirmAsync(title, message).then(function (userConfirmed) {
|
||||
if (!userConfirmed) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if ($disconnect.hasClass('gfrecaptcha-changetype')) {
|
||||
$disconnect.html(gforms_recaptcha_recaptcha_strings.change_connection_type);
|
||||
} else {
|
||||
$disconnect.html(gforms_recaptcha_recaptcha_strings.disconnect);
|
||||
}
|
||||
var url_params = wpAjax.unserialize(e.target.href);
|
||||
var nonce_value = url_params.nonce;
|
||||
|
||||
// Perform Ajax request.
|
||||
$.post(ajaxurl, {
|
||||
action: 'disconnect_recaptcha',
|
||||
nonce: nonce_value
|
||||
}, function (response) {
|
||||
window.location.href = window.location.href;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Handle form submission on connect screen.
|
||||
$form.on('submit', function (e) {
|
||||
// Determining if we're just connecting for the first time.
|
||||
if ($form.find('input[value="recaptcha_setup"]').length === 1) {
|
||||
// is_postback
|
||||
e.preventDefault();
|
||||
|
||||
// Set l18n.
|
||||
var $save_button = $form.find('#gform-settings-save');
|
||||
var $connection_type = $form.find('[name="_gform_setting_connection_type"]:checked').val();
|
||||
|
||||
// Get nonce.
|
||||
var nonce_value = $form.find('input[name="recaptcha_nonce"]').val();
|
||||
if ($connection_type === 'enterprise') {
|
||||
// Perform Ajax request.
|
||||
$.post(ajaxurl, {
|
||||
action: 'perform_enterprise_oauth',
|
||||
nonce: nonce_value,
|
||||
mode: $connection_type
|
||||
}, function (response) {
|
||||
if (!response.data.errors) {
|
||||
window.location.href = response.data.redirect;
|
||||
}
|
||||
}, 'json');
|
||||
} else {
|
||||
// Perform Ajax request.
|
||||
$.post(ajaxurl, {
|
||||
action: 'update_reload_settings',
|
||||
nonce: nonce_value,
|
||||
connection_type: $connection_type
|
||||
}, function (response) {
|
||||
if (!response.data.errors) {
|
||||
var url = new URL(response.data.redirect);
|
||||
url.searchParams.set('connection_type', $connection_type);
|
||||
window.location.href = url;
|
||||
}
|
||||
}, 'json');
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ('gf_recaptcha_enterprise' === $action.val()) {
|
||||
e.preventDefault();
|
||||
|
||||
// Getting selected items from the account/property and data stream drop downs.
|
||||
var $selected_project = $form.find('select[name="recaptcha_project"]').find(':selected');
|
||||
var $selected_site_key = $form.find('#recaptcha-site-keys :selected');
|
||||
$.post(ajaxurl, {
|
||||
action: 'save_recaptcha_enterprise_data',
|
||||
project_number: $selected_project.val(),
|
||||
project_id: $selected_project.data('project-id'),
|
||||
project_name: $selected_project.data('project-name'),
|
||||
site_key_v3_enterprise: $selected_site_key.val(),
|
||||
site_key_type_v3_enterprise: $selected_site_key.data('site-key-type'),
|
||||
site_key_display_name: $selected_site_key.data('site-key-display-name'),
|
||||
score_threshold_v3: $form.find('#score_threshold_v3').val(),
|
||||
disable_badge_v3: $form.find('input[name="_gform_setting_disable_badge_v3"]').val(),
|
||||
nonce: $form.find('input[name="recaptcha_nonce"]').val()
|
||||
}, function (response) {
|
||||
if (response.success) {
|
||||
window.location.href = response['data'];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Get keys available to the selected project.
|
||||
$('#recaptcha_project').on('change', function (e) {
|
||||
var $option = $(this).find(':selected');
|
||||
var nonce = $('body').find('input[name="recaptcha_nonce"]').val();
|
||||
$('#recaptcha-site-keys').html('<br /><img src="' + gforms_recaptcha_recaptcha_strings.spinner + '" />');
|
||||
$.post(ajaxurl, {
|
||||
action: 'get_enterprise_site_keys',
|
||||
project: $option.val(),
|
||||
nonce: nonce
|
||||
}, function (response) {
|
||||
if (response.success) {
|
||||
var siteKeys = response['data'];
|
||||
var select = document.createElement('select');
|
||||
select.name = 'recaptcha-site-keys';
|
||||
var label = document.createElement('label');
|
||||
label.textContent = 'Enterprise Site Key';
|
||||
label.setAttribute('for', 'recaptcha-site-keys');
|
||||
label.classList.add('gform-settings-label');
|
||||
var header = document.createElement('div');
|
||||
header.classList.add('gform-settings-field__header');
|
||||
header.appendChild(label);
|
||||
var defaultOption = document.createElement('option');
|
||||
defaultOption.value = '';
|
||||
defaultOption.textContent = 'Select a site key';
|
||||
select.appendChild(defaultOption);
|
||||
siteKeys.forEach(function (key) {
|
||||
var option = document.createElement('option');
|
||||
option.value = key.value;
|
||||
option.textContent = key.displayName;
|
||||
option.setAttribute('data-site-key-display-name', key.displayName);
|
||||
option.setAttribute('data-site-key-type', key.type);
|
||||
select.appendChild(option);
|
||||
});
|
||||
var container = document.querySelector('#recaptcha-site-keys');
|
||||
container.innerHTML = '';
|
||||
container.appendChild(header);
|
||||
container.appendChild(select);
|
||||
} else {
|
||||
$('#recaptcha-site-keys').html('');
|
||||
}
|
||||
});
|
||||
});
|
||||
gform.adminUtils.handleUnsavedChanges('#gform-settings');
|
||||
});
|
||||
})(jQuery);
|
||||
/******/ })()
|
||||
;
|
||||
//# sourceMappingURL=plugin_settings.js.map
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user