From 6cfc417937d3807dcefa73d53ef8543a04c53fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Sat, 25 Nov 2017 23:22:15 +0100 Subject: [PATCH] add missing js file --- ponyconf/static/js/markdown-preview.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ponyconf/static/js/markdown-preview.js diff --git a/ponyconf/static/js/markdown-preview.js b/ponyconf/static/js/markdown-preview.js new file mode 100644 index 0000000..f214420 --- /dev/null +++ b/ponyconf/static/js/markdown-preview.js @@ -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.'); + }); +})