PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.14.1
Yatra – Travel Booking & Tour Operator Software v3.0.14.1
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / assets / js / recaptcha.js

recaptcha.js in Yatra – Travel Booking & Tour Operator Software 3.0.14.1, at assets/js/recaptcha.js

56 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Yatra reCAPTCHA v3 helper.
3 *
4 * Exposes window.yatraRecaptcha.execute(action) -> Promise<token> and
5 * window.yatraRecaptcha.protects(form) -> bool. Form submit handlers call
6 * execute() right before sending, then include the token as `recaptcha_token`.
7 *
8 * The config object (siteKey, enabled, forms) is injected by
9 * wp_localize_script before this file runs; we augment it with methods.
10 *
11 * @package Yatra
12 */
13 (function () {
14 var cfg = (window.yatraRecaptcha = window.yatraRecaptcha || {});
15
16 /**
17 * Get a fresh v3 token for the given action. Resolves to '' (never rejects)
18 * if reCAPTCHA is unavailable, so a script/network failure can be handled by
19 * the caller / server rather than throwing in the submit path.
20 *
21 * @param {string} action
22 * @returns {Promise<string>}
23 */
24 cfg.execute = function (action) {
25 return new Promise(function (resolve) {
26 try {
27 if (!cfg.enabled || !cfg.siteKey || typeof grecaptcha === 'undefined') {
28 resolve('');
29 return;
30 }
31 grecaptcha.ready(function () {
32 grecaptcha
33 .execute(cfg.siteKey, { action: action || 'submit' })
34 .then(function (token) {
35 resolve(token || '');
36 })
37 .catch(function () {
38 resolve('');
39 });
40 });
41 } catch (e) {
42 resolve('');
43 }
44 });
45 };
46
47 /**
48 * Whether a given form is configured to be protected.
49 * @param {string} form
50 * @returns {boolean}
51 */
52 cfg.protects = function (form) {
53 return !!(cfg.enabled && cfg.forms && cfg.forms[form]);
54 };
55 })();
56