Skip to content

Commit

Permalink
chore: render and execute separately
Browse files Browse the repository at this point in the history
  • Loading branch information
meysam81 committed Jan 6, 2025
1 parent a092338 commit d6eea55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions docs/static/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ document$.subscribe(function prepareSubForm() {
formParentDiv.classList.toggle("hidden");
}

function renderCaptcha() {
captchaWidget = hcaptcha.render(hcaptchaDivId, {
sitekey: hcaptchaSiteKey,
});
}

function subscribeButtonSubmit(event) {
event.preventDefault();

Expand All @@ -28,9 +34,11 @@ document$.subscribe(function prepareSubForm() {
});

if (hcaptcha.getRespKey().length == 0) {
captchaWidget = hcaptcha.render(hcaptchaDivId, {
sitekey: hcaptchaSiteKey,
});
renderCaptcha();
return;
}

if (hcaptcha.getResponse().length == 0) {
hcaptcha.execute(captchaWidget);
return;
}
Expand All @@ -47,7 +55,6 @@ document$.subscribe(function prepareSubForm() {
submitInfo.classList.add("md-banner--warning");
submitInfo.innerHTML = "Subscription failed. Please try again.";
hcaptcha.reset(captchaWidget);
document.getElementById(hcaptchaDivId).innerHTML = "";
}
};
xhr.send(formData);
Expand Down
2 changes: 1 addition & 1 deletion overrides/partials/subscription-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<i class="icon-paper-plane-abdcf51b"></i>
</button>
<div id="subscribe-form-9b27c56e" class="hidden">
<h3>Subscribe to Newsletter</h3>
<h3>Subscribe to our Newsletter</h3>
<div class="hidden" id="subscribe-submit-info-345a25b9"></div>
<form
id="subscription-form-b8eb1947"
Expand Down

0 comments on commit d6eea55

Please sign in to comment.