2016-08-10 22:08:13 +02:00
{% if site.repository and site.staticman.branch %}
< script >
(function ($) {
2016-08-12 04:32:27 +02:00
$('#new_comment').submit(function () {
2016-08-10 22:08:13 +02:00
var form = this;
2016-08-12 04:32:27 +02:00
$(form).addClass('disabled');
2018-01-04 20:27:27 +01:00
$('#comment-form-submit').html('< i class = "fas fa-spinner fa-spin fa-fw" > < / i > {{ site.data.ui-text[site.locale].loading_label | default: "Loading..." }}');
2016-08-10 22:08:13 +02:00
$.ajax({
type: $(this).attr('method'),
url: $(this).attr('action'),
data: $(this).serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function (data) {
2016-08-12 04:32:27 +02:00
$('#comment-form-submit').html('{{ site.data.ui-text[site.locale].comment_btn_submitted | default: "Submitted" }}');
$('.page__comments-form .js-notice').removeClass('notice--danger');
$('.page__comments-form .js-notice').addClass('notice--success');
showAlert('{{ 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." }}');
2016-08-10 22:08:13 +02:00
},
error: function (err) {
console.log(err);
2016-08-12 04:32:27 +02:00
$('#comment-form-submit').html('{{ site.data.ui-text[site.locale].comment_btn_submit | default: "Submit Comment" }}');
$('.page__comments-form .js-notice').removeClass('notice--success');
$('.page__comments-form .js-notice').addClass('notice--danger');
showAlert('{{ 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('disabled');
2016-08-10 22:08:13 +02:00
}
});
return false;
});
2016-08-12 04:32:27 +02:00
function showAlert(message) {
$('.page__comments-form .js-notice').removeClass('hidden');
$('.page__comments-form .js-notice-text').html(message);
2016-08-10 22:08:13 +02:00
}
})(jQuery);
< / script >
2019-01-01 22:39:39 +01:00
{% endif %}