From 2d25181e19aa4875ae981255f5688af6d591c339 Mon Sep 17 00:00:00 2001 From: George Berezhnoy Date: Sat, 25 Nov 2017 14:29:45 +0300 Subject: [PATCH] Docs --- example/plugins/paragraph/paragraph.js | 69 ++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/example/plugins/paragraph/paragraph.js b/example/plugins/paragraph/paragraph.js index a3d1c776..36c9020e 100644 --- a/example/plugins/paragraph/paragraph.js +++ b/example/plugins/paragraph/paragraph.js @@ -1,19 +1,39 @@ /** -* Paragraph Plugin -* Creates DIV tag and adds content to this tag -*/ + * @class Paragraph + * Paragraph plugin for CodexEditor + * + * @author CodeX Team (team@ifmo.su) + * @copyright CodeX Team 2017 + * @license The MIT License (MIT) + * @version 2.0.0 + * + * + * @typedef {Object} ParagraphData + * @property {String} text — HTML content to insert to paragraph element + * + */ -class Paragraph { +export default class Paragraph { + /** + * Get the name of the plugin + * + * @returns {string} The plugin name + */ static get name() { return 'paragraph'; } + /** + * Render plugin`s html and set initial content + * + * @param {ParagraphData} data — initial plugin content + */ constructor(data={}) { - this.CSS = { + this._CSS = { wrapper: 'ce-paragraph' }; @@ -21,22 +41,34 @@ class Paragraph { this.data = data; - this.element = this.render(); + this._element = this._render(); } - render() { + /** + * Create div element and add needed css classes + * + * @returns {HTMLDivElement} Created DIV element + * @private + */ + _render() { let div = document.createElement('DIV'); - div.classList.add(this.CSS.wrapper); + div.classList.add(this._CSS.wrapper); div.contentEditable = true; return div; } + /** + * Check if saved text is empty + * + * @param {ParagraphData} savedData — data received from plugins`s element + * @returns {boolean} false if saved text is empty, true otherwise + */ validate(savedData) { if (savedData.text.trim() === '') { @@ -49,15 +81,25 @@ class Paragraph { } + /** + * Get plugin`s element HTMLDivElement + * + * @returns {HTMLDivElement} Plugin`s element + */ get html() { - return this.element; + return this._element; } + /** + * Get current plugin`s data + * + * @returns {ParagraphData} Current data + */ get data() { - let text = this.element.innerHTML; + let text = this._element.innerHTML; this._data.text = text; @@ -65,11 +107,16 @@ class Paragraph { } + /** + * Set new data for plugin + * + * @param {ParagraphData} data — data to set + */ set data(data) { Object.assign(this._data, data); - this.element.innerHTML = this._data.text || ''; + this._element.innerHTML = this._data.text || ''; }