From 6217d343f16009de5b896cc0765796a3247158bd Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Thu, 16 Apr 2020 20:51:56 +0300 Subject: [PATCH 1/2] security-package/issues/203: Added reset reCaptcha for Product Review form with tabs. --- .../view/frontend/web/js/reCaptcha.js | 36 +++++++++++++++++++ .../view/frontend/web/js/registry.js | 1 + 2 files changed, 37 insertions(+) diff --git a/ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js b/ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js index 0321bf70..b972caaf 100644 --- a/ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js +++ b/ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js @@ -126,6 +126,9 @@ define( registry.captchaList.push(widgetId); registry.tokenFields.push(this.tokenField); + let captchaId = this.getReCaptchaId(); + registry.captchaListDetails.push([widgetId] = captchaId); + }, /** @@ -180,6 +183,39 @@ define( me.initCaptcha(); }); } + + let captchaListDetails = registry.captchaListDetails(); + + if (this.getReCaptchaId()) { + + let captchaReloaded = false; + + $(".product.data.items").on("dimensionsChanged", function (event, data) { + if (captchaReloaded == false) { + let opened = data.opened; + + if (opened) { + + if (event.target && event.target.hasAttribute('aria-controls')) { + + let ariaControls = event.target.getAttribute('aria-controls'); + + if ($('#' + ariaControls).has('#' + this.getReCaptchaId()).length) { + let keys = captchaListDetails.keys(), + key; + + for (key of keys) { + if (captchaListDetails[key] == this.getReCaptchaId()) { + grecaptcha.reset(key); + captchaReloaded = true; + } + } + } + } + } + } + }.bind(this)); + } }, /** diff --git a/ReCaptchaFrontendUi/view/frontend/web/js/registry.js b/ReCaptchaFrontendUi/view/frontend/web/js/registry.js index 2ff47a0c..2cabbdd1 100644 --- a/ReCaptchaFrontendUi/view/frontend/web/js/registry.js +++ b/ReCaptchaFrontendUi/view/frontend/web/js/registry.js @@ -9,6 +9,7 @@ define(['ko'], function (ko) { return { ids: ko.observableArray([]), captchaList: ko.observableArray([]), + captchaListDetails: ko.observableArray([]), tokenFields: ko.observableArray([]) }; }); From bba11576adef78e65f596016f54d7a60937b512b Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Thu, 16 Apr 2020 21:05:04 +0300 Subject: [PATCH 2/2] security-package/issues/203: Added reset reCaptcha for Product Review form with tabs. --- ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js b/ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js index b972caaf..7c9cf630 100644 --- a/ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js +++ b/ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js @@ -186,7 +186,7 @@ define( let captchaListDetails = registry.captchaListDetails(); - if (this.getReCaptchaId()) { + if (this.getIsInvisibleRecaptcha() && this.getReCaptchaId()) { let captchaReloaded = false;