Skip to content

Commit

Permalink
merge: PR #30 from dev
Browse files Browse the repository at this point in the history
Weekly release 2023-02-20
  • Loading branch information
alycejenni authored Feb 20, 2023
2 parents 706b109 + 0f7e9fe commit 91cda49
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 261 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exclude: /(vendor|dist)/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
Expand Down Expand Up @@ -25,3 +26,9 @@ repos:
# these can't be pulled directly from the config atm, not sure why
args: ["-i", "--wrap-summaries=88", "--wrap-descriptions=88",
"--pre-summary-newline", "--make-summary-multi-line"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.4
hooks:
- id: prettier
types_or: [ javascript, vue, less, sass, scss, css ]
args: [ '--single-quote' ]
71 changes: 37 additions & 34 deletions ckanext/contact/theme/assets/modules/form-contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,45 @@
* <form data-module="form-contact"> ... </form>
*
*/
ckan.module('form-contact', function($, _) {
let self = null;
ckan.module('form-contact', function ($, _) {
let self = null;

return {
/**
* Initialisation function for this module, just sets up some variables and sets up the
* event listeners once the recaptcha library is ready.
*/
initialize: function() {
self = this;
return {
/**
* Initialisation function for this module, just sets up some variables and sets up the
* event listeners once the recaptcha library is ready.
*/
initialize: function () {
self = this;

// setup the recaptcha context
self.context = window.contacts_recaptcha.load(self.options.key, self.options.action);
if (self.context) {
// add a callback on the form's submission if the context is created, if it isn't we
// don't need to hijack the submit functionality on the form and can just let it go
// through as normal
self.el.on('submit', self.onSubmit);
}
},
// setup the recaptcha context
self.context = window.contacts_recaptcha.load(
self.options.key,
self.options.action,
);
if (self.context) {
// add a callback on the form's submission if the context is created, if it isn't we
// don't need to hijack the submit functionality on the form and can just let it go
// through as normal
self.el.on('submit', self.onSubmit);
}
},

/**
* Called when the form is submitted. Note that this callback is only attached if a
* recaptcha context is created, otherwise the default form submit function is used.
*/
onSubmit: function(event) {
// stop the form going through
event.preventDefault();
/**
* Called when the form is submitted. Note that this callback is only attached if a
* recaptcha context is created, otherwise the default form submit function is used.
*/
onSubmit: function (event) {
// stop the form going through
event.preventDefault();

// add the token to the form and then submit it when ready
self.context.addToken(self.el).then(function(token) {
// remove the listener we added so that we don't create an infinite loop
self.el.off('submit', self.onSubmit);
// submit the form as normal
self.el.submit();
});
},
};
// add the token to the form and then submit it when ready
self.context.addToken(self.el).then(function (token) {
// remove the listener we added so that we don't create an infinite loop
self.el.off('submit', self.onSubmit);
// submit the form as normal
self.el.submit();
});
},
};
});
Loading

0 comments on commit 91cda49

Please sign in to comment.