text: /**
   * Name         : Martor v1.4.7
   * Created by   : Agus Makmun (Summon Agus)
   * Release date : 17-Feb-2020
   * License      : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
   * Repository   : https://github.com/agusmakmun/django-markdown-editor
  **/
  
  !function(e){e||(e=django.jQuery),e.fn.martor=function(){e(".martor").trigger("martor.init");var n=function(e){var n=null,o=0;if(document.cookie&&""!==document.cookie)for(var t=document.cookie.split(";");o<t.length;o++){var a=jQuery.trim(t[o]);if(a.substring(0,e.length+1)===e+"="){n=decodeURIComponent(a.substring(e.length+1));break}}return n};this.each(function(o,t){var a=e(t),i=a.data("field-name"),s=e("#id_"+i),r="martor-"+i,c=ace.edit(r),l=JSON.parse(s.data("enable-configs").replace(/'/g,'"'));c.setTheme("ace/theme/github"),c.getSession().setMode("ace/mode/markdown"),c.getSession().setUseWrapMode(!0),c.$blockScrolling=1/0,c.renderer.setScrollMargin(10,10),c.setAutoScrollEditorIntoView(!0),c.setShowPrintMargin(!1),c.setOptions({enableBasicAutocompletion:!0,enableSnippets:!0,enableLiveAutocompletion:!0,enableMultiselect:!1}),"true"==l.living&&e(t).addClass("enable-living");var m={getCompletions:function(e,n,o,t,a){var i="undefined"!=typeof emojis?emojis:[],s=e.getSession().getTokenAt(o.row,o.column.count).value.split(/\s+/);":"==s[s.length-1][0]&&a(null,i.map(function(e){return{caption:e,value:e.replace(":","")+" ",meta:"emoji"}}))}},d={getCompletions:function(o,t,a,i,r){var c=o.getSession().getTokenAt(a.row,a.column.count).value.split(/\s+/),l=c[c.length-1];"@"==l[0]&&"["==l[1]&&(username=l.replace(/([\@\[\/\]\/])/g,""),e.ajax({url:s.data("search-users-url"),data:{username:username,csrfmiddlewaretoken:n("csrftoken")},success:function(e){if(200==e.status){for(var n=[],o=0;o<e.data.length;o++)n.push(e.data[o].username);r(null,n.map(function(e){return{caption:e,value:e,meta:"username"}}))}}}))}};"true"===l.mention?c.completers=[m,d]:c.completers=[m],s.attr({style:"display:none"}),e(t).find(".martor-toolbar").find(".markdown-selector").attr({"data-field-name":i}),e(t).find(".upload-progress").attr({"data-field-name":i}),e(t).find(".modal-help-guide").attr({"data-field-name":i}),e(t).find(".modal-emoji").attr({"data-field-name":i}),c.on("change",function(e){var n=c.getValue();s.val(n)}),e("#"+r).resizable({direction:"bottom",stop:function(){c.resize()}});var u=e(".tab.segment[data-tab=preview-tab-"+i+"]"),f=e(".item[data-tab=preview-tab-"+i+"]"),g=function(){var o=s.val(),t=new FormData;t.append("content",o),t.append("csrfmiddlewaretoken",n("csrftoken")),u.addClass("martor-preview-stale"),e.ajax({url:s.data("markdownfy-url"),type:"POST",data:t,processData:!1,contentType:!1,success:function(n){n?("true"==l.hljs&&e("pre").each(function(e,n){hljs.highlightBlock(n)}),u.html(n).removeClass("martor-preview-stale"),e(document).trigger("martor:preview",[u])):u.html("<p>Nothing to preview</p>")},error:function(e){console.log("error",e)}})};if(g(),"true"!==l.living?f.click(function(){e(this).closest(".tab-martor-menu").find(".martor-toolbar").hide(),g()}):c.on("change",g),e(".item[data-tab=editor-tab-"+i+"]").click(function(){e(this).closest(".tab-martor-menu").find(".martor-toolbar").show()}),"true"==l.spellcheck)try{enable_spellcheck(r)}catch(e){console.log("Spellcheck lib doesn't installed.")}var v=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o," **** "),e.focus(),e.selection.moveTo(o.row,o.column+3)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"**"+a+"**"),n.end.column+=4,e.focus(),e.selection.setSelectionRange(n)}},p=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o," __ "),e.focus(),e.selection.moveTo(o.row,o.column+2)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"_"+a+"_"),n.end.column+=2,e.focus(),e.selection.setSelectionRange(n)}},w=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o,"\n\n----------\n\n"),e.focus(),e.selection.moveTo(o.row+4,o.column+10)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"\n\n----------\n\n"+a),e.focus(),e.selection.moveTo(n.end.row+4,n.end.column+10)}},k=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o,"\n\n# "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"\n\n# "+a+"\n"),e.focus(),e.selection.moveTo(n.end.row+2,n.end.column+2)}},C=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o,"\n\n## "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"\n\n## "+a+"\n"),e.focus(),e.selection.moveTo(n.end.row+2,n.end.column+3)}},h=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o,"\n\n### "),e.focus(),e.selection.moveTo(o.row+2,o.column+4)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"\n\n### "+a+"\n"),e.focus(),e.selection.moveTo(n.end.row+2,n.end.column+4)}},y=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o,"\n\n```\n\n```\n"),e.focus(),e.selection.moveTo(o.row+3,o.column)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"\n\n```\n"+a+"\n```\n"),e.focus(),e.selection.moveTo(n.end.row+3,n.end.column+3)}},T=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o," `` "),e.focus(),e.selection.moveTo(o.row,o.column+2)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"`"+a+"`"),n.end.column+=2,e.focus(),e.selection.setSelectionRange(n)}},S=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o,"\n\n> \n"),e.focus(),e.selection.moveTo(o.row+2,o.column+2)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"\n\n> "+a+"\n"),e.focus(),e.selection.moveTo(n.end.row+2,n.end.column+2)}},b=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o,"\n\n* "),e.focus(),e.selection.moveTo(o.row+2,o.column+2)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"\n\n* "+a),e.focus(),e.selection.moveTo(n.end.row+2,n.end.column+2)}},R=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o,"\n\n1. "),e.focus(),e.selection.moveTo(o.row+2,o.column+3)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"\n\n1. "+a),e.focus(),e.selection.moveTo(n.end.row+2,n.end.column+3)}},x=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o," [](http://) "),e.focus(),e.selection.moveTo(o.row,o.column+2)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"["+a+"](http://) "),e.focus(),e.selection.moveTo(n.end.row,n.end.column+10)}},O=function(e,n){var o=e.getSelectionRange();if(void 0===n)if(e.selection.isEmpty()){var t=e.getCursorPosition();e.session.insert(t," ![](http://) "),e.focus(),e.selection.moveTo(t.row,t.column+3)}else{var a=e.getSelectionRange(),i=e.session.getTextRange(a);e.session.replace(a,"!["+i+"](http://) "),e.focus(),e.selection.moveTo(o.end.row,o.end.column+11)}else{t=e.getCursorPosition();e.session.insert(t,"!["+n.name+"]("+n.link+") "),e.focus(),e.selection.moveTo(t.row,t.column+n.name.length+2)}},j=function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o," @[]"),e.focus(),e.selection.moveTo(o.row,o.column+3)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"@["+a+"]"),e.focus(),e.selection.moveTo(n.end.row,n.end.column+3)}},P=function(e,n){var o=e.getCursorPosition();e.session.insert(o," "+n+" "),e.focus(),e.selection.moveTo(o.row,o.column+n.length+2)},E=function(o){var t=e("#"+r).closest("form").get(0),a=o.container.id.replace("martor-",""),i=new FormData(t);return i.append("csrfmiddlewaretoken",n("csrftoken")),e.ajax({url:s.data("upload-url"),type:"POST",data:i,async:!0,cache:!1,contentType:!1,enctype:"multipart/form-data",processData:!1,beforeSend:function(){console.log("Uploading..."),e(".upload-progress[data-field-name="+a+"]").show()},success:function(n){e(".upload-progress[data-field-name="+a+"]").hide(),200==n.status?(console.log(n),O(o=o,imageData={name:n.name,link:n.link})):alert(n.error)},error:function(n){console.log("error",n),e(".upload-progress[data-field-name="+a+"]").hide()}}),!1};c.commands.addCommand({name:"markdownToBold",bindKey:{win:"Ctrl-B",mac:"Command-B"},exec:function(e){v(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToItalic",bindKey:{win:"Ctrl-I",mac:"Command-I"},exec:function(e){p(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToUnderscores",bindKey:{win:"Ctrl-Shift-U",mac:"Command-Option-U"},exec:function(e){!function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o," ++++ "),e.focus(),e.selection.moveTo(o.row,o.column+3)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"++"+a+"++"),n.end.column+=4,e.focus(),e.selection.setSelectionRange(n)}}(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToStrikethrough",bindKey:{win:"Ctrl-Shift-S",mac:"Command-Option-S"},exec:function(e){!function(e){var n=e.getSelectionRange();if(e.selection.isEmpty()){var o=e.getCursorPosition();e.session.insert(o," ~~~~ "),e.focus(),e.selection.moveTo(o.row,o.column+3)}else{var t=e.getSelectionRange(),a=e.session.getTextRange(t);e.session.replace(t,"~~"+a+"~~"),n.end.column+=4,e.focus(),e.selection.setSelectionRange(n)}}(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToHorizontal",bindKey:{win:"Ctrl-H",mac:"Command-H"},exec:function(e){w(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToH1",bindKey:{win:"Ctrl-Alt-1",mac:"Command-Option-1"},exec:function(e){k(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToH2",bindKey:{win:"Ctrl-Alt-2",mac:"Command-Option-3"},exec:function(e){C(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToH3",bindKey:{win:"Ctrl-Alt-3",mac:"Command-Option-3"},exec:function(e){h(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToPre",bindKey:{win:"Ctrl-Alt-P",mac:"Command-Option-P"},exec:function(e){y(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToCode",bindKey:{win:"Ctrl-Alt-C",mac:"Command-Option-C"},exec:function(e){T(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToBlockQuote",bindKey:{win:"Ctrl-Q",mac:"Command-Q"},exec:function(e){S(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToUnorderedList",bindKey:{win:"Ctrl-U",mac:"Command-U"},exec:function(e){b(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToOrderedList",bindKey:{win:"Ctrl-Shift+O",mac:"Command-Option-O"},exec:function(e){R(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToLink",bindKey:{win:"Ctrl-L",mac:"Command-L"},exec:function(e){x(e)},readOnly:!0}),c.commands.addCommand({name:"markdownToImageLink",bindKey:{win:"Ctrl-Shift-I",mac:"Command-Option-I"},exec:function(e){O(e)},readOnly:!0}),"true"===l.mention&&c.commands.addCommand({name:"markdownToMention",bindKey:{win:"Ctrl-M",mac:"Command-M"},exec:function(e){j(e)},readOnly:!0}),e(".markdown-bold[data-field-name="+i+"]").click(function(){v(c)}),e(".markdown-italic[data-field-name="+i+"]").click(function(){p(c)}),e(".markdown-horizontal[data-field-name="+i+"]").click(function(){w(c)}),e(".markdown-h1[data-field-name="+i+"]").click(function(){k(c)}),e(".markdown-h2[data-field-name="+i+"]").click(function(){C(c)}),e(".markdown-h3[data-field-name="+i+"]").click(function(){h(c)}),e(".markdown-pre[data-field-name="+i+"]").click(function(){y(c)}),e(".markdown-code[data-field-name="+i+"]").click(function(){T(c)}),e(".markdown-blockquote[data-field-name="+i+"]").click(function(){S(c)}),e(".markdown-unordered-list[data-field-name="+i+"]").click(function(){b(c)}),e(".markdown-ordered-list[data-field-name="+i+"]").click(function(){R(c)}),e(".markdown-link[data-field-name="+i+"]").click(function(){x(c)}),e(".markdown-image-link[data-field-name="+i+"]").click(function(){O(c)});var K=e(".markdown-direct-mention[data-field-name="+i+"]"),z=e(".markdown-image-upload[data-field-name="+i+"]");"true"===l.mention&&"true"===l.imgur?(K.click(function(){j(c)}),z.on("change",function(e){e.preventDefault(),E(c)})):"true"===l.mention&&"false"===l.imgur?(K.click(function(){j(c)}),z.remove()):"false"===l.mention&&"true"===l.imgur?(K.remove(),z.on("change",function(e){e.preventDefault(),E(c)})):(K.remove(),z.remove(),e(".markdown-reference tbody tr")[1].remove()),e(".markdown-help[data-field-name="+i+"]").click(function(){e(".modal-help-guide[data-field-name="+i+"]").modal("show")}),a.find(".ui.martor-toolbar .ui.dropdown").dropdown(),a.find(".ui.tab-martor-menu .item").tab();var A=e(".martor-field-"+i),M=e(".markdown-toggle-maximize[data-field-name="+i+"]"),_=function(){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"),a.removeClass("main-martor-fullscreen"),A.removeAttr("style"),c.resize()};M.on("click",function(){!function(n){n.attr({title:"Minimize"}),n.find(".maximize.icon").removeClass("maximize").addClass("minimize"),a.addClass("main-martor-fullscreen");var o=document.body.clientHeight-90;A.attr({style:"height:"+o+"px"}),e(".main-martor-fullscreen").find(".martor-preview").attr({style:"overflow-y: auto;height:"+o+"px"}),c.resize(),n.one("click",_),e(document.body).addClass("overflow")}(e(this))}),e(document).keyup(function(n){27==n.keyCode&&a.hasClass("main-martor-fullscreen")&&e(".minimize.icon").trigger("click")}),e(".markdown-emoji[data-field-name="+i+"]").click(function(){var n=e(".modal-emoji[data-field-name="+i+"]"),o="undefined"!=typeof emojis?emojis:[],t=n.find(".emoji-content-body"),a=n.find(".emoji-loader-init");t.html(""),a.show(),n.modal({onVisible:function(){for(var i=0;i<o.length;i++){var r=s.data("base-emoji-url")+o[i].replace(/:/g,"")+".png";t.append('<div class="four wide column"><p><a data-emoji-target="'+o[i]+'" class="insert-emoji"><img class="marked-emoji" src="'+r+'"> '+o[i]+"</a></p></div>"),e('a[data-emoji-target="'+o[i]+'"]').click(function(){P(c,e(this).data("emoji-target")),n.modal("hide",100)})}a.hide(),n.modal("refresh")}}).modal("show")}),""!=s.val()&&c.setValue(s.val(),-1)})},e(function(){e(".main-martor").martor()}),"django"in window&&"jQuery"in window.django&&django.jQuery(document).on("formset:added",function(n,o){o.find(".main-martor").each(function(){var n=o.attr("id");n=n.substr(n.lastIndexOf("-")+1);var t=e(this.outerHTML.replace(/__prefix__/g,n));e(this).replaceWith(t),t.martor()})})}(jQuery);
  