From b9b10fcfb83602f6ed4f267d8a68f608c1f031b2 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 18 Feb 2016 16:09:37 +0100 Subject: [PATCH] prepare form interaction, send GA events --- .../javascripts/bigchain/newsletter.js | 31 +++++++++++++------ .../javascripts/vendor/jquery.ajaxchimp.js | 10 ++++-- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/_src/_assets/javascripts/bigchain/newsletter.js b/_src/_assets/javascripts/bigchain/newsletter.js index 29316c6..31cdd9b 100644 --- a/_src/_assets/javascripts/bigchain/newsletter.js +++ b/_src/_assets/javascripts/bigchain/newsletter.js @@ -12,22 +12,33 @@ var Newsletter = (function(w, d, $) { }, _private = { - parsley: function() { - if (_config.newsletter.length > 0) { - _config.newsletter.parsley({ - trigger: 'change' - }); - } - }, - ajaxChimp: function() { - _config.newsletter.ajaxChimp(); + _config.newsletter.ajaxChimp({ + callback: formCallback + }); + + function formCallback (resp) { + if (resp.result === 'success') { + + _config.newsletter.find('.input-group').addClass('hide'); + + // send GA event + ga('send', 'event', 'newsletter', 'subscribe', 'success', true); + } + if (resp.result === 'error') { + _config.newsletter.find('.btn') + .removeClass('disabled') + .text('Subscribe'); + + // send GA event + ga('send', 'event', 'newsletter', 'subscribe', 'error', true); + } + } } }; app = { init: function() { - _private.parsley(); _private.ajaxChimp(); } }; diff --git a/_src/_assets/javascripts/vendor/jquery.ajaxchimp.js b/_src/_assets/javascripts/vendor/jquery.ajaxchimp.js index 0914948..4141e90 100644 --- a/_src/_assets/javascripts/vendor/jquery.ajaxchimp.js +++ b/_src/_assets/javascripts/vendor/jquery.ajaxchimp.js @@ -57,7 +57,7 @@ For e.g. 'http://blahblah.us1.list-manage.com/subscribe/post-json?u=5afsdhfuhdsi var form = $(elem); var email = form.find('input[type=email]'); var feedback = form.find('.form-control-feedback'); - var formgroup = form.find('.form-group'); + var formgroup = form.find('.input-group'); var settings = $.extend({ 'url': form.attr('action'), @@ -135,7 +135,7 @@ For e.g. 'http://blahblah.us1.list-manage.com/subscribe/post-json?u=5afsdhfuhdsi }); // Translate and display submit message - var submitMsg = 'Submitting...'; + var submitMsg = 'Sending...'; if( settings.language !== 'en' && $.ajaxChimp.translations @@ -144,7 +144,11 @@ For e.g. 'http://blahblah.us1.list-manage.com/subscribe/post-json?u=5afsdhfuhdsi ) { submitMsg = $.ajaxChimp.translations[settings.language]['submit']; } - feedback.html(submitMsg).show(2000); + form.find('.btn') + .addClass('disabled') + .text(submitMsg); + + //feedback.html(submitMsg).show(2000); return false; });