diff --git a/martor/settings.py b/martor/settings.py
index c3bbf56b..ac770866 100644
--- a/martor/settings.py
+++ b/martor/settings.py
@@ -233,3 +233,9 @@
)
# Disable admin style when using custom admin interface e.g django-grappelli
MARTOR_ENABLE_ADMIN_CSS = getattr(settings, "MARTOR_ENABLE_ADMIN_CSS", True)
+
+MARTOR_CSRF_COOKIE_NAME = (
+ settings.MARTOR_CSRF_COOKIE_NAME
+ if hasattr(settings, "MARTOR_CSRF_COOKIE_NAME")
+ else "csrftoken"
+)
\ No newline at end of file
diff --git a/martor/static/martor/js/martor.bootstrap.js b/martor/static/martor/js/martor.bootstrap.js
index c6aa781c..e06a1c69 100644
--- a/martor/static/martor/js/martor.bootstrap.js
+++ b/martor/static/martor/js/martor.bootstrap.js
@@ -92,7 +92,7 @@
url: textareaId.data('search-users-url'),
data: {
'username': username,
- 'csrfmiddlewaretoken': getCookie('csrftoken')
+ 'csrfmiddlewaretoken': getCookie(textareaId.data('csrf-cookie-name'))
},
success: function (data) {
if (data['status'] == 200) {
@@ -154,7 +154,7 @@
var value = textareaId.val();
var form = new FormData();
form.append('content', value);
- form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
+ form.append('csrfmiddlewaretoken', getCookie(textareaId.data('csrf-cookie-name')));
currentTab.addClass('martor-preview-stale');
$.ajax({
@@ -541,7 +541,7 @@
var firstForm = $('#' + editorId).closest('form').get(0);
var field_name = editor.container.id.replace('martor-', '');
var form = new FormData(firstForm);
- form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
+ form.append('csrfmiddlewaretoken', getCookie(textareaId.data('csrf-cookie-name')));
$.ajax({
url: textareaId.data('upload-url'),
diff --git a/martor/static/martor/js/martor.bootstrap.min.js b/martor/static/martor/js/martor.bootstrap.min.js
index 95c41b0d..1e508829 100644
--- a/martor/static/martor/js/martor.bootstrap.min.js
+++ b/martor/static/martor/js/martor.bootstrap.min.js
@@ -6,4 +6,4 @@
* Repository : https://github.com/agusmakmun/django-markdown-editor
* JS Minifier : https://jscompress.com
**/
-!function(A){(A=A||django.jQuery).fn.martor=function(){A(".martor").trigger("martor.init");function K(e){var n=null,o=0;if(document.cookie&&""!==document.cookie)for(var t=document.cookie.split(";");oNothing to preview
")},error:function(e){console.log("error",e)}})}let g;if(window.onload=function(){u()},"true"!==a.living?n.click(function(){d.hide(),u()}):r.on("change",function(){g&&clearTimeout(g),g=setTimeout(u,c.data("save-timeout"))}),"true"==a.spellcheck)try{enable_spellcheck(t)}catch(e){console.log("Spellcheck lib doesn't installed.")}function f(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," **** "),e.focus(),e.selection.moveTo(o.row,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"**"+o+"**"),t.end.column+=4,e.focus(),e.selection.setSelectionRange(t))}function p(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," __ "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"_"+o+"_"),t.end.column+=2,e.focus(),e.selection.setSelectionRange(t))}function w(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n----------\n\n"),e.focus(),e.selection.moveTo(o.row+4,o.column+10)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n----------\n\n"+o),e.focus(),e.selection.moveTo(t.end.row+4,t.end.column+10))}function v(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n# "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n# "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function k(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n## "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n## "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+3))}function h(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n### "),e.focus(),e.selection.moveTo(o.row+2,o.column+4)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n### "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+4))}function C(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n```\n\n```\n"),e.focus(),e.selection.moveTo(o.row+3,o.column)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n```\n"+o+"\n```\n"),e.focus(),e.selection.moveTo(t.end.row+3,t.end.column+3))}function y(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," `` "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"`"+o+"`"),t.end.column+=2,e.focus(),e.selection.setSelectionRange(t))}function T(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n> \n"),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n> "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function S(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n* "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n* "+o),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function R(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n1. "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n1. "+o),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+3))}function b(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," [](https://) "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"["+o+"](https://) "),e.focus(),e.selection.moveTo(t.end.row,t.end.column+11))}function x(e,n){var o,t,a,i=e.getSelectionRange();void 0===n?e.selection.isEmpty()?(a=e.getCursorPosition(),e.session.insert(a,"  "),e.focus(),e.selection.moveTo(a.row,a.column+3)):(o=e.getSelectionRange(),t=e.session.getTextRange(o),e.session.replace(o," "),e.focus(),e.selection.moveTo(i.end.row,i.end.column+12)):(a=e.getCursorPosition(),e.session.insert(a," "),e.focus(),e.selection.moveTo(a.row,a.column+n.name.length+2))}function O(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," @[]"),e.focus(),e.selection.moveTo(o.row,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"@["+o+"]"),e.focus(),e.selection.moveTo(t.end.row,t.end.column+3))}r.commands.addCommand({name:"markdownToBold",bindKey:{win:"Ctrl-B",mac:"Command-B"},exec:function(e){f(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToItalic",bindKey:{win:"Ctrl-I",mac:"Command-I"},exec:function(e){p(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToUnderscores",bindKey:{win:"Ctrl-Shift-U",mac:"Command-Shift-U"},exec:function(e){var n,o,t;t=(n=e).getSelectionRange(),n.selection.isEmpty()?(o=n.getCursorPosition(),n.session.insert(o," ++++ "),n.focus(),n.selection.moveTo(o.row,o.column+3)):(e=n.getSelectionRange(),o=n.session.getTextRange(e),n.session.replace(e,"++"+o+"++"),t.end.column+=4,n.focus(),n.selection.setSelectionRange(t))},readOnly:!0}),r.commands.addCommand({name:"markdownToStrikethrough",bindKey:{win:"Ctrl-Shift-S",mac:"Command-Shift-S"},exec:function(e){var n,o,t;t=(n=e).getSelectionRange(),n.selection.isEmpty()?(o=n.getCursorPosition(),n.session.insert(o," ~~~~ "),n.focus(),n.selection.moveTo(o.row,o.column+3)):(e=n.getSelectionRange(),o=n.session.getTextRange(e),n.session.replace(e,"~~"+o+"~~"),t.end.column+=4,n.focus(),n.selection.setSelectionRange(t))},readOnly:!0}),r.commands.addCommand({name:"markdownToHorizontal",bindKey:{win:"Ctrl-H",mac:"Command-H"},exec:function(e){w(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToH1",bindKey:{win:"Ctrl-Alt-1",mac:"Command-Option-1"},exec:function(e){v(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToH2",bindKey:{win:"Ctrl-Alt-2",mac:"Command-Option-3"},exec:function(e){k(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToH3",bindKey:{win:"Ctrl-Alt-3",mac:"Command-Option-3"},exec:function(e){h(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToPre",bindKey:{win:"Ctrl-Alt-P",mac:"Command-Option-P"},exec:function(e){C(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToCode",bindKey:{win:"Ctrl-Alt-C",mac:"Command-Option-C"},exec:function(e){y(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToBlockQuote",bindKey:{win:"Ctrl-Q",mac:"Command-Shift-K"},exec:function(e){T(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToUnorderedList",bindKey:{win:"Ctrl-U",mac:"Command-U"},exec:function(e){S(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToOrderedList",bindKey:{win:"Ctrl-Shift+O",mac:"Command-Option-O"},exec:function(e){R(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToLink",bindKey:{win:"Ctrl-L",mac:"Command-L"},exec:function(e){b(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToImageLink",bindKey:{win:"Ctrl-Shift-I",mac:"Command-Option-I"},exec:function(e){x(e)},readOnly:!0}),"true"===a.mention&&r.commands.addCommand({name:"markdownToMention",bindKey:{win:"Ctrl-M",mac:"Command-M"},exec:function(e){O(e)},readOnly:!0}),A(".markdown-bold[data-field-name="+s+"]").click(function(){f(r)}),A(".markdown-italic[data-field-name="+s+"]").click(function(){p(r)}),A(".markdown-horizontal[data-field-name="+s+"]").click(function(){w(r)}),A(".markdown-h1[data-field-name="+s+"]").click(function(){v(r)}),A(".markdown-h2[data-field-name="+s+"]").click(function(){k(r)}),A(".markdown-h3[data-field-name="+s+"]").click(function(){h(r)}),A(".markdown-pre[data-field-name="+s+"]").click(function(){C(r)}),A(".markdown-code[data-field-name="+s+"]").click(function(){y(r)}),A(".markdown-blockquote[data-field-name="+s+"]").click(function(){T(r)}),A(".markdown-unordered-list[data-field-name="+s+"]").click(function(){S(r)}),A(".markdown-ordered-list[data-field-name="+s+"]").click(function(){R(r)}),A(".markdown-link[data-field-name="+s+"]").click(function(){b(r)}),A(".markdown-image-link[data-field-name="+s+"]").click(function(){x(r)});i=A(".markdown-direct-mention[data-field-name="+s+"]"),n=A(".markdown-image-upload[data-field-name="+s+"]");"true"==a.mention?i.click(function(){O(r)}):(i.remove(),A(".markdown-reference tbody tr")[1].remove()),"true"==a.imgur?n.on("change",function(e){var n,o;e.preventDefault(),n=r,e=A("#"+t).closest("form").get(0),o=n.container.id.replace("martor-",""),(e=new FormData(e)).append("csrfmiddlewaretoken",K("csrftoken")),A.ajax({url:c.data("upload-url"),type:"POST",data:e,async:!0,cache:!1,contentType:!1,enctype:"multipart/form-data",processData:!1,beforeSend:function(){console.log("Uploading..."),A(".upload-progress[data-field-name="+o+"]").show()},success:function(e){A(".upload-progress[data-field-name="+o+"]").hide(),200==e.status?(console.log(e),x(n,imageData={name:e.name,link:e.link})):alert(e.error)},error:function(e){console.log("error",e),A(".upload-progress[data-field-name="+o+"]").hide()}})}):n.remove(),A(".markdown-help[data-field-name="+s+"]").click(function(){A(".modal-help-guide[data-field-name="+s+"]").modal("show")});function j(){A(document.body).removeClass("overflow"),A(this).attr({title:"Full Screen"}),A(this).find("svg.bi-arrows-angle-expand").show(),A(this).find("svg.bi-arrows-angle-contract").hide(),A(".main-martor-fullscreen").find(".martor-preview").removeAttr("style"),o.removeClass("main-martor-fullscreen"),P.removeAttr("style"),r.resize()}var P=A(".martor-field-"+s),E=A(".markdown-toggle-maximize[data-field-name="+s+"]");E.on("click",function(){!function(e){e.attr({title:"Minimize"}),e.find("svg.bi-arrows-angle-expand").hide(),e.find("svg.bi-arrows-angle-contract").show(),o.addClass("main-martor-fullscreen");var n=document.body.clientHeight-90;P.attr({style:"height:"+n+"px"}),A(".main-martor-fullscreen").find(".martor-preview").attr({style:"overflow-y: auto;height:"+n+"px"}),r.resize(),e.one("click",j),A(document.body).addClass("overflow")}(A(this))}),A(document).keyup(function(e){27==e.keyCode&&o.hasClass("main-martor-fullscreen")&&E.trigger("click")}),A(".markdown-emoji[data-field-name="+s+"]").click(function(){var t=A(".modal-emoji[data-field-name="+s+"]").modal("show"),e="undefined"!=typeof emojis?emojis:[],n=t.find(".emoji-content-body"),o=t.find(".emoji-loader-init");n.html(""),o.show(),t.show();for(var a=0;a
'+e[a]+"
"),A('a[data-emoji-target="'+e[a]+'"]').click(function(){var e,n,o;e=r,n=A(this).data("emoji-target"),o=e.getCursorPosition(),e.session.insert(o," "+n+" "),e.focus(),e.selection.moveTo(o.row,o.column+n.length+2),t.modal("hide")})}o.hide(),n.show(),t.modal("handleUpdate")}),r.setValue(c.val(),-1)})},A(function(){A(".main-martor").martor()}),"django"in window&&"jQuery"in window.django&&django.jQuery(document).on("formset:added",function(e){setTimeout(function(){var n=A(e.target);n.find(".main-martor").each(function(){var e=(e=n.attr("id")).substr(e.lastIndexOf("-")+1),e=A(this.outerHTML.replace(/__prefix__/g,e));A(this).replaceWith(e),e.martor()})},1e3)})}(jQuery);
+!function(A){(A=A||django.jQuery).fn.martor=function(){A(".martor").trigger("martor.init");function K(e){var n=null,o=0;if(document.cookie&&""!==document.cookie)for(var t=document.cookie.split(";");oNothing to preview")},error:function(e){console.log("error",e)}})}let g;if(window.onload=function(){u()},"true"!==a.living?n.click(function(){d.hide(),u()}):r.on("change",function(){g&&clearTimeout(g),g=setTimeout(u,c.data("save-timeout"))}),"true"==a.spellcheck)try{enable_spellcheck(t)}catch(e){console.log("Spellcheck lib doesn't installed.")}function f(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," **** "),e.focus(),e.selection.moveTo(o.row,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"**"+o+"**"),t.end.column+=4,e.focus(),e.selection.setSelectionRange(t))}function p(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," __ "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"_"+o+"_"),t.end.column+=2,e.focus(),e.selection.setSelectionRange(t))}function w(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n----------\n\n"),e.focus(),e.selection.moveTo(o.row+4,o.column+10)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n----------\n\n"+o),e.focus(),e.selection.moveTo(t.end.row+4,t.end.column+10))}function v(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n# "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n# "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function k(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n## "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n## "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+3))}function h(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n### "),e.focus(),e.selection.moveTo(o.row+2,o.column+4)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n### "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+4))}function C(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n```\n\n```\n"),e.focus(),e.selection.moveTo(o.row+3,o.column)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n```\n"+o+"\n```\n"),e.focus(),e.selection.moveTo(t.end.row+3,t.end.column+3))}function y(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," `` "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"`"+o+"`"),t.end.column+=2,e.focus(),e.selection.setSelectionRange(t))}function T(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n> \n"),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n> "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function S(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n* "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n* "+o),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function R(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n1. "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n1. "+o),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+3))}function b(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," [](https://) "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"["+o+"](https://) "),e.focus(),e.selection.moveTo(t.end.row,t.end.column+11))}function x(e,n){var o,t,a,i=e.getSelectionRange();void 0===n?e.selection.isEmpty()?(a=e.getCursorPosition(),e.session.insert(a,"  "),e.focus(),e.selection.moveTo(a.row,a.column+3)):(o=e.getSelectionRange(),t=e.session.getTextRange(o),e.session.replace(o," "),e.focus(),e.selection.moveTo(i.end.row,i.end.column+12)):(a=e.getCursorPosition(),e.session.insert(a," "),e.focus(),e.selection.moveTo(a.row,a.column+n.name.length+2))}function O(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," @[]"),e.focus(),e.selection.moveTo(o.row,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"@["+o+"]"),e.focus(),e.selection.moveTo(t.end.row,t.end.column+3))}r.commands.addCommand({name:"markdownToBold",bindKey:{win:"Ctrl-B",mac:"Command-B"},exec:function(e){f(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToItalic",bindKey:{win:"Ctrl-I",mac:"Command-I"},exec:function(e){p(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToUnderscores",bindKey:{win:"Ctrl-Shift-U",mac:"Command-Shift-U"},exec:function(e){var n,o,t;t=(n=e).getSelectionRange(),n.selection.isEmpty()?(o=n.getCursorPosition(),n.session.insert(o," ++++ "),n.focus(),n.selection.moveTo(o.row,o.column+3)):(e=n.getSelectionRange(),o=n.session.getTextRange(e),n.session.replace(e,"++"+o+"++"),t.end.column+=4,n.focus(),n.selection.setSelectionRange(t))},readOnly:!0}),r.commands.addCommand({name:"markdownToStrikethrough",bindKey:{win:"Ctrl-Shift-S",mac:"Command-Shift-S"},exec:function(e){var n,o,t;t=(n=e).getSelectionRange(),n.selection.isEmpty()?(o=n.getCursorPosition(),n.session.insert(o," ~~~~ "),n.focus(),n.selection.moveTo(o.row,o.column+3)):(e=n.getSelectionRange(),o=n.session.getTextRange(e),n.session.replace(e,"~~"+o+"~~"),t.end.column+=4,n.focus(),n.selection.setSelectionRange(t))},readOnly:!0}),r.commands.addCommand({name:"markdownToHorizontal",bindKey:{win:"Ctrl-H",mac:"Command-H"},exec:function(e){w(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToH1",bindKey:{win:"Ctrl-Alt-1",mac:"Command-Option-1"},exec:function(e){v(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToH2",bindKey:{win:"Ctrl-Alt-2",mac:"Command-Option-3"},exec:function(e){k(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToH3",bindKey:{win:"Ctrl-Alt-3",mac:"Command-Option-3"},exec:function(e){h(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToPre",bindKey:{win:"Ctrl-Alt-P",mac:"Command-Option-P"},exec:function(e){C(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToCode",bindKey:{win:"Ctrl-Alt-C",mac:"Command-Option-C"},exec:function(e){y(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToBlockQuote",bindKey:{win:"Ctrl-Q",mac:"Command-Shift-K"},exec:function(e){T(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToUnorderedList",bindKey:{win:"Ctrl-U",mac:"Command-U"},exec:function(e){S(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToOrderedList",bindKey:{win:"Ctrl-Shift+O",mac:"Command-Option-O"},exec:function(e){R(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToLink",bindKey:{win:"Ctrl-L",mac:"Command-L"},exec:function(e){b(e)},readOnly:!0}),r.commands.addCommand({name:"markdownToImageLink",bindKey:{win:"Ctrl-Shift-I",mac:"Command-Option-I"},exec:function(e){x(e)},readOnly:!0}),"true"===a.mention&&r.commands.addCommand({name:"markdownToMention",bindKey:{win:"Ctrl-M",mac:"Command-M"},exec:function(e){O(e)},readOnly:!0}),A(".markdown-bold[data-field-name="+s+"]").click(function(){f(r)}),A(".markdown-italic[data-field-name="+s+"]").click(function(){p(r)}),A(".markdown-horizontal[data-field-name="+s+"]").click(function(){w(r)}),A(".markdown-h1[data-field-name="+s+"]").click(function(){v(r)}),A(".markdown-h2[data-field-name="+s+"]").click(function(){k(r)}),A(".markdown-h3[data-field-name="+s+"]").click(function(){h(r)}),A(".markdown-pre[data-field-name="+s+"]").click(function(){C(r)}),A(".markdown-code[data-field-name="+s+"]").click(function(){y(r)}),A(".markdown-blockquote[data-field-name="+s+"]").click(function(){T(r)}),A(".markdown-unordered-list[data-field-name="+s+"]").click(function(){S(r)}),A(".markdown-ordered-list[data-field-name="+s+"]").click(function(){R(r)}),A(".markdown-link[data-field-name="+s+"]").click(function(){b(r)}),A(".markdown-image-link[data-field-name="+s+"]").click(function(){x(r)});i=A(".markdown-direct-mention[data-field-name="+s+"]"),n=A(".markdown-image-upload[data-field-name="+s+"]");"true"==a.mention?i.click(function(){O(r)}):(i.remove(),A(".markdown-reference tbody tr")[1].remove()),"true"==a.imgur?n.on("change",function(e){var n,o;e.preventDefault(),n=r,e=A("#"+t).closest("form").get(0),o=n.container.id.replace("martor-",""),(e=new FormData(e)).append("csrfmiddlewaretoken",K(c.data("csrf-cookie-name"))),A.ajax({url:c.data("upload-url"),type:"POST",data:e,async:!0,cache:!1,contentType:!1,enctype:"multipart/form-data",processData:!1,beforeSend:function(){console.log("Uploading..."),A(".upload-progress[data-field-name="+o+"]").show()},success:function(e){A(".upload-progress[data-field-name="+o+"]").hide(),200==e.status?(console.log(e),x(n,imageData={name:e.name,link:e.link})):alert(e.error)},error:function(e){console.log("error",e),A(".upload-progress[data-field-name="+o+"]").hide()}})}):n.remove(),A(".markdown-help[data-field-name="+s+"]").click(function(){A(".modal-help-guide[data-field-name="+s+"]").modal("show")});function j(){A(document.body).removeClass("overflow"),A(this).attr({title:"Full Screen"}),A(this).find("svg.bi-arrows-angle-expand").show(),A(this).find("svg.bi-arrows-angle-contract").hide(),A(".main-martor-fullscreen").find(".martor-preview").removeAttr("style"),o.removeClass("main-martor-fullscreen"),P.removeAttr("style"),r.resize()}var P=A(".martor-field-"+s),E=A(".markdown-toggle-maximize[data-field-name="+s+"]");E.on("click",function(){!function(e){e.attr({title:"Minimize"}),e.find("svg.bi-arrows-angle-expand").hide(),e.find("svg.bi-arrows-angle-contract").show(),o.addClass("main-martor-fullscreen");var n=document.body.clientHeight-90;P.attr({style:"height:"+n+"px"}),A(".main-martor-fullscreen").find(".martor-preview").attr({style:"overflow-y: auto;height:"+n+"px"}),r.resize(),e.one("click",j),A(document.body).addClass("overflow")}(A(this))}),A(document).keyup(function(e){27==e.keyCode&&o.hasClass("main-martor-fullscreen")&&E.trigger("click")}),A(".markdown-emoji[data-field-name="+s+"]").click(function(){var t=A(".modal-emoji[data-field-name="+s+"]").modal("show"),e="undefined"!=typeof emojis?emojis:[],n=t.find(".emoji-content-body"),o=t.find(".emoji-loader-init");n.html(""),o.show(),t.show();for(var a=0;a
'+e[a]+"
"),A('a[data-emoji-target="'+e[a]+'"]').click(function(){var e,n,o;e=r,n=A(this).data("emoji-target"),o=e.getCursorPosition(),e.session.insert(o," "+n+" "),e.focus(),e.selection.moveTo(o.row,o.column+n.length+2),t.modal("hide")})}o.hide(),n.show(),t.modal("handleUpdate")}),r.setValue(c.val(),-1)})},A(function(){A(".main-martor").martor()}),"django"in window&&"jQuery"in window.django&&django.jQuery(document).on("formset:added",function(e){setTimeout(function(){var n=A(e.target);n.find(".main-martor").each(function(){var e=(e=n.attr("id")).substr(e.lastIndexOf("-")+1),e=A(this.outerHTML.replace(/__prefix__/g,e));A(this).replaceWith(e),e.martor()})},1e3)})}(jQuery);
diff --git a/martor/static/martor/js/martor.semantic.js b/martor/static/martor/js/martor.semantic.js
index 55c95696..4cfd49a5 100644
--- a/martor/static/martor/js/martor.semantic.js
+++ b/martor/static/martor/js/martor.semantic.js
@@ -92,7 +92,7 @@
url: textareaId.data('search-users-url'),
data: {
'username': username,
- 'csrfmiddlewaretoken': getCookie('csrftoken')
+ 'csrfmiddlewaretoken': getCookie(textareaId.data('csrf-cookie-name'))
},
success: function (data) {
if (data['status'] == 200) {
@@ -143,7 +143,7 @@
var value = textareaId.val();
var form = new FormData();
form.append('content', value);
- form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
+ form.append('csrfmiddlewaretoken', getCookie(textareaId.data('csrf-cookie-name')));
currentTab.addClass('martor-preview-stale');
$.ajax({
@@ -536,7 +536,7 @@
var firstForm = $('#' + editorId).closest('form').get(0);
var field_name = editor.container.id.replace('martor-', '');
var form = new FormData(firstForm);
- form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
+ form.append('csrfmiddlewaretoken', getCookie(textareaId.data('csrf-cookie-name')));
$.ajax({
url: textareaId.data('upload-url'),
diff --git a/martor/static/martor/js/martor.semantic.min.js b/martor/static/martor/js/martor.semantic.min.js
index fb93eed9..bd5b1c9e 100644
--- a/martor/static/martor/js/martor.semantic.min.js
+++ b/martor/static/martor/js/martor.semantic.min.js
@@ -6,4 +6,4 @@
* Repository : https://github.com/agusmakmun/django-markdown-editor
* JS Minifier : https://jscompress.com
**/
-!function(E){(E=E||django.jQuery).fn.martor=function(){E(".martor").trigger("martor.init");function P(e){var n=null,o=0;if(document.cookie&&""!==document.cookie)for(var t=document.cookie.split(";");oNothing to preview")},error:function(e){console.log("error",e)}})}var d=E(".tab.segment[data-tab=preview-tab-"+s+"]"),a=E(".item[data-tab=preview-tab-"+s+"]");let u;if(window.onload=function(){l()},"true"!==i.living?a.click(function(){E(this).closest(".tab-martor-menu").find(".martor-toolbar").hide(),l()}):c.on("change",function(){u&&clearTimeout(u),u=setTimeout(l,r.data("save-timeout"))}),E(".item[data-tab=editor-tab-"+s+"]").click(function(){E(this).closest(".tab-martor-menu").find(".martor-toolbar").show()}),"true"==i.spellcheck)try{enable_spellcheck(t)}catch(e){console.log("Spellcheck lib doesn't installed.")}function f(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," **** "),e.focus(),e.selection.moveTo(o.row,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"**"+o+"**"),t.end.column+=4,e.focus(),e.selection.setSelectionRange(t))}function g(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," __ "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"_"+o+"_"),t.end.column+=2,e.focus(),e.selection.setSelectionRange(t))}function p(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n----------\n\n"),e.focus(),e.selection.moveTo(o.row+4,o.column+10)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n----------\n\n"+o),e.focus(),e.selection.moveTo(t.end.row+4,t.end.column+10))}function w(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n# "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n# "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function v(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n## "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n## "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+3))}function k(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n### "),e.focus(),e.selection.moveTo(o.row+2,o.column+4)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n### "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+4))}function C(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n```\n\n```\n"),e.focus(),e.selection.moveTo(o.row+3,o.column)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n```\n"+o+"\n```\n"),e.focus(),e.selection.moveTo(t.end.row+3,t.end.column+3))}function h(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," `` "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"`"+o+"`"),t.end.column+=2,e.focus(),e.selection.setSelectionRange(t))}function y(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n> \n"),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n> "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function T(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n* "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n* "+o),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function S(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n1. "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n1. "+o),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+3))}function b(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," [](https://) "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"["+o+"](https://) "),e.focus(),e.selection.moveTo(t.end.row,t.end.column+10))}function R(e,n){var o,t,i,a=e.getSelectionRange();void 0===n?e.selection.isEmpty()?(i=e.getCursorPosition(),e.session.insert(i,"  "),e.focus(),e.selection.moveTo(i.row,i.column+3)):(o=e.getSelectionRange(),t=e.session.getTextRange(o),e.session.replace(o," "),e.focus(),e.selection.moveTo(a.end.row,a.end.column+11)):(i=e.getCursorPosition(),e.session.insert(i," "),e.focus(),e.selection.moveTo(i.row,i.column+n.name.length+2))}function x(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," @[]"),e.focus(),e.selection.moveTo(o.row,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"@["+o+"]"),e.focus(),e.selection.moveTo(t.end.row,t.end.column+3))}c.commands.addCommand({name:"markdownToBold",bindKey:{win:"Ctrl-B",mac:"Command-B"},exec:function(e){f(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToItalic",bindKey:{win:"Ctrl-I",mac:"Command-I"},exec:function(e){g(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToUnderscores",bindKey:{win:"Ctrl-Shift-U",mac:"Command-Shift-U"},exec:function(e){var n,o,t;t=(n=e).getSelectionRange(),n.selection.isEmpty()?(o=n.getCursorPosition(),n.session.insert(o," ++++ "),n.focus(),n.selection.moveTo(o.row,o.column+3)):(e=n.getSelectionRange(),o=n.session.getTextRange(e),n.session.replace(e,"++"+o+"++"),t.end.column+=4,n.focus(),n.selection.setSelectionRange(t))},readOnly:!0}),c.commands.addCommand({name:"markdownToStrikethrough",bindKey:{win:"Ctrl-Shift-S",mac:"Command-Shift-S"},exec:function(e){var n,o,t;t=(n=e).getSelectionRange(),n.selection.isEmpty()?(o=n.getCursorPosition(),n.session.insert(o," ~~~~ "),n.focus(),n.selection.moveTo(o.row,o.column+3)):(e=n.getSelectionRange(),o=n.session.getTextRange(e),n.session.replace(e,"~~"+o+"~~"),t.end.column+=4,n.focus(),n.selection.setSelectionRange(t))},readOnly:!0}),c.commands.addCommand({name:"markdownToHorizontal",bindKey:{win:"Ctrl-H",mac:"Command-H"},exec:function(e){p(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToH1",bindKey:{win:"Ctrl-Alt-1",mac:"Command-Option-1"},exec:function(e){w(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToH2",bindKey:{win:"Ctrl-Alt-2",mac:"Command-Option-3"},exec:function(e){v(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToH3",bindKey:{win:"Ctrl-Alt-3",mac:"Command-Option-3"},exec:function(e){k(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToPre",bindKey:{win:"Ctrl-Alt-P",mac:"Command-Option-P"},exec:function(e){C(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToCode",bindKey:{win:"Ctrl-Alt-C",mac:"Command-Option-C"},exec:function(e){h(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToBlockQuote",bindKey:{win:"Ctrl-Q",mac:"Command-Shift-K"},exec:function(e){y(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToUnorderedList",bindKey:{win:"Ctrl-U",mac:"Command-U"},exec:function(e){T(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToOrderedList",bindKey:{win:"Ctrl-Shift+O",mac:"Command-Option-O"},exec:function(e){S(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToLink",bindKey:{win:"Ctrl-L",mac:"Command-L"},exec:function(e){b(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToImageLink",bindKey:{win:"Ctrl-Shift-I",mac:"Command-Option-I"},exec:function(e){R(e)},readOnly:!0}),"true"===i.mention&&c.commands.addCommand({name:"markdownToMention",bindKey:{win:"Ctrl-M",mac:"Command-M"},exec:function(e){x(e)},readOnly:!0}),E(".markdown-bold[data-field-name="+s+"]").click(function(){f(c)}),E(".markdown-italic[data-field-name="+s+"]").click(function(){g(c)}),E(".markdown-horizontal[data-field-name="+s+"]").click(function(){p(c)}),E(".markdown-h1[data-field-name="+s+"]").click(function(){w(c)}),E(".markdown-h2[data-field-name="+s+"]").click(function(){v(c)}),E(".markdown-h3[data-field-name="+s+"]").click(function(){k(c)}),E(".markdown-pre[data-field-name="+s+"]").click(function(){C(c)}),E(".markdown-code[data-field-name="+s+"]").click(function(){h(c)}),E(".markdown-blockquote[data-field-name="+s+"]").click(function(){y(c)}),E(".markdown-unordered-list[data-field-name="+s+"]").click(function(){T(c)}),E(".markdown-ordered-list[data-field-name="+s+"]").click(function(){S(c)}),E(".markdown-link[data-field-name="+s+"]").click(function(){b(c)}),E(".markdown-image-link[data-field-name="+s+"]").click(function(){R(c)});n=E(".markdown-direct-mention[data-field-name="+s+"]"),a=E(".markdown-image-upload[data-field-name="+s+"]");"true"===i.mention?n.click(function(){x(c)}):(n.remove(),E(".markdown-reference tbody tr")[1].remove()),"true"===i.imgur?a.on("change",function(e){var n,o;e.preventDefault(),n=c,e=E("#"+t).closest("form").get(0),o=n.container.id.replace("martor-",""),(e=new FormData(e)).append("csrfmiddlewaretoken",P("csrftoken")),E.ajax({url:r.data("upload-url"),type:"POST",data:e,async:!0,cache:!1,contentType:!1,enctype:"multipart/form-data",processData:!1,beforeSend:function(){console.log("Uploading..."),E(".upload-progress[data-field-name="+o+"]").show()},success:function(e){E(".upload-progress[data-field-name="+o+"]").hide(),200==e.status?(console.log(e),R(n,imageData={name:e.name,link:e.link})):alert(e.error)},error:function(e){console.log("error",e),E(".upload-progress[data-field-name="+o+"]").hide()}})}):a.remove(),E(".markdown-help[data-field-name="+s+"]").click(function(){E(".modal-help-guide[data-field-name="+s+"]").modal("show")}),o.find(".ui.martor-toolbar .ui.dropdown").dropdown(),o.find(".ui.tab-martor-menu .item").tab();function O(){E(document.body).removeClass("overflow"),E(this).attr({title:"Full Screen"}),E(this).find(".minimize.icon").removeClass("minimize").addClass("maximize"),E(".main-martor-fullscreen").find(".martor-preview").removeAttr("style"),o.removeClass("main-martor-fullscreen"),j.removeAttr("style"),c.resize()}var j=E(".martor-field-"+s),a=E(".markdown-toggle-maximize[data-field-name="+s+"]");a.on("click",function(){!function(e){e.attr({title:"Minimize"}),e.find(".maximize.icon").removeClass("maximize").addClass("minimize"),o.addClass("main-martor-fullscreen");var n=document.body.clientHeight-90;j.attr({style:"height:"+n+"px"}),E(".main-martor-fullscreen").find(".martor-preview").attr({style:"overflow-y: auto;height:"+n+"px"}),c.resize(),e.one("click",O),E(document.body).addClass("overflow")}(E(this))}),E(document).keyup(function(e){27==e.keyCode&&o.hasClass("main-martor-fullscreen")&&E(".minimize.icon").trigger("click")}),E(".markdown-emoji[data-field-name="+s+"]").click(function(){var t=E(".modal-emoji[data-field-name="+s+"]"),o="undefined"!=typeof emojis?emojis:[],i=t.find(".emoji-content-body"),a=t.find(".emoji-loader-init");i.html(""),a.show(),t.modal({onVisible:function(){for(var e=0;e
'+o[e]+"
"),E('a[data-emoji-target="'+o[e]+'"]').click(function(){var e,n,o;e=c,n=E(this).data("emoji-target"),o=e.getCursorPosition(),e.session.insert(o," "+n+" "),e.focus(),e.selection.moveTo(o.row,o.column+n.length+2),t.modal("hide",100)})}a.hide(),t.modal("refresh")}}).modal("show")}),c.setValue(r.val(),-1)})},E(function(){E(".main-martor").martor()}),"django"in window&&"jQuery"in window.django&&django.jQuery(document).on("formset:added",function(e,n){setTimeout(function(){n.find(".main-martor").each(function(){var e=(e=n.attr("id")).substr(e.lastIndexOf("-")+1),e=E(this.outerHTML.replace(/__prefix__/g,e));E(this).replaceWith(e),e.martor()})},1e3)})}(jQuery);
+!function(E){(E=E||django.jQuery).fn.martor=function(){E(".martor").trigger("martor.init");function P(e){var n=null,o=0;if(document.cookie&&""!==document.cookie)for(var t=document.cookie.split(";");oNothing to preview")},error:function(e){console.log("error",e)}})}var d=E(".tab.segment[data-tab=preview-tab-"+s+"]"),a=E(".item[data-tab=preview-tab-"+s+"]");let u;if(window.onload=function(){l()},"true"!==i.living?a.click(function(){E(this).closest(".tab-martor-menu").find(".martor-toolbar").hide(),l()}):c.on("change",function(){u&&clearTimeout(u),u=setTimeout(l,r.data("save-timeout"))}),E(".item[data-tab=editor-tab-"+s+"]").click(function(){E(this).closest(".tab-martor-menu").find(".martor-toolbar").show()}),"true"==i.spellcheck)try{enable_spellcheck(t)}catch(e){console.log("Spellcheck lib doesn't installed.")}function f(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," **** "),e.focus(),e.selection.moveTo(o.row,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"**"+o+"**"),t.end.column+=4,e.focus(),e.selection.setSelectionRange(t))}function g(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," __ "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"_"+o+"_"),t.end.column+=2,e.focus(),e.selection.setSelectionRange(t))}function p(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n----------\n\n"),e.focus(),e.selection.moveTo(o.row+4,o.column+10)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n----------\n\n"+o),e.focus(),e.selection.moveTo(t.end.row+4,t.end.column+10))}function w(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n# "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n# "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function v(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n## "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n## "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+3))}function k(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n### "),e.focus(),e.selection.moveTo(o.row+2,o.column+4)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n### "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+4))}function C(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n```\n\n```\n"),e.focus(),e.selection.moveTo(o.row+3,o.column)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n```\n"+o+"\n```\n"),e.focus(),e.selection.moveTo(t.end.row+3,t.end.column+3))}function h(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," `` "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"`"+o+"`"),t.end.column+=2,e.focus(),e.selection.setSelectionRange(t))}function y(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n> \n"),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n> "+o+"\n"),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function T(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n* "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n* "+o),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+2))}function S(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o,"\n\n1. "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"\n\n1. "+o),e.focus(),e.selection.moveTo(t.end.row+2,t.end.column+3))}function b(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," [](https://) "),e.focus(),e.selection.moveTo(o.row,o.column+2)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"["+o+"](https://) "),e.focus(),e.selection.moveTo(t.end.row,t.end.column+10))}function R(e,n){var o,t,i,a=e.getSelectionRange();void 0===n?e.selection.isEmpty()?(i=e.getCursorPosition(),e.session.insert(i,"  "),e.focus(),e.selection.moveTo(i.row,i.column+3)):(o=e.getSelectionRange(),t=e.session.getTextRange(o),e.session.replace(o," "),e.focus(),e.selection.moveTo(a.end.row,a.end.column+11)):(i=e.getCursorPosition(),e.session.insert(i," "),e.focus(),e.selection.moveTo(i.row,i.column+n.name.length+2))}function x(e){var n,o,t=e.getSelectionRange();e.selection.isEmpty()?(o=e.getCursorPosition(),e.session.insert(o," @[]"),e.focus(),e.selection.moveTo(o.row,o.column+3)):(n=e.getSelectionRange(),o=e.session.getTextRange(n),e.session.replace(n,"@["+o+"]"),e.focus(),e.selection.moveTo(t.end.row,t.end.column+3))}c.commands.addCommand({name:"markdownToBold",bindKey:{win:"Ctrl-B",mac:"Command-B"},exec:function(e){f(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToItalic",bindKey:{win:"Ctrl-I",mac:"Command-I"},exec:function(e){g(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToUnderscores",bindKey:{win:"Ctrl-Shift-U",mac:"Command-Shift-U"},exec:function(e){var n,o,t;t=(n=e).getSelectionRange(),n.selection.isEmpty()?(o=n.getCursorPosition(),n.session.insert(o," ++++ "),n.focus(),n.selection.moveTo(o.row,o.column+3)):(e=n.getSelectionRange(),o=n.session.getTextRange(e),n.session.replace(e,"++"+o+"++"),t.end.column+=4,n.focus(),n.selection.setSelectionRange(t))},readOnly:!0}),c.commands.addCommand({name:"markdownToStrikethrough",bindKey:{win:"Ctrl-Shift-S",mac:"Command-Shift-S"},exec:function(e){var n,o,t;t=(n=e).getSelectionRange(),n.selection.isEmpty()?(o=n.getCursorPosition(),n.session.insert(o," ~~~~ "),n.focus(),n.selection.moveTo(o.row,o.column+3)):(e=n.getSelectionRange(),o=n.session.getTextRange(e),n.session.replace(e,"~~"+o+"~~"),t.end.column+=4,n.focus(),n.selection.setSelectionRange(t))},readOnly:!0}),c.commands.addCommand({name:"markdownToHorizontal",bindKey:{win:"Ctrl-H",mac:"Command-H"},exec:function(e){p(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToH1",bindKey:{win:"Ctrl-Alt-1",mac:"Command-Option-1"},exec:function(e){w(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToH2",bindKey:{win:"Ctrl-Alt-2",mac:"Command-Option-3"},exec:function(e){v(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToH3",bindKey:{win:"Ctrl-Alt-3",mac:"Command-Option-3"},exec:function(e){k(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToPre",bindKey:{win:"Ctrl-Alt-P",mac:"Command-Option-P"},exec:function(e){C(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToCode",bindKey:{win:"Ctrl-Alt-C",mac:"Command-Option-C"},exec:function(e){h(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToBlockQuote",bindKey:{win:"Ctrl-Q",mac:"Command-Shift-K"},exec:function(e){y(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToUnorderedList",bindKey:{win:"Ctrl-U",mac:"Command-U"},exec:function(e){T(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToOrderedList",bindKey:{win:"Ctrl-Shift+O",mac:"Command-Option-O"},exec:function(e){S(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToLink",bindKey:{win:"Ctrl-L",mac:"Command-L"},exec:function(e){b(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToImageLink",bindKey:{win:"Ctrl-Shift-I",mac:"Command-Option-I"},exec:function(e){R(e)},readOnly:!0}),"true"===i.mention&&c.commands.addCommand({name:"markdownToMention",bindKey:{win:"Ctrl-M",mac:"Command-M"},exec:function(e){x(e)},readOnly:!0}),E(".markdown-bold[data-field-name="+s+"]").click(function(){f(c)}),E(".markdown-italic[data-field-name="+s+"]").click(function(){g(c)}),E(".markdown-horizontal[data-field-name="+s+"]").click(function(){p(c)}),E(".markdown-h1[data-field-name="+s+"]").click(function(){w(c)}),E(".markdown-h2[data-field-name="+s+"]").click(function(){v(c)}),E(".markdown-h3[data-field-name="+s+"]").click(function(){k(c)}),E(".markdown-pre[data-field-name="+s+"]").click(function(){C(c)}),E(".markdown-code[data-field-name="+s+"]").click(function(){h(c)}),E(".markdown-blockquote[data-field-name="+s+"]").click(function(){y(c)}),E(".markdown-unordered-list[data-field-name="+s+"]").click(function(){T(c)}),E(".markdown-ordered-list[data-field-name="+s+"]").click(function(){S(c)}),E(".markdown-link[data-field-name="+s+"]").click(function(){b(c)}),E(".markdown-image-link[data-field-name="+s+"]").click(function(){R(c)});n=E(".markdown-direct-mention[data-field-name="+s+"]"),a=E(".markdown-image-upload[data-field-name="+s+"]");"true"===i.mention?n.click(function(){x(c)}):(n.remove(),E(".markdown-reference tbody tr")[1].remove()),"true"===i.imgur?a.on("change",function(e){var n,o;e.preventDefault(),n=c,e=E("#"+t).closest("form").get(0),o=n.container.id.replace("martor-",""),(e=new FormData(e)).append("csrfmiddlewaretoken",P(r.data("csrf-cookie-name"))),E.ajax({url:r.data("upload-url"),type:"POST",data:e,async:!0,cache:!1,contentType:!1,enctype:"multipart/form-data",processData:!1,beforeSend:function(){console.log("Uploading..."),E(".upload-progress[data-field-name="+o+"]").show()},success:function(e){E(".upload-progress[data-field-name="+o+"]").hide(),200==e.status?(console.log(e),R(n,imageData={name:e.name,link:e.link})):alert(e.error)},error:function(e){console.log("error",e),E(".upload-progress[data-field-name="+o+"]").hide()}})}):a.remove(),E(".markdown-help[data-field-name="+s+"]").click(function(){E(".modal-help-guide[data-field-name="+s+"]").modal("show")}),o.find(".ui.martor-toolbar .ui.dropdown").dropdown(),o.find(".ui.tab-martor-menu .item").tab();function O(){E(document.body).removeClass("overflow"),E(this).attr({title:"Full Screen"}),E(this).find(".minimize.icon").removeClass("minimize").addClass("maximize"),E(".main-martor-fullscreen").find(".martor-preview").removeAttr("style"),o.removeClass("main-martor-fullscreen"),j.removeAttr("style"),c.resize()}var j=E(".martor-field-"+s),a=E(".markdown-toggle-maximize[data-field-name="+s+"]");a.on("click",function(){!function(e){e.attr({title:"Minimize"}),e.find(".maximize.icon").removeClass("maximize").addClass("minimize"),o.addClass("main-martor-fullscreen");var n=document.body.clientHeight-90;j.attr({style:"height:"+n+"px"}),E(".main-martor-fullscreen").find(".martor-preview").attr({style:"overflow-y: auto;height:"+n+"px"}),c.resize(),e.one("click",O),E(document.body).addClass("overflow")}(E(this))}),E(document).keyup(function(e){27==e.keyCode&&o.hasClass("main-martor-fullscreen")&&E(".minimize.icon").trigger("click")}),E(".markdown-emoji[data-field-name="+s+"]").click(function(){var t=E(".modal-emoji[data-field-name="+s+"]"),o="undefined"!=typeof emojis?emojis:[],i=t.find(".emoji-content-body"),a=t.find(".emoji-loader-init");i.html(""),a.show(),t.modal({onVisible:function(){for(var e=0;e
'+o[e]+"
"),E('a[data-emoji-target="'+o[e]+'"]').click(function(){var e,n,o;e=c,n=E(this).data("emoji-target"),o=e.getCursorPosition(),e.session.insert(o," "+n+" "),e.focus(),e.selection.moveTo(o.row,o.column+n.length+2),t.modal("hide",100)})}a.hide(),t.modal("refresh")}}).modal("show")}),c.setValue(r.val(),-1)})},E(function(){E(".main-martor").martor()}),"django"in window&&"jQuery"in window.django&&django.jQuery(document).on("formset:added",function(e,n){setTimeout(function(){n.find(".main-martor").each(function(){var e=(e=n.attr("id")).substr(e.lastIndexOf("-")+1),e=E(this.outerHTML.replace(/__prefix__/g,e));E(this).replaceWith(e),e.martor()})},1e3)})}(jQuery);
diff --git a/martor/widgets.py b/martor/widgets.py
index 6b8c076f..c68aed75 100644
--- a/martor/widgets.py
+++ b/martor/widgets.py
@@ -18,6 +18,7 @@
MARTOR_THEME,
MARTOR_TOOLBAR_BUTTONS,
MARTOR_UPLOAD_URL,
+ MARTOR_CSRF_COOKIE_NAME,
)
@@ -40,6 +41,7 @@ def render(self, name, value, attrs=None, renderer=None, **kwargs):
attributes_to_pass = {
"data-enable-configs": MARTOR_ENABLE_CONFIGS,
"data-markdownfy-url": reverse("martor_markdownfy"),
+ "data-csrf-cookie-name": MARTOR_CSRF_COOKIE_NAME,
}
if MARTOR_UPLOAD_URL:
@@ -51,6 +53,7 @@ def render(self, name, value, attrs=None, renderer=None, **kwargs):
if MARTOR_MARKDOWNIFY_TIMEOUT:
attributes_to_pass["data-save-timeout"] = MARTOR_MARKDOWNIFY_TIMEOUT
+
# Make sure that the martor value is in the class attr passed in
if "class" in attrs:
attrs["class"] += " martor"