Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE & jQuery slim compatible Staticman JS #782

Merged
merged 2 commits into from
Oct 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions assets/js/staticman.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,42 @@ layout: null
var endpoint = '{{ sm.endpoint }}';
var repository = '{{ sm.repository }}';
var branch = '{{ sm.branch }}';
let url = endpoint + repository + '/' + branch + '/comments';
let data = $(this).serialize();

$.ajax({
type: $(this).attr('method'),
url: endpoint + repository + '/' + branch + '/comments',
data: $(this).serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function (data) {
$('#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');
},
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');
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onreadystatechange = function () {
if(xhr.readyState === XMLHttpRequest.DONE) {
var status = xhr.status;
if (status >= 200 && status < 400) {
formSubmitted();
} else {
formError();
}
}
});
};

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;
});
Expand Down