1
0
mirror of https://github.com/bigchaindb/site.git synced 2024-11-29 23:28:03 +01:00
site/_src/_assets/javascripts/bigchain/form-contact.js
Matthias Kretschmann 7f8b9909f7 More Google Analytics custom events
- whitepaper download
- all form submissions (success & error)
2016-02-11 15:59:24 +01:00

67 lines
2.1 KiB
JavaScript

var FormContact = (function(w, d, $) {
'use strict';
var app, _private, _config;
_config = {
form: $('#form-contact'),
formBtn: $('#form-contact').find('.btn'),
formURL: $('#form-contact').attr('action'),
formMethod: $('#form-contact').attr('method')
};
_private = {
formSubmit: function() {
_config.form.submit(function(e) {
e.preventDefault();
if ( $(this).parsley().isValid() ) {
$.ajax({
url: _config.formURL,
method: _config.formMethod,
data: $(this).serialize(),
dataType: 'json',
beforeSend: function() {
_config.formBtn
.addClass('disabled')
.attr('value', 'Sending...');
},
success: function(data) {
_config.form.find('.form-group').addClass('hide');
_config.form.find('.alert-success').removeClass('hide');
_config.formBtn.removeClass('disabled');
// send GA event
if (!_dntEnabled()) {
GoogleAnalytics.gaEventContactSuccess();
}
},
error: function(err) {
_config.form.find('.alert-danger').removeClass('hide');
_config.formBtn
.removeClass('disabled')
.attr('value', 'Send');
// send GA event
if (!_dntEnabled()) {
GoogleAnalytics.gaEventContactError();
}
}
});
}
});
}
};
app = {
init: function() {
_private.formSubmit();
}
};
return app;
})(window, document, jQuery);