diff --git a/docs-src/conf.py b/docs-src/conf.py
index c800af1..4a3860a 100644
--- a/docs-src/conf.py
+++ b/docs-src/conf.py
@@ -38,6 +38,7 @@ extensions = [
'sphinx.ext.githubpages',
'classycode',
'sphinxcontrib.autoanysrc',
+ 'sphinx.ext.autosectionlabel'
# 'edit_on_github'
]
diff --git a/docs-src/js/docs/markdownx.rst b/docs-src/js/docs/markdownx.rst
index ab66d44..4372aaf 100644
--- a/docs-src/js/docs/markdownx.rst
+++ b/docs-src/js/docs/markdownx.rst
@@ -1,98 +1,237 @@
MarkdownX
---------
+.. js:data:: GeneralEventHandlers
+
+ :JSON Object: General (document level) event handlers.
+
+ .. js:function:: inhibitDefault(event)
+
+ Routine tasks for event handlers (e.g. default preventions).
+
+ :param Event|KeyboardEvent event: The events to be inhibited.
+ :returns: event
+ :return type: Event
+
+ .. js:function:: onDragEnter (event)
+
+ Upon enter (when a file, e.g. an image, is dragged into the browser),
+ the defualt events are inhibited, and the drop event is set as `copy`.
+
+ :param DragEvent event: Drag event.
+ :returns: Inhibited drag event with `copy` added to the drop event.
+ :return type: Event
+
+
+.. js:data:: keyboardEvents
+
+ :JSON Object: Keyboard events and their handlers.
+
+ .. js:attribute:: TAB
+
+ - (*string*) - represents: ``Tab``
+
+ .. js:attribute:: DUPLICATE
+
+ - (*string*) - represents: ``d``
+
+ .. js:attribute:: UNINDENT
+
+ - (*string*) - represents: ``[``
+
+ .. js:attribute:: INDENT
+
+ - (*string*) - represents: ``]``
+
+ .. js:function:: hub(event)
+
+ Mapping of hotkeys from keyboard events to their corresponding functions.
+
+ :param KeyboardEvent event: Keyboard event to be handled.
+ :return type: Function | Boolean
+
+ .. js:data:: Handlers
+
+ Handler functions, as mapped by :js:func:`hub`.
+
+ :JSON Object: Hotkey response functions.
+
+ .. note::
+ Properties receive a single argument ``properties``, which is an instance of :js:data:`properties`. See the
+ ``markdownx`` class for additional details.
+
+ .. js:function:: applyTab(properties)
+
+ Smart application of tab indentations under various conditions.
+
+ :param JSON properties: See object descriptions for details.
+ :return type: string
+
+ .. js:function:: removeTab(properties)
+
+ Smart removal of tab indentations.
+
+ :param JSON properties: See object descriptions for details.
+ :return type: string
+
+ .. js:function:: _multiLineIndentation(properties)
+
+ **private**
+
+ Handles multi line indentations.
+
+ :param JSON properties: See object descriptions for details.
+ :return type: string
+
+ .. js:function:: applyIndentation(properties)
+
+ Smart application of indentation at the beginning of the line.
+
+ :param JSON properties: See object descriptions for details.
+ :return type: string
+
+ .. js:function:: removeIndentation(properties)
+
+ Smart removal of indentation from the beginning of the line.
+
+ :param JSON properties: See object descriptions for details.
+ :return type: string
+
+ .. js:function:: applyDuplication(properties)
+
+ Duplication of the current or selected lines.
+
+ :param JSON properties: See object descriptions for details.
+ :return type: string
+
+
+.. js:function:: getHeight(element)
+
+ Returns either the height of an element as defined in the ``style`` attribute or CSS or its browser-computed height.
+
+ :param element HTMLElement: The element whose height is to be determined.
+ :returns: Height of the element.
+ :return type: number
+
+
+.. js:function:: updateHeight(element)
+
+ Updates the height of an element based on its scroll height.
+
+ :param HTMLTextAreaElement editor: Editor element whose height is to be updated.
+ :return type: HTMLTextAreaElement
+
.. js:class:: MarkdownX(editor, preview)
- **Example:**
+ MarkdownX initializer.
- .. code-block:: javascript
+ :example:
+ .. code-block:: javascript
- let editor = document.getElementById('MyMarkdownEditor'),
- preview = document.getElementById('MyMarkdownPreview');
+ >>> let parent = document.getElementsByClassName('markdownx'),
+ ... editor = parent.querySelector('.MyMarkdownEditor'),
+ ... preview = parent.querySelector('.MyMarkdownPreview');
- let mdx = new MarkdownX(editor, preview)
+ >>> let mdx = new MarkdownX(parent, editor, preview)
- :param HTMLTextAreaElement editor: Markdown editor element.
- :param HTMLElement preview: Markdown preview element.
+ :param HTMLElement parent: Markdown editor element.
+ :param HTMLTextAreaElement editor: Markdown editor element.
+ :param HTMLElement preview: Markdown preview element.
- .. js:attribute:: editor
+ .. js:data:: properties
- - (*HTMLTextAreaElement*) - Instance editor.
+ :JSON Object: Class variables.
- .. js:attribute:: preview
+ .. js:attribute:: editor
- - (*HMTLElement*) - Instance preview.
+ - (*HTMLTextAreaElement*) - Instance editor.
- .. js:attribute:: timeout
+ .. js:attribute:: preview
- - (*number* | *null*) - Private property; timeout settings.
+ - (*HMTLElement*) - Instance preview.
- .. js:attribute:: _editorIsResizable
+ .. js:attribute:: parent
- - (*Boolean*) - Private property; ``true`` if instance editor is resizable, otherwise ``false``.
+ - (*HMTLElement*) - Instance parent.
- .. js:function:: _markdownify()
+ .. js:attribute:: _latency
- Private settings for ``timeout``.
+ **private**
- .. js:function:: _routineEventResponse(event)
+ - (*number* | *null*) - Private property; timeout settings.
- Private routine tasks for event handlers (e.g. default preventions).
+ .. js:attribute:: _editorIsResizable
- :param Event event: Event to be handled.
+ **private**
+ - (*Boolean*) - Private property; ``true`` if instance editor is resizable, otherwise ``false``.
- .. js:function:: getEditorHeight(editor)
+ .. js:function:: _markdownify()
- :param HTMLTextAreaElement editor: Markdown editor element.
- :returns: The editor's height in pixels; e.g. ``"150px"``.
- :return type: string
+ **private**
- .. js:function:: inputChanged()
+ Settings for ``timeout``.
- Event handlers in response to alterations in the instance editor.
+ .. js:function:: _routineEventResponse(event)
- :param Event event: Event to be handled.
+ **private**
+ Routine tasks for event handlers (e.g. default preventions).
- .. js:function:: onDragEnter(event)
+ :param Event event: Event to be handled.
- Event handler for :guilabel:`dragEnter` events.
+ .. js:function:: getEditorHeight(editor)
- :param Event event: Event to be handled.
+ :param HTMLTextAreaElement editor: Markdown editor element.
+ :returns: The editor's height in pixels; e.g. ``"150px"``.
+ :return type: string
+ .. js:function:: inputChanged()
- .. js:function:: onDragLeave(event)
+ Event handlers in response to alterations in the instance editor.
- Event handler for :guilabel:`dragLeave` events.
+ :param Event event: Event to be handled.
- :param Event event: Event to be handled.
+ .. js:function:: onDragEnter(event)
+ Event handler for :guilabel:`dragEnter` events.
- .. js:function:: onDrop(event)
+ :param Event event: Event to be handled.
- Event handler for :guilabel:`drop` events (in drag and drops).
+ .. js:function:: onDragLeave(event)
- :param Event event: Event to be handled.
+ Event handler for :guilabel:`dragLeave` events.
+ :param Event event: Event to be handled.
- .. js:function:: onKeyDown(event)
+ .. js:function:: onDrop(event)
- Event handler for :guilabel:`keyDown` events as registered in the instance editor.
+ Event handler for :guilabel:`drop` events (in drag and drops).
- :param Event event: Event to be handled.
- :returns: ``null`` if the key pressed is *Tab* (ASCII #9) else ``false``.
- :return type: boolean | null
+ :param Event event: Event to be handled.
- .. js:function:: sendFile()
+ .. js:function:: onKeyDown(event)
- pass
+ Event handler for :guilabel:`keyDown` events as registered in the instance editor.
- .. js:function:: getMarkdown()
+ :param Event event: Event to be handled.
+ :returns: ``null`` if the key pressed is *Tab* (ASCII #9) else ``false``.
+ :return type: boolean | null
- pass
+ .. js:function:: sendFile(file)
- .. js:function:: insertImage()
+ Uploading the ``file`` onto the server through an AJAX request.
- pass
+ :param File file: File to be uploaded.
+
+ .. js:function:: getMarkdown()
+
+ Uploading the markdown text from :attr:`properties.editor` onto the server through an AJAX request, and upon
+ receiving the HTML encoded text in response, the response will be displayed in :attr:`properties.preview`.
+
+ .. js:function:: insertImage(textToInsert)
+
+ Inserts markdown encoded image URL into :attr:`properties.editor` where the cursor is located.
+
+ :param string textToInsert: Markdown text (with path to the image) to be inserted into the editor.
diff --git a/docs-src/js/docs/utils.rst b/docs-src/js/docs/utils.rst
index 0a4e59c..387136f 100644
--- a/docs-src/js/docs/utils.rst
+++ b/docs-src/js/docs/utils.rst
@@ -18,7 +18,62 @@ Utilities
not exist.
:param string name: The name of the cookie.
- :returns: Value of the cookie with the key ``name`` or ``null``.
+ :returns: Value of the cookie with the key ``name`` or ``null``.
+ :return type: string | null
+
+
+.. js:function:: zip(...rows)
+
+ JavaScript implementation of Python's ``zip`` function.
+
+ :param rows: Array or arrays to zipped together.
+ :returns: Array of zipped items.
+ :return type: Array[]
+
+ :example:
+ .. code-block:: javascript
+
+ >>> let zipped = zip([1, 'H'], [5, 'i']);
+
+ >>> zipped.map(row => row.reduce((m, n) => m + n))
+ // [6, "Hi"]
+
+
+.. js:function:: mountEvents (...collections)
+
+ Mounts a set of events defined in an object onto the document.
+
+ :param collections: Must be JSON object and follow the structure outlined in the example.
+ :returns: Listeners
+ :return type: Event
+
+ :example:
+ .. code-block:: javascript
+
+ >>> let editorListeners = {
+ ... object: document.getElementById('my-editor'),
+ ... listeners: [
+ ... { type: "input", capture: true , listener: inputChanged },
+ ... { type: "compositionstart", capture: true , listener: onKeyDown }
+ ... ]
+ ... };
+
+
+.. js:function:: triggerEvent(element, type)
+
+ Triggers an existing HTML event manually.
+
+ :param Element element: Element whose event is to be created and triggered.
+ :param string type: Type of the event to be triggered.
+
+
+.. js:function:: triggerCustomEvent(type, element, args)
+
+ Triggers an already defined custom event manually.
+
+ :param Element|Document element: Element whose event is to be triggered.
+ :param string type: Type of the event to be triggered.
+ :param args: Values to be passed as custom argument to ``event.details``. (Default = ``null``)
.. js:function:: preparePostData(data)
@@ -34,3 +89,129 @@ Utilities
:returns: A new instance **FormData** that incorporated the data embedded in ``data`` and the CSRF token in enabled.
:return type: FormData
+
+
+.. js:function:: AJAXRequest()
+
+ Determines the supported AJAX requests API in IE6+ browsers.
+
+ :return type: XMLHttpRequest
+ :throws TypeError: AJAX request is not supported.
+
+
+.. js:class:: Request(url, data)
+
+ An XMLHttpRequest wrapper object to initialize AJAX POST requests.
+
+ :example:
+ .. code-block:: javascript
+
+ >>> let value = "This is a test value",
+ postUrl = "https://example.com/";
+
+ >>> const xhr = new utils.Request(
+ ... postUrl, // URL
+ ... preparePostData({content: value}) // Data
+ ... );
+
+ >>> xhr.success = response => console.log(response);
+
+ >>> xhr.error = response => console.error(response);
+
+ >>> xhr.progress = event => {
+ ...
+ ... if (event.lengthComputable)
+ ... console.info(`${(event.loaded / event.total) * 100}% uploaded.`)
+ ...
+ ... };
+
+ >>> xhr.send();
+
+ .. js:attribute:: url
+
+ - (*string*) - URL to which the data is to be posted.
+
+ .. js:attribute:: data
+
+ - (*FormData*) - Data, as an instance of `FromData`, to be posted.
+
+ .. js:attribute:: xhr
+
+ **private**
+
+ - (*any*) - Value obtained automatically by calling :js:func:`AjaxRequest`.
+
+ .. js:function:: constructor(url, data)
+
+ :param string url: URL to which the data is to be posted.
+ :param FormData data: Data, as an instance of `FromData`, to be posted.
+
+ .. js:function:: progress(event)
+
+ Progress callback.
+
+ :param Event event: The entire event (see the example for additional information on usage).
+
+ .. js:function:: success(response)
+
+ Success callback.
+
+ :param any response: Success values; first available one of ``responseText``, ``responseXML``, or ``response``.
+
+ .. js:function:: error(response)
+
+ Error callback.
+
+ :param any response: Error value: ``responseText``.
+
+ .. js:function:: send()
+
+ Starts the transfer.
+
+
+.. js:function:: addClass(element, ...classNames)
+
+ Given an instance of an element, adds classes to it.
+
+ :param Element element: Instance of an element.
+ :param string[] classNames: Can be a single string, or multiple strings.
+
+ :example:
+ .. code-block:: javascript
+
+ >>> addClass(document.getElementById('my-element'), 'className');
+
+ // or
+
+ >>> addClass(document.getElementById('my-element'), 'classA', 'classB', 'classC');
+
+
+.. js:function:: hasClass(element, className)
+
+ Given an instance of an element, confirms whether or not the element has the class.
+
+ :param Element element: Instance of an element.
+ :param string[] className: Can be a single string, or multiple strings.
+ :returns: ``true`` if the element has the class, otherwise ``false``.
+ :return type: boolean
+ :example:
+ .. code-block:: javascript
+
+ >>> hasClass(document.getElementById('my-element'), 'className')
+ // returns True if the element with id "my-element" has the class "className", otherwise False.
+
+
+.. js:function:: removeClass(element, ...classNames)
+
+ Given an instance of an element, removes classes to it.
+
+ :param Element element: Instance of an element.
+ :param string[] classNames: Can be a single string, or multiple strings.
+ :example:
+ .. code-block:: javascript
+
+ >>> removeClass(document.getElementById('my-element'), 'className');
+
+ // or
+
+ >>> removeClass(document.getElementById('my-element'), 'classA', 'classB', 'classC');
diff --git a/docs/_modules/index.html b/docs/_modules/index.html
index bbccf1d..4a28bd7 100644
--- a/docs/_modules/index.html
+++ b/docs/_modules/index.html
@@ -8,7 +8,7 @@
-
Overview: module code — Django Markdownx 2.0.19 documentation
+ Overview: module code — Django Markdownx 2.0.21 documentation
@@ -35,7 +35,7 @@
-
+
@@ -202,7 +202,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Django Markdownx
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Source code for markdownx.exceptions
-from django.utils.translation import ugettext_lazy as _
-from django.forms import ValidationError
-
-
-[docs] class MarkdownxImageUploadError ( ValidationError ):
-
"""
-
Custom **MarkdownX** exceptions.
-
"""
-
-
@staticmethod
-
[docs] def not_uploaded ():
-
"""
-
No file is available to upload.
-
-
:return: Locale compatible version of the error with the following message:
-
-
- No files have been uploaded.
-
-
:rtype: MarkdownxImageUploadError
-
"""
-
return MarkdownxImageUploadError ( _ ( 'No files have been uploaded.' ))
-
-
@staticmethod
-
-
-
@staticmethod
-
[docs] def invalid_size ( current , expected ):
-
"""
-
The file is larger in size that the maximum allow in :guilabel:`settings.py` (or the default).
-
-
:param current: Current size of the file.
-
:type current: float, int
-
:param expected: Expected (maximum permitted) size of the file.
-
:type expected: float, int
-
:return: Locale compatible version of the error with the following message:
-
-
- Please keep file size under %(max)s. Current file size: %(current)s.'
-
-
:rtype: MarkdownxImageUploadError
-
"""
-
from django.template.defaultfilters import filesizeformat
-
-
return MarkdownxImageUploadError (
-
_ ( 'Please keep file size under %(max)s . Current file size: %(current)s .' ) % {
-
'max' : filesizeformat ( expected ),
-
'current' : filesizeformat ( current )
-
}
-
)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-