Advertisement
Guest User

Untitled

a guest
Feb 10th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. /**
  2. * MailChimp working newsletter
  3. * read more http://stackoverflow.com/a/15120409/477958
  4. */
  5. $.each($('form.mc-embedded-subscribe-form'), function(index, el) {
  6. var newsletterForm = $(el);
  7. newsletterForm.h5Validate();
  8.  
  9. newsletterForm.submit(function(e) {
  10. e.preventDefault();
  11. // If data-nldemo="0" attribute don't do nothing, just throw an alert.
  12. if(newsletterForm.attr('data-nldemo') && cform.attr('data-nldemo') == "0") {
  13. $.magnificPopup.open({
  14. items: {
  15. src: '<div class="white-popup">Newsletter form disabled on demo!</div>',
  16. type: 'inline'
  17. },
  18. closeBtnInside: true
  19. });
  20. return;
  21. }
  22. if(newsletterForm.h5Validate('allValid')) {
  23. var notifContainer = newsletterForm.next('.notification_container');
  24. $.ajax({
  25. type : newsletterForm.attr('method'),
  26. url : newsletterForm.attr('action'),
  27. data : newsletterForm.serialize(),
  28. cache : false,
  29. dataType : 'json',
  30. contentType : "application/json; charset=utf-8",
  31. error : function(err) {
  32. notifContainer.html('<div class="alert alert-warning">Could not connect to server. Please try again later.</div>');
  33. },
  34. success : function(data) {
  35. if (data.result != "success") {
  36. var message = data.msg.substring(4);
  37. notifContainer.html('<div class="alert alert-warning">'+message+'</div>');
  38. } else {
  39. var message = data.msg;
  40. notifContainer.html('<div class="alert alert-success">'+message+'</div>');
  41. }
  42. }
  43. });
  44. }
  45. });
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement