diff --git a/build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js b/build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js index f3e3041519d08..3e8bb83ddf2b6 100644 --- a/build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js +++ b/build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js @@ -3,33 +3,34 @@ * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +Joomla = window.Joomla || {}; -window.JoomlaInitReCaptcha2 = () => { - 'use strict'; +((window, document, Joomla) => { + Joomla.initReCaptcha2 = () => { + 'use strict'; - const itemNodes = document.getElementsByClassName('g-recaptcha'); - const optionKeys = ['sitekey', 'theme', 'size', 'tabindex', 'callback', 'expired-callback', 'error-callback']; - const items = [].slice.call(itemNodes); + const elements = [].slice.call(document.getElementsByClassName('g-recaptcha')); + const optionKeys = ['sitekey', 'theme', 'size', 'tabindex', 'callback', 'expired-callback', 'error-callback']; - items.forEach((item) => { - let options = {}; + elements.forEach((element) => { + let options = {}; - if (item.dataset) { - options = item.dataset; - } else { - [].slice.call(optionKeys).forEach((optionData) => { - const optionKeyFq = `data-${optionData}`; - if (item.hasAttribute(optionKeyFq)) { - options[optionData] = item.getAttribute(optionKeyFq); - } - }); - } + if (element.dataset) { + options = element.dataset; + } else { + optionKeys.forEach((key) => { + const optionKeyFq = `data-${key}`; + if (element.hasAttribute(optionKeyFq)) { + options[key] = element.getAttribute(optionKeyFq); + } + }); + } - // Set the widget id of the recaptcha item - item.setAttribute( - 'data-recaptcha-widget-id', - /* global grecaptcha */ - grecaptcha.render(item, options), - ); - }); -}; + // Set the widget id of the recaptcha item + element.setAttribute( + 'data-recaptcha-widget-id', + window.grecaptcha.render(element, options), + ); + }); + }; +})(window, document, Joomla); diff --git a/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.es6.js b/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.es6.js new file mode 100644 index 0000000000000..31e0598e165bf --- /dev/null +++ b/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.es6.js @@ -0,0 +1,40 @@ +/** + * @package Joomla.JavaScript + * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ +Joomla = window.Joomla || {}; + +((window, document, Joomla) => { + Joomla.initReCaptchaInvisible = () => { + 'use strict'; + + const elements = [].slice.call(document.getElementsByClassName('g-recaptcha')); + const optionKeys = ['sitekey', 'badge', 'size', 'tabindex', 'callback', 'expired-callback', 'error-callback']; + + elements.forEach((element) => { + let options = {}; + + if (element.dataset) { + options = element.dataset; + } else { + optionKeys.forEach((key) => { + const optionKeyFq = `data-${optionKeys[key]}`; + + if (element.hasAttribute(optionKeyFq)) { + options[optionKeys[key]] = element.getAttribute(optionKeyFq); + } + }); + } + + // Set the widget id of the recaptcha item + element.setAttribute( + 'data-recaptcha-widget-id', + window.grecaptcha.render(element, options), + ); + + // Execute the invisible reCAPTCHA + window.grecaptcha.execute(element.getAttribute('data-recaptcha-widget-id')); + }); + }; +})(window, document, Joomla); diff --git a/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.js b/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.js deleted file mode 100644 index fc8db49afd4fa..0000000000000 --- a/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @package Joomla.JavaScript - * @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ -window.JoomlaInitReCaptchaInvisible = function() { - 'use strict'; - - var items = document.getElementsByClassName('g-recaptcha'), - item, - option_keys = ['sitekey', 'badge', 'size', 'tabindex', 'callback', 'expired-callback', 'error-callback'], - options = {}, - option_key_fq - ; - - for (var i = 0, l = items.length; i < l; i++) { - item = items[i]; - if (item.dataset) { - options = item.dataset; - } else { - for (var j = 0; j < option_keys.length; j++) { - option_key_fq = ('data-' + option_keys[j]); - if (item.hasAttribute(option_key_fq)) { - options[option_keys[j]] = item.getAttribute(option_key_fq); - } - } - } - - // Set the widget id of the recaptcha item - item.setAttribute( - 'data-recaptcha-widget-id', - grecaptcha.render(item, options) - ); - // Execute the invisible reCAPTCHA - grecaptcha.execute(item.getAttribute('data-recaptcha-widget-id')); - } -}; diff --git a/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.min.js b/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.min.js deleted file mode 100644 index 04a75ce6a8e6a..0000000000000 --- a/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.min.js +++ /dev/null @@ -1 +0,0 @@ -window.JoomlaInitReCaptchaInvisible=function(){"use strict";for(var t,e,a=document.getElementsByClassName("g-recaptcha"),i=["sitekey","badge","type","size","tabindex","callback"],c={},r=0,d=a.length;rgetTag() + 'https://www.google.com/recaptcha/api.js?onload=Joomla.initReCaptcha2&render=explicit&hl=' . Factory::getLanguage()->getTag() ); return true; diff --git a/plugins/captcha/recaptcha_invisible/recaptcha_invisible.php b/plugins/captcha/recaptcha_invisible/recaptcha_invisible.php index eda39453b94f1..96ef58774453a 100644 --- a/plugins/captcha/recaptcha_invisible/recaptcha_invisible.php +++ b/plugins/captcha/recaptcha_invisible/recaptcha_invisible.php @@ -77,7 +77,7 @@ public function onInit($id = 'dynamic_recaptcha_invisible_1') // Load Google reCAPTCHA api js $file = 'https://www.google.com/recaptcha/api.js' - . '?onload=JoomlaInitReCaptchaInvisible' + . '?onload=Joomla.initReCaptchaInvisible' . '&render=explicit' . '&hl=' . Factory::getLanguage()->getTag(); HTMLHelper::_(