add missing js file

This commit is contained in:
Élie Bouttier 2017-11-25 23:22:15 +01:00
parent 825a0111b4
commit 6cfc417937
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
var csrftoken = $.cookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
$('a[href="#preview"]').on("show.bs.tab", function (e) {
$('#markdown-preview').html('Loading preview...');
var markdown = $('#markdown-content').val();
$.post(markdown_preview_url, {'data': markdown})
.done(function(data, textStatus) {
$('#markdown-preview').html(data);
})
.fail(function () {
$('#markdown-preview').html('Sorry, an error occured.');
});
})