Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HichemTab-tech committed Jul 27, 2023
1 parent d3634d1 commit a6fd5a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
20 changes: 12 additions & 8 deletions dist/easycaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,37 +182,37 @@ function handleOneChild($group, i, options, AUTO_INIT) {
if (meta.length !== 0) {
settings.ReCAPTCHA_API_KEY_CLIENT = meta.attr('content');
}
if ($this.attr('data-okbtn-selector') !== "") {
if (attrExist($this.attr('data-okbtn-selector'))) {
settings.autoVerification.okBtn = $this.attr('data-okbtn-selector');
}
if ($this.attr('data-recaptcha-apikey') !== "") {
if (attrExist($this.attr('data-recaptcha-apikey'))) {
settings.ReCAPTCHA_API_KEY_CLIENT = $this.attr('data-recaptcha-apikey');
}
if ($this.attr('data-required-msg-example-selector') !== "") {
if (attrExist($this.attr('data-required-msg-example-selector'))) {
let e = $($this.attr('data-required-msg-example-selector')).clone();
e.removeClass('hidden');
e.removeClass('d-none');
settings.autoVerification.requiredMsg = e;
}
if ($this.attr('data-loading-msg-example-selector') !== "") {
if (attrExist($this.attr('data-loading-msg-example-selector'))) {
let e = $($this.attr('data-loading-msg-example-selector')).clone();
e.removeClass('hidden');
e.removeClass('d-none');
settings.apiScriptLoading.loadingMsg = e;
}
if ($this.attr('data-error-msg-example-selector') !== "") {
if (attrExist($this.attr('data-error-msg-example-selector'))) {
let e = $($this.attr('data-error-msg-example-selector')).clone();
e.removeClass('hidden');
e.removeClass('d-none');
settings.apiScriptLoading.errorMsg = e;
}
if ($this.attr('data-theme') !== "") {
if (attrExist($this.attr('data-theme'))) {
settings.theme = $this.attr('data-theme');
}
data.settings = settings;
changeBtnState(data, false);
let idSuffix = Math.floor((Math.random() * 1000) + 100);
if ($this.attr('id') !== "") {
if (attrExist($this.attr('id'))) {
$this.attr('id', idSuffix + "_ReCaptchaTargetParent");
}
data.parentId = $this.attr('id');
Expand All @@ -225,6 +225,7 @@ function handleOneChild($group, i, options, AUTO_INIT) {
let $hiddenInput = $('<input type="hidden" name="g-recaptcha-response" id="g-recaptcha-response" value="">');
$hiddenInput.appendTo($this);
}
$this.data('EasyCaptcha', data);
startCheckingGoogleReCaptchaScript(data).then(
function () {
handleOneChild($group, i+1, options, AUTO_INIT);
Expand All @@ -233,7 +234,6 @@ function handleOneChild($group, i, options, AUTO_INIT) {
settings.failure(error??"Unknown error");
}
);
$this.data('EasyCaptcha', data);
} else {
handleOneChild($group, i+1, options, AUTO_INIT);
}
Expand Down Expand Up @@ -344,6 +344,10 @@ function changeBtnState(data, enable) {
else $okBtn.removeClass('disabled');
}
}

function attrExist(attr) {
return typeof attr !== 'undefined' && attr !== null && attr !== "";
}
;// CONCATENATED MODULE: ./index.js


Expand Down
2 changes: 1 addition & 1 deletion dist/easycaptcha.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions src/easycaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,37 +120,37 @@ function handleOneChild($group, i, options, AUTO_INIT) {
if (meta.length !== 0) {
settings.ReCAPTCHA_API_KEY_CLIENT = meta.attr('content');
}
if ($this.attr('data-okbtn-selector') !== "") {
if (attrExist($this.attr('data-okbtn-selector'))) {
settings.autoVerification.okBtn = $this.attr('data-okbtn-selector');
}
if ($this.attr('data-recaptcha-apikey') !== "") {
if (attrExist($this.attr('data-recaptcha-apikey'))) {
settings.ReCAPTCHA_API_KEY_CLIENT = $this.attr('data-recaptcha-apikey');
}
if ($this.attr('data-required-msg-example-selector') !== "") {
if (attrExist($this.attr('data-required-msg-example-selector'))) {
let e = $($this.attr('data-required-msg-example-selector')).clone();
e.removeClass('hidden');
e.removeClass('d-none');
settings.autoVerification.requiredMsg = e;
}
if ($this.attr('data-loading-msg-example-selector') !== "") {
if (attrExist($this.attr('data-loading-msg-example-selector'))) {
let e = $($this.attr('data-loading-msg-example-selector')).clone();
e.removeClass('hidden');
e.removeClass('d-none');
settings.apiScriptLoading.loadingMsg = e;
}
if ($this.attr('data-error-msg-example-selector') !== "") {
if (attrExist($this.attr('data-error-msg-example-selector'))) {
let e = $($this.attr('data-error-msg-example-selector')).clone();
e.removeClass('hidden');
e.removeClass('d-none');
settings.apiScriptLoading.errorMsg = e;
}
if ($this.attr('data-theme') !== "") {
if (attrExist($this.attr('data-theme'))) {
settings.theme = $this.attr('data-theme');
}
data.settings = settings;
changeBtnState(data, false);
let idSuffix = Math.floor((Math.random() * 1000) + 100);
if ($this.attr('id') !== "") {
if (attrExist($this.attr('id'))) {
$this.attr('id', idSuffix + "_ReCaptchaTargetParent");
}
data.parentId = $this.attr('id');
Expand All @@ -163,6 +163,7 @@ function handleOneChild($group, i, options, AUTO_INIT) {
let $hiddenInput = $('<input type="hidden" name="g-recaptcha-response" id="g-recaptcha-response" value="">');
$hiddenInput.appendTo($this);
}
$this.data('EasyCaptcha', data);
startCheckingGoogleReCaptchaScript(data).then(
function () {
handleOneChild($group, i+1, options, AUTO_INIT);
Expand All @@ -171,7 +172,6 @@ function handleOneChild($group, i, options, AUTO_INIT) {
settings.failure(error??"Unknown error");
}
);
$this.data('EasyCaptcha', data);
} else {
handleOneChild($group, i+1, options, AUTO_INIT);
}
Expand Down Expand Up @@ -281,4 +281,8 @@ function changeBtnState(data, enable) {
if (!enable) $okBtn.addClass('disabled');
else $okBtn.removeClass('disabled');
}
}

function attrExist(attr) {
return typeof attr !== 'undefined' && attr !== null && attr !== "";
}

0 comments on commit a6fd5a1

Please sign in to comment.