Add includes for static-based comments powered by Staticman
- Configure Staticman with sane defaults - Build comment form to capture new comments and ajax data to Staticman - Build comments view that iterates over `_data/comments/post-slug/*.yml` files
This commit is contained in:
52
_includes/comments-providers/staticman.html
Normal file
52
_includes/comments-providers/staticman.html
Normal file
@@ -0,0 +1,52 @@
|
||||
{% if site.repository and site.staticman.branch %}
|
||||
<!-- Start comment form modal -->
|
||||
<article class="modal">
|
||||
<h2 class="modal__title js-modal-title"></h2>
|
||||
<div class="modal__supporting-text js-modal-text"></div>
|
||||
<div class="modal__actions">
|
||||
<button class="btn btn--danger js-close-modal">Close</button>
|
||||
</div>
|
||||
</article>
|
||||
<!-- End comment form modal -->
|
||||
|
||||
<script>
|
||||
(function ($) {
|
||||
var $comments = $('.js-comments');
|
||||
|
||||
$('.js-form').submit(function () {
|
||||
var form = this;
|
||||
|
||||
$(form).addClass('form--loading');
|
||||
|
||||
$.ajax({
|
||||
type: $(this).attr('method'),
|
||||
url: $(this).attr('action'),
|
||||
data: $(this).serialize(),
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
success: function (data) {
|
||||
showModal('{{ site.data.ui-text[site.locale].comment_success_title | default: "Comment submitted" }}', '{{ site.data.ui-text[site.locale].comment_success_msg | default: "Thanks for your comment! It will show on the site once it has been approved." }}');
|
||||
$(form).removeClass('form--loading');
|
||||
},
|
||||
error: function (err) {
|
||||
console.log(err);
|
||||
showModal('{{ site.data.ui-text[site.locale].comment_error_title | default: "Error" }}', '{{ site.data.ui-text[site.locale].comment_error_msg | default: "Sorry, there was an error with your submission. Please make sure all required fields have been completed and try again." }}');
|
||||
$(form).removeClass('form--loading');
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.js-close-modal').click(function () {
|
||||
$('body').removeClass('show-modal');
|
||||
});
|
||||
|
||||
function showModal(title, message) {
|
||||
$('.js-modal-title').text(title);
|
||||
$('.js-modal-text').html(message);
|
||||
|
||||
$('body').addClass('show-modal');
|
||||
}
|
||||
})(jQuery);
|
||||
</script>
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user