(function(){function e(t,r,n){function a(o,s){if(!r[o]){if(!t[o]){var u="function"==typeof require&&require;if(!s&&u)return u(o,!0);if(i)return i(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var c=r[o]={exports:{}};t[o][0].call(c.exports,function(e){var r=t[o][1][e];return a(r||e)},c,c.exports,e,t,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o0&&e.value[e.start-1].match(/\t/)!==null?e.start-1:e.start;t=e.value.substring(e.start).replace("\t","")}else if(!r){t=e.value.substring(e.start).replace("\t","")}else{t=e.value.substring(e.start,e.end).replace(/^\t/gm,"")+e.value.substring(e.end)}return e.value.substring(0,e.start)+t},_multiLineIndentation:function(e){var t=new RegExp("(?:\n|.){0,"+e.end+"}(^.*$)","m").exec(e.value)[1];return e.value.substring(e.value.indexOf(new RegExp("(?:\n|.){0,"+e.start+"}(^.*$)","m").exec(e.value)[1]),e.value.indexOf(t)?e.value.indexOf(t)+t.length:e.end)},applyIndentation:function(e){if(e.start===e.end){var t=new RegExp("(?:\n|.){0,"+e.start+"}(^.+$)","m").exec(e.value)[1];return e.value.replace(t,"\t"+t)}var r=p.handlers._multiLineIndentation({start:e.start,end:e.end,value:e.value});return e.value.replace(r,r.replace(/(^.+$)\n*/gim,"\t$&"))},removeIndentation:function(e){if(e.start===e.end){var t=new RegExp("(?:\n|.){0,"+e.start+"}(^\t.+$)","m").exec(e.value)[1];return e.value.replace(t,t.substring(1))}var r=p.handlers._multiLineIndentation({start:e.start,end:e.end,value:e.value});return e.value.replace(r,r.replace(/^\t(.+)\n*$/gim,"$1"))},applyDuplication:function(e){if(e.start!==e.end)return e.value.substring(0,e.start)+e.value.substring(e.start,e.end)+(~e.value.charAt(e.start-1).indexOf("\n")||~e.value.charAt(e.start).indexOf("\n")?"\n":"")+e.value.substring(e.start,e.end)+e.value.substring(e.end);var t=new RegExp("(?:.|\n){0,160}(^.*$)","m"),r="";e.value.replace(t,function(e,t){return r+=t});return e.value.replace(r,r+"\n"+r)}},hub:function(e){switch(e.key){case this.keys.TAB:return e.shiftKey?this.handlers.removeTab:this.handlers.applyTab;case this.keys.DUPLICATE:return e.ctrlKey||e.metaKey?this.handlers.applyDuplication:false;case this.keys.INDENT:return e.ctrlKey||e.metaKey?this.handlers.applyIndentation:false;case this.keys.UNINDENT:return e.ctrlKey||e.metaKey?this.handlers.removeIndentation:false;default:return false}}};function v(e){return Math.max(parseInt(window.getComputedStyle(e).height),parseInt(e.style.height)||0)}function h(e){e.style.height=e.scrollHeight+parseInt(getComputedStyle(e).borderTop)+parseInt(getComputedStyle(e).borderBottom)+"px";return e}var m=function(e,t,r){var v=this;var m={editor:t,preview:r,parent:e,_latency:null,_editorIsResizable:null};var g=function(){v.timeout=null;var e={object:document,listeners:[{type:"drop",capture:false,listener:f.inhibitDefault},{type:"dragover",capture:false,listener:f.inhibitDefault},{type:"dragenter",capture:false,listener:f.inhibitDefault},{type:"dragleave",capture:false,listener:f.inhibitDefault}]},t={object:m.editor,listeners:[{type:"paste",capture:false,listener:x},{type:"drop",capture:false,listener:w},{type:"input",capture:true,listener:b},{type:"keydown",capture:true,listener:E},{type:"focusin",capture:true,listener:b},{type:"dragover",capture:false,listener:f.onDragEnter},{type:"dragenter",capture:false,listener:f.onDragEnter},{type:"dragleave",capture:false,listener:f.inhibitDefault},{type:"compositionstart",capture:true,listener:E}]};n.mountEvents(t,e);m.editor.setAttribute("data-markdownx-init","");m.editor.style.transition="opacity 1s ease";m.editor.style.webkitTransition="opacity 1s ease";m._latency=Math.max(parseInt(m.editor.getAttribute(s))||0,u);m._editorIsResizable=(m.editor.getAttribute(o).match(/true/i)||[]).length>0&&m.editor.offsetHeight>0&&m.editor.offsetWidth>0;T();n.triggerCustomEvent("markdownx.init")};var y=function(){clearTimeout(v.timeout);v.timeout=setTimeout(T,m._latency)};var b=function(){m.editor=m._editorIsResizable?h(m.editor):m.editor;return y()};var x=function(e){if(e.clipboardData&&e.clipboardData.files.length){Object.keys(e.clipboardData.files).map(function(t){return k(e.clipboardData.files[t])});f.inhibitDefault(e)}};var w=function(e){if(e.dataTransfer&&e.dataTransfer.files.length)Object.keys(e.dataTransfer.files).map(function(t){return k(e.dataTransfer.files[t])});f.inhibitDefault(e)};var E=function(e){var t=p.hub(e);if(typeof t!="function")return false;f.inhibitDefault(e);var r=m.editor.selectionStart;m.editor.value=t({start:m.editor.selectionStart,end:m.editor.selectionEnd,value:m.editor.value});y();m.editor.focus();switch(e.key){case p.keys.TAB:if(e.shiftKey){m.editor.selectionEnd=m.editor.selectionStart=r-1}else{m.editor.selectionEnd=m.editor.selectionStart=r+1}break;case p.keys.INDENT:m.editor.selectionEnd=m.editor.selectionStart=r+1;break;case p.keys.UNINDENT:m.editor.selectionEnd=m.editor.selectionStart=r-1;break;default:m.editor.selectionEnd=m.editor.selectionStart=r}return false};var k=function(e){m.editor.style.opacity=c;var t=new n.Request(m.editor.getAttribute(a),n.preparePostData({image:e}));t.success=function(e){var t=JSON.parse(e);if(t.image_code){D(t.image_code);n.triggerCustomEvent("markdownx.fileUploadEnd",m.parent,[t])}else if(t.image_path){D('![]("'+t.image_path+'")');n.triggerCustomEvent("markdownx.fileUploadEnd",m.parent,[t])}else{console.error(l,t);n.triggerCustomEvent("markdownx.fileUploadError",m.parent,[t]);D(l)}m.editor.style.opacity=d};t.error=function(e){console.error(e);n.triggerCustomEvent("fileUploadError",m.parent,[e]);D(l);m.editor.style.opacity=d};return t.send()};var T=function(){var e=new n.Request(m.editor.getAttribute(i),n.preparePostData({content:m.editor.value}));e.success=function(e){m.preview.innerHTML=e;m.editor=m._editorIsResizable?h(m.editor):m.editor;n.triggerCustomEvent("markdownx.update",m.parent,[e])};e.error=function(e){console.error(e);n.triggerCustomEvent("markdownx.updateError",m.parent,[e])};return e.send()};var D=function(e){m.editor.value=""+m.editor.value.substring(0,m.editor.selectionStart)+e+(""+m.editor.value.substring(m.editor.selectionEnd));m.editor.selectionStart=m.editor.selectionEnd=m.editor.selectionStart+e.length;n.triggerEvent(m.editor,"keyup");b()};g()};r.MarkdownX=m;(function(e,t){e=e||"docReady";t=t||window;var r=[],n=false,a=false;var i=function(){if(!n){n=true;r.map(function(e){return e.fn.call(window,e.ctx)});r=[]}};var o=function(){return document.readyState==="complete"?i():null};t[e]=function(e,t){if(n){setTimeout(function(){return e(t)},1);return}else{r.push({fn:e,ctx:t})}if(document.readyState==="complete"){setTimeout(i,1)}else if(!a){document.addEventListener("DOMContentLoaded",i,false);window.addEventListener("load",i,false);a=true}}})("docReady",window);docReady(function(){var e=document.getElementsByClassName("markdownx");return Object.keys(e).map(function(t){var r=e[t],n=r.querySelector(".markdownx-editor"),a=r.querySelector(".markdownx-preview");if(!n.hasAttribute("data-markdownx-init"))return new m(r,n,a)})})},{"./utils":2}],2:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});function n(e){if(document.cookie&&document.cookie.length){var t="; "+document.cookie;var r=t.split("; "+e+"=");if(r.length===2){try{return decodeURIComponent(r.pop().split(";").shift())}catch(t){if(t instanceof TypeError){console.info('No cookie with key "'+e+'". Wrong name?');return null}throw t}}}return null}r.getCookie=n;function a(){var e=[];for(var t=0;t-1)r.splice(n,1);e.className=r.join(" ")}})}r.removeClass=f},{}]},{},[1]);