IE & jQuery slim compatible Staticman JS (#782)
This commit is contained in:
parent
85444cbac5
commit
452f1e025e
1 changed files with 34 additions and 21 deletions
|
@ -14,29 +14,42 @@ layout: null
|
||||||
var endpoint = '{{ sm.endpoint }}';
|
var endpoint = '{{ sm.endpoint }}';
|
||||||
var repository = '{{ sm.repository }}';
|
var repository = '{{ sm.repository }}';
|
||||||
var branch = '{{ sm.branch }}';
|
var branch = '{{ sm.branch }}';
|
||||||
|
let url = endpoint + repository + '/' + branch + '/comments';
|
||||||
|
let data = $(this).serialize();
|
||||||
|
|
||||||
$.ajax({
|
var xhr = new XMLHttpRequest();
|
||||||
type: $(this).attr('method'),
|
xhr.open("POST", url);
|
||||||
url: endpoint + repository + '/' + branch + '/comments',
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||||
data: $(this).serialize(),
|
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||||
contentType: 'application/x-www-form-urlencoded',
|
xhr.onreadystatechange = function () {
|
||||||
success: function (data) {
|
if(xhr.readyState === XMLHttpRequest.DONE) {
|
||||||
$('#comment-form-submit').addClass('d-none');
|
var status = xhr.status;
|
||||||
$('#comment-form-submitted').removeClass('d-none');
|
if (status >= 200 && status < 400) {
|
||||||
$('.page__comments-form .js-notice').removeClass('alert-danger');
|
formSubmitted();
|
||||||
$('.page__comments-form .js-notice').addClass('alert-success');
|
} else {
|
||||||
showAlert('success');
|
formError();
|
||||||
},
|
}
|
||||||
error: function (err) {
|
|
||||||
console.log(err);
|
|
||||||
$('#comment-form-submitted').addClass('d-none');
|
|
||||||
$('#comment-form-submit').removeClass('d-none');
|
|
||||||
$('.page__comments-form .js-notice').removeClass('alert-success');
|
|
||||||
$('.page__comments-form .js-notice').addClass('alert-danger');
|
|
||||||
showAlert('failure');
|
|
||||||
$(form).removeClass('disabled');
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
function formSubmitted() {
|
||||||
|
$('#comment-form-submit').addClass('d-none');
|
||||||
|
$('#comment-form-submitted').removeClass('d-none');
|
||||||
|
$('.page__comments-form .js-notice').removeClass('alert-danger');
|
||||||
|
$('.page__comments-form .js-notice').addClass('alert-success');
|
||||||
|
showAlert('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
function formError() {
|
||||||
|
$('#comment-form-submitted').addClass('d-none');
|
||||||
|
$('#comment-form-submit').removeClass('d-none');
|
||||||
|
$('.page__comments-form .js-notice').removeClass('alert-success');
|
||||||
|
$('.page__comments-form .js-notice').addClass('alert-danger');
|
||||||
|
showAlert('failure');
|
||||||
|
$(form).removeClass('disabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.send(data);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue