From 16c938714f595a9b71de9cef4a2d991fd2c34849 Mon Sep 17 00:00:00 2001 From: Pixelik Date: Tue, 9 Jan 2024 08:31:17 +0200 Subject: [PATCH] Update g-recaptcha.js --- addon/components/g-recaptcha.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/addon/components/g-recaptcha.js b/addon/components/g-recaptcha.js index a6d83ec..db0c11a 100644 --- a/addon/components/g-recaptcha.js +++ b/addon/components/g-recaptcha.js @@ -54,22 +54,23 @@ export default class GRecaptchaComponent extends Component { @action _initialize(element) { - window[`__ember_g_recaptcha_${this.elementId}_onload`] = () => { + const globalName = `__ember_g_recaptcha_${this.elementId}_onload`; + + window[globalName] = () => { this._render(element); }; - const baseUrl = [ - `${ - this.config['jsUrl'] || 'https://www.google.com/recaptcha/api.js' - }?render=explicit`, - `onload=__ember_g_recaptcha_${this.elementId}_onload`, - this.config['hl'] ? `hl=${this.config['hl']}` : '', - ].join('&'); + let baseUrl = [ + `${this.config['jsUrl'] || 'https://www.google.com/recaptcha/api.js'}?render=explicit`, + `onload=${globalName}` + ]; + + if (this.config['hl']) { + baseUrl.push(`hl=${this.config['hl']}`); + } if (!this.options['skip']) { - this._appendScript( - `${baseUrl}&onload=__ember_g_recaptcha_${this.elementId}_onload` - ); + this._appendScript(baseUrl.join('&')); } else { this._render(); }