From fd169b39e6b4b6f5b14bab783a6474dada913fc9 Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 23 Apr 2017 17:19:03 +0200 Subject: [PATCH 1/3] Bootstrap fix --- dev.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev.xml b/dev.xml index 8d5e8c9..feab1cc 100644 --- a/dev.xml +++ b/dev.xml @@ -47,7 +47,7 @@ sudo sed -i '$a workon django-markdownx' ~/.bashrc cd /srv/django-markdownx/ npm install npm run dist -./manage.py migrate +python manage.py migrate echo -e '\e[33;1;5mDONE!\e[0m \e[33;1;3m Connect using "vagrant ssh" \e[0m' From 98b9d3def66d1ffc76cf82b840c5cfe0af98d5ae Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 23 Apr 2017 18:13:37 +0200 Subject: [PATCH 2/3] setuptools related --- markdownx/__init__.py | 9 +++++---- setup.py | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/markdownx/__init__.py b/markdownx/__init__.py index 483a82c..e1e3d10 100755 --- a/markdownx/__init__.py +++ b/markdownx/__init__.py @@ -35,8 +35,8 @@ Key features * Multiple editors per page. * Django Admin support. -.. image:: https://github.com/adi-/django-markdownx/raw/master/django-markdownx-preview.gif?raw=true - :target: https://github.com/adi-/django-markdownx +.. image:: https://github.com/neutronX/django-markdownx/raw/master/django-markdownx-preview.gif?raw=true + :target: https://github.com/neutronX/django-markdownx :align: center :alt: django-markdownx preview @@ -44,7 +44,7 @@ Key features .. _Django: https://www.djangoproject.com .. |PyPi_Status| image:: https://img.shields.io/pypi/status/django-markdownx.svg -.. |Build_Status| image:: https://img.shields.io/travis/adi-/django-markdownx.svg +.. |Build_Status| image:: https://img.shields.io/travis/neutronX/django-markdownx.svg .. |Format| image:: https://img.shields.io/pypi/format/django-markdownx.svg .. |Supported_versions_of_Python| image:: https://img.shields.io/pypi/pyversions/django-markdownx.svg .. |Supported_versions_of_Django| image:: https://img.shields.io/badge/Django-1.8,%201.9,%201.10-green.svg @@ -61,7 +61,8 @@ Key features # ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~= # Documentations # ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- -__author__ = 'Adi' +__author__ = 'aaadeji' +__author_email__ = 'aaadeji@gmail.com' __description__ = 'A comprehensive Markdown editor built for Django.' __credits__ = 'Adi, Pouria Hadjibagheri' __copyright__ = 'Copyright 2017' diff --git a/setup.py b/setup.py index e362760..1217d18 100755 --- a/setup.py +++ b/setup.py @@ -50,6 +50,7 @@ if 'vagrant' in str(environ): def get_meta(): values = { 'author', + 'author_email', 'description', 'credits', 'copyright', @@ -97,11 +98,12 @@ setup( version=metadata.get('version'), packages=find_packages(), author=metadata.get('author'), + author_email=metadata.get('author_email'), maintainer=metadata.get('maintainer'), include_package_data=True, description=metadata.get('description'), long_description=metadata.get('doc'), - url='https://github.com/adi-/django-markdownx', + url='https://github.com/neutronX/django-markdownx', license=metadata.get('license'), classifiers=[ 'Development Status :: 5 - Production/Stable', @@ -111,6 +113,7 @@ setup( 'Framework :: Django :: 1.8', 'Framework :: Django :: 1.9', 'Framework :: Django :: 1.10', + 'Framework :: Django :: 1.11', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', From 139b9a453b65153f58a21e0317469d8a59e8e0f3 Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 23 Apr 2017 18:13:48 +0200 Subject: [PATCH 3/3] static files --- markdownx/static/markdownx/js/markdownx.js | 278 +++++++++++------- .../static/markdownx/js/markdownx.min.js | 2 +- 2 files changed, 165 insertions(+), 115 deletions(-) diff --git a/markdownx/static/markdownx/js/markdownx.js b/markdownx/static/markdownx/js/markdownx.js index 411b6ab..0f74912 100644 --- a/markdownx/static/markdownx/js/markdownx.js +++ b/markdownx/static/markdownx/js/markdownx.js @@ -14,6 +14,8 @@ * JavaScript ECMA 5 files formatted as `.js` are trans-compiled files. Please do not edit such files as all * changes will be lost. Please modify `.ts` stored in `django-markdownx/markdownx/.static/markdownx/js` directory. * See **Contributions** in the documentations for additional instructions. + * + * @Copyright 2017 - Adi, Pouria Hadjibagheri. */ // Import, definitions and constant ------------------------------------------------------------------------------------ "use strict"; @@ -39,7 +41,7 @@ var EventHandlers = { }, /** * - * @param event + * @param {DragEvent} event * returns {Event} */ onDragEnter: function (event) { @@ -52,7 +54,7 @@ var EventHandlers = { */ var keyboardEvents = { /** - * + * Custom hotkeys. */ keys: { TAB: "Tab", @@ -61,11 +63,13 @@ var keyboardEvents = { INDENT: "]" }, /** - * + * Hotkey response functions. */ handlers: { /** + * Smart application of tab indentations under various conditions. * + * @param {JSON} properties * @returns {string} */ applyTab: function (properties) { @@ -84,84 +88,9 @@ var keyboardEvents = { ); }, /** + * Smart removal of tab indentations. * - * @returns {string} - */ - _multiLineIndentation: function (properties) { - // Last line in the selection; regardless of - // where of not the entire line is selected. - var endLine = new RegExp("(?:\n|.){0," + properties.end + "}(^.*$)", "m") - .exec(properties.value)[1]; - // Do not replace with variables; this - // feature is optimised for swift response. - return properties.value.substring( - // First line of the selection, regardless of - // where or not the entire line is selected. - properties.value.indexOf(new RegExp("(?:\n|.){0," + properties.start + "}(^.*$)", "m") - .exec(properties.value)[1] // Start line. - ), ( - // If there is a last line in a multi line selected - // value where the last line is not empty or `\n`: - properties.value.indexOf(endLine) ? - // Location where the last line finishes with - // respect to the entire value. - properties.value.indexOf(endLine) + endLine.length : - // Otherwise, where the selection ends. - properties.end)); - }, - /** - * - * @returns {string} - */ - applyIndentation: function (properties) { - // Single line? - if (properties.start === properties.end) { - // Current line, from the beginning to the end, regardless of any selections. - var line = new RegExp("(?:\n|.){0," + properties.start + "}(^.+$)", "m") - .exec(properties.value)[1]; - return properties.value.replace(line, "\t" + line); - } - // Multi line - var content = this._multiLineIndentation({ - start: properties.start, - end: properties.end, - value: properties.value - }); - return properties.value - .replace(content, // Existing contents. - content.replace(/(^.+$)\n*/gmi, "\t$&") // Indented contents. - ); - }, - /** - * - * @returns {string} - */ - removeIndentation: function (properties) { - // Single Line - if (properties.start === properties.end) { - // Entire line where the line immediately begins - // with a one or more `\t`, regardless of any - // selections. - var line = new RegExp("(?:\n|.){0," + properties.start + "}(^\t.+$)", "m") - .exec(properties.value)[1]; - return properties.value - .replace(line, // Existing content. - line.substring(1) // First character (necessarily a `\t`) removed. - ); - } - // Multi line - var content = this._multiLineIndentation({ - start: properties.start, - end: properties.end, - value: properties.value - }); - return properties.value - .replace(content, // Existing content. - content.replace(/^\t(.+)\n*$/gmi, "$1") // A single `\t` removed from the beginning. - ); - }, - /** - * + * @param {JSON} properties * @returns {string} */ removeTab: function (properties) { @@ -199,7 +128,93 @@ var keyboardEvents = { substitution; }, /** + * Handles multi line indentations. * + * @param {JSON} properties + * @returns {string} + * @private + */ + _multiLineIndentation: function (properties) { + // Last line in the selection; regardless of + // where of not the entire line is selected. + var endLine = new RegExp("(?:\n|.){0," + properties.end + "}(^.*$)", "m") + .exec(properties.value)[1]; + // Do not replace with variables; this + // feature is optimised for swift response. + return properties.value.substring( + // First line of the selection, regardless of + // whether or not the entire line is selected. + properties.value.indexOf(new RegExp("(?:\n|.){0," + properties.start + "}(^.*$)", "m") + .exec(properties.value)[1] // Start line. + ), ( + // If there is a last line in a multi line selected + // value where the last line is not empty or `\n`: + properties.value.indexOf(endLine) ? + // Location where the last line finishes with + // respect to the entire value. + properties.value.indexOf(endLine) + endLine.length : + // Otherwise, where the selection ends. + properties.end)); + }, + /** + * Smart application of indentation at the beginning of the line. + * + * @param {JSON} properties + * @returns {string} + */ + applyIndentation: function (properties) { + // Single line? + if (properties.start === properties.end) { + // Current line, from the beginning to the end, regardless of any selections. + var line = new RegExp("(?:\n|.){0," + properties.start + "}(^.+$)", "m") + .exec(properties.value)[1]; + return properties.value.replace(line, "\t" + line); + } + // Multi line + var content = this._multiLineIndentation({ + start: properties.start, + end: properties.end, + value: properties.value + }); + return properties.value + .replace(content, // Existing contents. + content.replace(/(^.+$)\n*/gmi, "\t$&") // Indented contents. + ); + }, + /** + * Smart removal of indentation from the beginning of the line. + * + * @param {JSON} properties + * @returns {string} + */ + removeIndentation: function (properties) { + // Single Line + if (properties.start === properties.end) { + // Entire line where the line immediately begins + // with a one or more `\t`, regardless of any + // selections. + var line = new RegExp("(?:\n|.){0," + properties.start + "}(^\t.+$)", "m") + .exec(properties.value)[1]; + return properties.value + .replace(line, // Existing content. + line.substring(1) // First character (necessarily a `\t`) removed. + ); + } + // Multi line + var content = this._multiLineIndentation({ + start: properties.start, + end: properties.end, + value: properties.value + }); + return properties.value + .replace(content, // Existing content. + content.replace(/^\t(.+)\n*$/gmi, "$1") // A single `\t` removed from the beginning. + ); + }, + /** + * Duplication of the current or selected lines. + * + * @param {JSON} properties * @returns {string} */ applyDuplication: function (properties) { @@ -236,6 +251,7 @@ var keyboardEvents = { }, }, /** + * Mapping of hotkeys from keyboard events to their corresponding functions. * * @param {KeyboardEvent} event * @returns {Function | Boolean} @@ -255,11 +271,14 @@ var keyboardEvents = { // Is CTRL or CMD (on Mac) pressed? return (event.ctrlKey || event.metaKey) ? this.handlers.removeIndentation : false; default: + // default would prevent the + // inhibition of default settings. return false; } } }; /** + * Get either the height of an element as defined in style/CSS or its browser-computed height. * * @param {HTMLElement} element * @returns {number} @@ -271,6 +290,7 @@ function getHeight(element) { ); } /** + * Update the height of an element based on its scroll height. * * @param {HTMLTextAreaElement} editor * @returns {HTMLTextAreaElement} @@ -285,10 +305,13 @@ function updateHeight(editor) { /** * @example * - * let editor = document.getElementById('MyMarkdownEditor'), - * preview = document.getElementById('MyMarkdownPreview'); + * let element = document.getElementsByClassName('markdownx'); * - * let mdx = new MarkdownX(editor, preview) + * new MarkdownX( + * element, + * element.querySelector('.markdownx-editor'), + * element.querySelector('.markdownx-preview') + * ) * * @param {HTMLElement} parent - Markdown editor element. * @param {HTMLTextAreaElement} editor - Markdown editor element. @@ -296,6 +319,9 @@ function updateHeight(editor) { */ var MarkdownX = function (parent, editor, preview) { var _this = this; + /** + * MarkdownX properties. + */ var properties = { editor: editor, preview: preview, @@ -303,6 +329,12 @@ var MarkdownX = function (parent, editor, preview) { _latency: null, _editorIsResizable: null }; + /** + * Initialisation settings (mounting events, retrieval of initial data, + * setting animation properties, latency, timeout, and resizability). + * + * @private + */ var _initialize = function () { _this.timeout = null; // Events @@ -327,9 +359,6 @@ var MarkdownX = function (parent, editor, preview) { { type: "compositionstart", capture: true, listener: onKeyDown } ] }; - // If not `max-height` is defined, it will default to 75% of the total height. - if (!editor.style.maxHeight) - editor.style.maxHeight = window.innerHeight * 75 / 100 + "px"; // Initialise // -------------------------------------------------------- // Mounting the defined events. @@ -347,7 +376,7 @@ var MarkdownX = function (parent, editor, preview) { utils_1.triggerCustomEvent("markdownx.init"); }; /** - * settings for ``timeout``. + * settings for `timeout`. * * @private */ @@ -356,7 +385,7 @@ var MarkdownX = function (parent, editor, preview) { _this.timeout = setTimeout(getMarkdown, properties._latency); }; /** - * + * Handling changes in the editor. */ var inputChanged = function () { properties.editor = properties._editorIsResizable ? @@ -364,6 +393,7 @@ var MarkdownX = function (parent, editor, preview) { return _markdownify(); }; /** + * Handling of drop events (when a file is dropped into `properties.editor`). * * @param {DragEvent} event */ @@ -375,6 +405,7 @@ var MarkdownX = function (parent, editor, preview) { EventHandlers.inhibitDefault(event); }; /** + * Handling of keyboard events (i.e. primarily hotkeys). * * @param {KeyboardEvent} event * @returns {Boolean | null} @@ -398,8 +429,9 @@ var MarkdownX = function (parent, editor, preview) { return false; }; /** + * Uploading the `file` onto the server through an AJAX request. * - * @param file + * @param {File} file */ var sendFile = function (file) { properties.editor.style.opacity = UPLOAD_START_OPACITY; @@ -432,7 +464,9 @@ var MarkdownX = function (parent, editor, preview) { return xhr.send(); }; /** - * + * Uploading the markdown text from `properties.editor` onto the server + * through an AJAX request, and upon receiving the HTML encoded text + * in response, the response will be display in `properties.preview`. */ var getMarkdown = function () { var xhr = new utils_1.Request(properties.editor.getAttribute(PROCESSING_URL_ATTRIBUTE), // URL @@ -450,6 +484,8 @@ var MarkdownX = function (parent, editor, preview) { return xhr.send(); }; /** + * Inserts markdown encoded image URL into `properties.editor` where + * the cursor is located. * * @param textToInsert */ @@ -536,9 +572,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); /** * Looks for a cookie, and if found, returns the values. * - * NOTE: Only the first item in the array is returned - * to eliminate the need for array deconstruction in - * the target. + * ... note:: Only the first item in the array is returned + * to eliminate the need for array deconstruction + * in the target. * * @param {string} name - The name of the cookie. * @returns {string | null} @@ -592,16 +628,18 @@ function mountEvents() { collections[_i] = arguments[_i]; } return collections.map(function (events) { - return events.listeners.map(function (series) { - return events.object.addEventListener(series.type, series.listener, series.capture); + return events.listeners + .map(function (series) { + return events.object + .addEventListener(series.type, series.listener, series.capture); }); }); } exports.mountEvents = mountEvents; /** * - * @param data - * @param csrf + * @param {JSON} data + * @param {Boolean} csrf * @returns {FormData} */ function preparePostData(data, csrf) { @@ -613,7 +651,12 @@ function preparePostData(data, csrf) { return form; } exports.preparePostData = preparePostData; -var AJAXRequest = function () { +/** + * + * @returns {XMLHttpRequest} + * @throws TypeError - AJAX request is not supported. + */ +function AJAXRequest() { // Chrome, Firefox, IE7+, Opera, Safari // and everything else that has come post 2010. if ("XMLHttpRequest" in window) @@ -637,7 +680,7 @@ var AJAXRequest = function () { // Just throw the computer outta the window! alert("Your browser belongs to history!"); throw new TypeError("This browser does not support AJAX requests."); -}; +} /** * Handles AJAX POST requests. */ @@ -708,21 +751,21 @@ var Request = (function () { exports.Request = Request; /** * - * @param el - * @param type + * @param {Element} element + * @param {string} type */ -function triggerEvent(el, type) { +function triggerEvent(element, type) { // modern browsers, IE9+ - var e = document.createEvent('HTMLEvents'); - e.initEvent(type, false, true); - el.dispatchEvent(e); + var event = document.createEvent('HTMLEvents'); + event.initEvent(type, false, true); + element.dispatchEvent(event); } exports.triggerEvent = triggerEvent; /** * - * @param type - * @param element - * @param args + * @param {string} type + * @param {Element | Document} element + * @param {any} args */ function triggerCustomEvent(type, element, args) { if (element === void 0) { element = document; } @@ -732,15 +775,19 @@ function triggerCustomEvent(type, element, args) { element.dispatchEvent(event); } exports.triggerCustomEvent = triggerCustomEvent; +/** + * + * @param {Element} element + * @param {string[]} className + */ function addClass(element) { var className = []; for (var _i = 1; _i < arguments.length; _i++) { className[_i - 1] = arguments[_i]; } className.map(function (cname) { - if (element.classList) { + if (element.classList) element.classList.add(cname); - } else { var classes = element.className.split(' '); if (classes.indexOf(cname) < 0) @@ -750,18 +797,21 @@ function addClass(element) { }); } exports.addClass = addClass; +/** + * + * @param {Element} element + * @param {string[]} className + */ function removeClass(element) { var className = []; for (var _i = 1; _i < arguments.length; _i++) { className[_i - 1] = arguments[_i]; } className.map(function (cname) { - if (element.classList) { + if (element.classList) element.classList.remove(cname); - } else { - var classes = element.className.split(' '); - var idx = classes.indexOf(cname); + var classes = element.className.split(' '), idx = classes.indexOf(cname); if (idx > -1) classes.splice(idx, 1); element.className = classes.join(' '); diff --git a/markdownx/static/markdownx/js/markdownx.min.js b/markdownx/static/markdownx/js/markdownx.min.js index 74e8921..c4c3e95 100644 --- a/markdownx/static/markdownx/js/markdownx.min.js +++ b/markdownx/static/markdownx/js/markdownx.min.js @@ -1 +1 @@ -(function e(t,r,n){function a(s,o){if(!r[s]){if(!t[s]){var u=typeof require=="function"&&require;if(!o&&u)return u(s,!0);if(i)return i(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var c=r[s]={exports:{}};t[s][0].call(c.exports,function(e){var r=t[s][1][e];return a(r?r:e)},c,c.exports,e,t,r,n)}return r[s].exports}var i=typeof require=="function"&&require;for(var s=0;s0&&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},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){if(e.scrollTop)e.style.height=e.scrollTop+v(e)+"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}]},r={object:m.editor,listeners:[{type:"drop",capture:false,listener:b},{type:"input",capture:true,listener:x},{type:"keydown",capture:true,listener:w},{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:w}]};if(!t.style.maxHeight)t.style.maxHeight=window.innerHeight*75/100+"px";n.mountEvents(r,e);m.editor.style.transition="opacity 1s ease";m.editor.style.webkitTransition="opacity 1s ease";m._latency=Math.max(parseInt(m.editor.getAttribute(o))||0,u);m._editorIsResizable=(m.editor.getAttribute(s).match(/true/i)||[]).length>0;T();n.triggerCustomEvent("markdownx.init")};var y=function(){clearTimeout(v.timeout);v.timeout=setTimeout(T,m._latency)};var x=function(){m.editor=m._editorIsResizable?h(m.editor):m.editor;return y()};var b=function(e){if(e.dataTransfer&&e.dataTransfer.files.length)Object.keys(e.dataTransfer.files).map(function(t){return E(e.dataTransfer.files[t])});f.inhibitDefault(e)};var w=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();m.editor.selectionEnd=m.editor.selectionStart=r;return false};var E=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){k(t.image_code);n.triggerCustomEvent("markdownx.fileUploadEnd",m.parent,[t])}else if(t.image_path){k('![]("'+t.image_path+'")');n.triggerCustomEvent("markdownx.fileUploadEnd",m.parent,[t])}else{console.error(l,t);n.triggerCustomEvent("markdownx.fileUploadError",m.parent,[t]);return null}m.editor.style.opacity=d};t.error=function(e){m.editor.style.opacity=d;console.error(e);n.triggerCustomEvent("fileUploadError",m.parent,[e])};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=h(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 k=function(e){m.editor.value=m.editor.value.substring(0,m.editor.selectionStart)+"\n\n"+e+("\n\n"+m.editor.value.substring(m.editor.selectionEnd));m.editor.selectionStart=m.editor.selectionEnd=m.editor.selectionStart+e.length;n.triggerEvent(m.editor,"keyup");x()};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 s=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){return new m(e[t],e[t].querySelector(".markdownx-editor"),e[t].querySelector(".markdownx-preview"))})})},{"./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.split(";").filter(function(t){return t.indexOf(e+"=")!==-1})[0];try{return decodeURIComponent(t.trim().substring(e.length+1))}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]); \ No newline at end of file +(function e(t,r,n){function a(o,s){if(!r[o]){if(!t[o]){var u=typeof require=="function"&&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?r:e)},c,c.exports,e,t,r,n)}return r[o].exports}var i=typeof require=="function"&&require;for(var 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=this._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=this._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){if(e.scrollTop)e.style.height=e.scrollTop+v(e)+"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:"drop",capture:false,listener:x},{type:"input",capture:true,listener:b},{type:"keydown",capture:true,listener:w},{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:w}]};n.mountEvents(t,e);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;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.dataTransfer&&e.dataTransfer.files.length)Object.keys(e.dataTransfer.files).map(function(t){return E(e.dataTransfer.files[t])});f.inhibitDefault(e)};var w=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();m.editor.selectionEnd=m.editor.selectionStart=r;return false};var E=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){k(t.image_code);n.triggerCustomEvent("markdownx.fileUploadEnd",m.parent,[t])}else if(t.image_path){k('![]("'+t.image_path+'")');n.triggerCustomEvent("markdownx.fileUploadEnd",m.parent,[t])}else{console.error(l,t);n.triggerCustomEvent("markdownx.fileUploadError",m.parent,[t]);return null}m.editor.style.opacity=d};t.error=function(e){m.editor.style.opacity=d;console.error(e);n.triggerCustomEvent("fileUploadError",m.parent,[e])};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=h(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 k=function(e){m.editor.value=m.editor.value.substring(0,m.editor.selectionStart)+"\n\n"+e+("\n\n"+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){return new m(e[t],e[t].querySelector(".markdownx-editor"),e[t].querySelector(".markdownx-preview"))})})},{"./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.split(";").filter(function(t){return t.indexOf(e+"=")!==-1})[0];try{return decodeURIComponent(t.trim().substring(e.length+1))}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]); \ No newline at end of file