1/** 2 * __PrimeFaces Captcha Widget__ 3 * 4 * Captcha is a form validation component based on Recaptcha API V2. 5 * 6 * @typedef {"auto" | "light" | "dark"} PrimeFaces.widget.Captcha.Theme Captcha features light and dark modes for theme. 7 * 8 * @interface {PrimeFaces.widget.CaptchaCfg} cfg The configuration for the {@link Captcha| Captcha widget}. 9 * You can access this configuration via {@link PrimeFaces.widget.BaseWidget.cfg|BaseWidget.cfg}. Please note that this 10 * configuration is usually meant to be read-only and should not be modified. 11 * @extends {PrimeFaces.widget.BaseWidgetCfg} cfg 12 * 13 * @prop {string} cfg.callback Name of a function in the global scope. Callback to be executed when the user submits a 14 * successful CAPTCHA response. The user's response, goggle recaptcha-response, will be the input for your callback 15 * function. 16 * @prop {string} cfg.expired Name of a function in the global scope. The callback executed when the captcha response 17 * expires and the user needs to solve a new captcha. 18 * @prop {string} cfg.language Language in which information about this captcha is shown. 19 * @prop {string} cfg.sitekey Public recaptcha key for a specific domain (deprecated). 20 * @prop {string} cfg.size Size of the recaptcha. 21 * @prop {number} cfg.tabindex Position of the input element in the tabbing order. 22 * @prop {PrimeFaces.widget.Captcha.Theme} cfg.theme Theme of the captcha. 23 */ 24PrimeFaces.widget.Captcha = PrimeFaces.widget.BaseWidget.extend({ 25 26 /** 27 * @override 28 * @inheritdoc 29 * @param {TCfg} cfg 30 */ 31 init: function(cfg) { 32 this._super(cfg); 33 this.cfg.language = this.cfg.language||'en'; 34 this.cfg.theme = this.cfg.theme || PrimeFaces.env.getThemeContrast(); 35 36 var $this = this; 37 38 window[this.getInitCallbackName()] = function() { 39 $this.render(); 40 }; 41 42 var nonce = ''; 43 if (PrimeFaces.csp.NONCE_VALUE) { 44 nonce = 'nonce="'+PrimeFaces.csp.NONCE_VALUE+'"'; 45 } 46 47 $(document.body).append('<script src="https://www.google.com/recaptcha/api.js?onload=' + this.getInitCallbackName() + '&render=explicit&hl=' 48 + this.cfg.language +'" async defer ' + nonce + '>'); 49 50 }, 51 52 /** 53 * Finds the name to use for the callback function set globally on the window. 54 * @private 55 * @return {string} Name for the global callback. 56 */ 57 getInitCallbackName : function() { 58 return this.cfg.widgetVar + '_initCallback'; 59 }, 60 61 /** 62 * Renders the client-side parts of this widget. 63 * @private 64 */ 65 render: function() { 66 $this = this; 67 grecaptcha.render(this.jq.get(0), { 68 'sitekey' : this.cfg.sitekey, 69 'tabindex': this.cfg.tabindex, 70 'theme': this.cfg.theme, 71 'callback': $this.cfg.callback, 72 'expired-callback': $this.cfg.expired, 73 'size': this.cfg.size 74 }); 75 76 if (this.cfg.size === 'invisible') { 77 grecaptcha.execute(); 78 } 79 80 window[this.getInitCallbackName()] = null; 81 }, 82 83 /** 84 * @override 85 * @inheritdoc 86 */ 87 destroy: function() { 88 this._super(); 89 90 window[this.getInitCallbackName()] = null; 91 } 92});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.