staticman.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ---
  2. layout: null
  3. ---
  4. (function ($) {
  5. var $comments = $('.js-comments');
  6. $('#new_comment').submit(function () {
  7. var form = this;
  8. $(form).addClass('disabled');
  9. {% assign sm = site.staticman -%}
  10. var endpoint = '{{ sm.endpoint | default: "https://staticman3.herokuapp.com/v3/entry/github/" }}';
  11. var repository = '{{ sm.repository }}';
  12. var branch = '{{ sm.branch }}';
  13. $.ajax({
  14. type: $(this).attr('method'),
  15. url: endpoint + repository + '/' + branch + '/comments',
  16. data: $(this).serialize(),
  17. contentType: 'application/x-www-form-urlencoded',
  18. success: function (data) {
  19. $('#comment-form-submit').addClass('hidden');
  20. $('#comment-form-submitted').removeClass('hidden');
  21. $('.page__comments-form .js-notice').removeClass('notice--danger');
  22. $('.page__comments-form .js-notice').addClass('notice--success');
  23. showAlert('success');
  24. },
  25. error: function (err) {
  26. console.log(err);
  27. $('#comment-form-submitted').addClass('hidden');
  28. $('#comment-form-submit').removeClass('hidden');
  29. $('.page__comments-form .js-notice').removeClass('notice--success');
  30. $('.page__comments-form .js-notice').addClass('notice--danger');
  31. showAlert('failure');
  32. $(form).removeClass('disabled');
  33. }
  34. });
  35. return false;
  36. });
  37. function showAlert(message) {
  38. $('.page__comments-form .js-notice').removeClass('hidden');
  39. if (message == 'success') {
  40. $('.page__comments-form .js-notice-text-success').removeClass('hidden');
  41. $('.page__comments-form .js-notice-text-failure').addClass('hidden');
  42. } else {
  43. $('.page__comments-form .js-notice-text-success').addClass('hidden');
  44. $('.page__comments-form .js-notice-text-failure').removeClass('hidden');
  45. }
  46. }
  47. })(jQuery);