Skip to content

Commit

Permalink
Use jQuery slim
Browse files Browse the repository at this point in the history
Beautiful Jekyll from which this theme was ported switched to the slim version,
which doesn't include the `$.ajax()` function.  I changed the Staticman JS
script in the same way as my PR daattali/beautiful-jekyll#782 to make it
compatible with the slim version.
  • Loading branch information
VincentTam committed Feb 16, 2021
1 parent 99ca240 commit 9b4ca29
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
{{- if .Site.Params.selfHosted -}}
<script src="{{ "js/katex.min.js" | absURL }}"></script>
<script src="{{ "js/auto-render.min.js" | absURL }}"></script>
<script src="{{ "js/jquery.min.js" | absURL }}"></script>
<script src="{{ "js/jquery-3.5.1.slim.min.js" | absURL }}"></script>
<script src="{{ "js/bootstrap.min.js" | absURL }}"></script>
{{- else -}}
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.js" integrity="sha384-K3vbOmF2BtaVai+Qk37uypf7VrgBubhQreNQe9aGsz9lB63dIFiQVlJbr92dw2Lx" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/contrib/auto-render.min.js" integrity="sha384-kmZOZB5ObwgQnS/DuDg6TScgOiWWBiVt0plIRkZCmE6rDZGrEOQeHM5PcHi+nyqe" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
{{- end }}

Expand Down
2 changes: 2 additions & 0 deletions static/js/jquery-3.5.1.slim.min.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions static/js/jquery.min.js

This file was deleted.

34 changes: 20 additions & 14 deletions static/js/staticman.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@

$('.js-form').submit(function () {
var form = this;
let url = $(this).attr('action');
let data = $(this).serialize();

$(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('Perfect !', '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('Error', 'Sorry, there was an error with the submission!');
$(form).removeClass('form--loading');
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) {
showModal('Perfect !', 'Thanks for your comment! It will show on the site once it has been approved. .');
$(form).removeClass('form--loading');
} else {
console.error(xhr.statusText);
showModal('Error', 'Sorry, there was an error with the submission!');
$(form).removeClass('form--loading');
}
}
});
};

xhr.send(data);

return false;
});
Expand Down

0 comments on commit 9b4ca29

Please sign in to comment.