core: use pure js to get cookie in markdown input

This commit is contained in:
Antoine Bartuccio 2018-12-14 17:53:25 +01:00
parent 775f456c40
commit d6f08d3706

View File

@ -15,23 +15,22 @@
// You can't get the csrf token from the template in a widget // You can't get the csrf token from the template in a widget
// We get it from a cookie as a workaround, see this link // We get it from a cookie as a workaround, see this link
// https://docs.djangoproject.com/en/2.0/ref/csrf/#ajax // https://docs.djangoproject.com/en/2.0/ref/csrf/#ajax
function getCookie(name) { function getCookie(cname) {
var cookieValue = null; var name = cname + "=";
if (document.cookie && document.cookie !== '') { var decodedCookie = decodeURIComponent(document.cookie);
var cookies = document.cookie.split(';'); var ca = decodedCookie.split(';');
for (var i = 0; i < cookies.length; i++) { for(var i = 0; i <ca.length; i++) {
var cookie = jQuery.trim(cookies[i]); var c = ca[i];
// Does this cookie string begin with the name we want? while (c.charAt(0) == ' ') {
if (cookie.substring(0, name.length + 1) === (name + '=')) { c = c.substring(1);
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); }
break; if (c.indexOf(name) == 0) {
} return c.substring(name.length, c.length);
} }
} }
return cookieValue; return "";
} }
// Custom markdown parser // Custom markdown parser
function customMarkdownParser(plainText, preview) { function customMarkdownParser(plainText, preview) {
// Wait for jquery to load // Wait for jquery to load