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('d-none');
  20. $('#comment-form-submitted').removeClass('d-none');
  21. $('.page__comments-form .js-notice').removeClass('alert-danger');
  22. $('.page__comments-form .js-notice').addClass('alert-success');
  23. showAlert('success');
  24. },
  25. error: function (err) {
  26. console.log(err);
  27. $('#comment-form-submitted').addClass('d-none');
  28. $('#comment-form-submit').removeClass('d-none');
  29. $('.page__comments-form .js-notice').removeClass('alert-success');
  30. $('.page__comments-form .js-notice').addClass('alert-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('d-none');
  39. if (message == 'success') {
  40. $('.page__comments-form .js-notice-text-success').removeClass('d-none');
  41. $('.page__comments-form .js-notice-text-failure').addClass('d-none');
  42. } else {
  43. $('.page__comments-form .js-notice-text-success').addClass('d-none');
  44. $('.page__comments-form .js-notice-text-failure').removeClass('d-none');
  45. }
  46. }
  47. })(jQuery);