npm.io
1.0.4 • Published 2 years ago

@berlinsms/captcha-wrapper

Licence
MIT
Version
1.0.4
Deps
0
Size
46 kB
Vulns
0
Weekly
0

jQuery CaptchaWrapper

Homepage

Description

This captcha wrapper makes it easy to include multiple types of captcha on your site.

This can be helpful if, for example, you want to let your customers choose the type of captcha.

The libraries of the unused captchas are not loaded.

Usage

Include jquery

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

Download bsms-captcha-wrapper

https://static.berlinsms.de/toolsforcoder/captcha-wrapper/dist/bsms-captcha-wrapper.min.js

Include bsms-captcha-wrapper

<script src="bsms-captcha-wrapper.min.js"></script>

Find your jquery-container and assign captcha-wrapper

$('.plugin-container').bsmsCaptchaWrapper();    

Make sure, the script is fully loaded, before you assign captcha-wrapper, e.g. use jquerys 'ready'

$(document).ready(function () {
    $('.plugin-container').bsmsCaptchaWrapper();
});    

Provide options:

$(document).ready(()=>{
    $('.plugin-container').bsmsCaptchaWrapper( { sitekey:'asdfghjklasdfghjkl' } );
});    

Provide callbacks:

$(document).ready(function () {
    $('.plugin-container')
        .bsmsCaptchaWrapper( { sitekey:'asdfghjklasdfghjkl' } )
        .onSolved(captchaSolved)
        .onExpired(captchaExpired);
});    
function captchaSolved(token) {
    alert(`Captcha solved with token=${token}`);
}
function captchaExpired() {
    alert(`Captcha expired`);
}

Options

Option DESCRIPTION DEFAULT
captchaType Type of captcha used. Feel free to add more types of captchas reCaptcha
sitekey Sitekey of recaptcha or hcaptcha or anycaptcha
onLoad Callback that fires when the captcha has loaded null
onSolved Callback that is triggered when the captcha has been solved null
onExpired Callback triggered when the captcha expires null
onError Callback, will be triggered, if something is wrong null

Keywords