Skip to content

Commit

Permalink
Merge branch '4.0-dev' into lang-assoc-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
infograf768 committed Nov 27, 2019
2 parents d5a1705 + c849ba8 commit d16676b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 65 deletions.
51 changes: 26 additions & 25 deletions build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Original file line number Diff line number Diff line change
@@ -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);
37 changes: 0 additions & 37 deletions build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.js

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/captcha/recaptcha/recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function onInit($id = 'dynamic_recaptcha_1')

HTMLHelper::_(
'script',
'https://www.google.com/recaptcha/api.js?onload=JoomlaInitReCaptcha2&render=explicit&hl=' . Factory::getLanguage()->getTag()
'https://www.google.com/recaptcha/api.js?onload=Joomla.initReCaptcha2&render=explicit&hl=' . Factory::getLanguage()->getTag()
);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::_(
Expand Down

0 comments on commit d16676b

Please sign in to comment.