-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/FriendlyCaptcha/friendly-ca…
- Loading branch information
Showing
5 changed files
with
78 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
(function() { | ||
var resetFriendlyCaptchaWidget = function() { | ||
window.friendlyChallenge.autoWidget.reset(); | ||
} | ||
document.addEventListener( 'DOMContentLoaded', function( event ) { | ||
document.addEventListener( 'wpcf7mailsent', | ||
resetFriendlyCaptchaWidget | ||
); | ||
document.addEventListener( 'wpcf7mailfailed', | ||
resetFriendlyCaptchaWidget | ||
); | ||
document.addEventListener( 'wpcf7spam', | ||
resetFriendlyCaptchaWidget | ||
); | ||
}); | ||
})(); | ||
(function () { | ||
var resetFriendlyCaptchaWidget = function () { | ||
window.friendlyChallenge.autoWidget.reset(); | ||
}; | ||
document.addEventListener("DOMContentLoaded", function (event) { | ||
document.addEventListener("wpcf7mailsent", resetFriendlyCaptchaWidget); | ||
document.addEventListener("wpcf7mailfailed", resetFriendlyCaptchaWidget); | ||
document.addEventListener("wpcf7spam", resetFriendlyCaptchaWidget); | ||
document.addEventListener("wpcf7invalid", resetFriendlyCaptchaWidget); | ||
document.addEventListener("wpcf7submit", resetFriendlyCaptchaWidget); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(function () { | ||
document.addEventListener("submit", function (e) { | ||
const form = e.submitter.closest("form"); | ||
if (!form) { | ||
return; | ||
} | ||
|
||
const element = form.querySelector(".frc-captcha"); | ||
if (!element) { | ||
return; | ||
} | ||
|
||
const widget = element.friendlyChallengeWidget; | ||
if (!widget) { | ||
return; | ||
} | ||
|
||
setTimeout(() => { | ||
// We reset the widget after a short delay to give the form time to grab the solution and submit it | ||
// This is a workaround for the fact that the form submit event is fired before the solution value is grabbed | ||
// 1 second is really conservative as this is not affected by network speed or anything like that | ||
widget.reset(); | ||
}, 1000); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(($) => { | ||
function submitWidgetInForm(form) { | ||
const elements = form.find(".frc-captcha"); | ||
if (!elements) { | ||
return; | ||
} | ||
|
||
elements.each((_, e) => { | ||
const widget = e.friendlyChallengeWidget; | ||
console.log(widget); | ||
if (!widget) { | ||
return; | ||
} | ||
|
||
widget.reset(); | ||
}); | ||
} | ||
|
||
$("form.wpforms-form").on( | ||
"wpformsAjaxSubmitSuccess wpformsAjaxSubmitFailed", | ||
(event) => { | ||
const form = $(event.target); | ||
if (form) { | ||
submitWidgetInForm(form); | ||
} | ||
} | ||
); | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters