From 326767a20239b652fb0677807e0b13831153a82b Mon Sep 17 00:00:00 2001 From: khaydarov Date: Thu, 26 Jan 2017 00:54:02 +0300 Subject: [PATCH] paragraph module (#116) * paragraph refactored * improved after review --- plugins/paragraph/paragraph.css | 3 +- plugins/paragraph/paragraph.js | 87 +++++++++++++++++++-------------- 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/plugins/paragraph/paragraph.css b/plugins/paragraph/paragraph.css index 11bf8abb..172d1c93 100644 --- a/plugins/paragraph/paragraph.css +++ b/plugins/paragraph/paragraph.css @@ -6,7 +6,8 @@ padding: 0.7em 0 !important; line-height: 1.7em; } -.ce-paragraph:empty::before{ +.ce-paragraph:empty::before, +.ce-paragraph p:empty::before{ content : attr(data-placeholder); color: #818BA1; opacity: .7; diff --git a/plugins/paragraph/paragraph.js b/plugins/paragraph/paragraph.js index 0684ec27..5a581089 100644 --- a/plugins/paragraph/paragraph.js +++ b/plugins/paragraph/paragraph.js @@ -1,16 +1,19 @@ /** * Paragraph Plugin -* Creates P tag and adds content to this tag +* Creates DIV tag and adds content to this tag */ var paragraph = (function(paragraph) { /** + * @private + * * Make initial header block * @param {object} JSON with block data * @return {Element} element to append */ - paragraph.make = function (data) { + + var make_ = function (data) { /** Create Empty DIV */ var tag = codex.draw.node('DIV', ['ce-paragraph'], {}); @@ -21,11 +24,6 @@ var paragraph = (function(paragraph) { tag.contentEditable = true; - /** - * if plugin need to add placeholder - * tag.setAttribute('data-placeholder', 'placehoder'); - */ - /** * @uses Paste tool callback. * Function analyzes pasted data @@ -39,52 +37,67 @@ var paragraph = (function(paragraph) { }; /** - * Method to render HTML block from JSON + * @private + * + * Handles input data for save + * @param data */ - paragraph.render = function (data) { - - return this.make(data); + var prepareDataForSave_ = function(data) { }; /** + * @public + * + * Plugins should have prepare method + * @param config + */ + paragraph.prepare = function(config) { + + }; + + /* + * @public + * + * Method to render HTML block from JSON + */ + paragraph.render = function (data) { + + return make_(data); + + }; + + /** + * @public + * + * Check output data for validity. + * Should be defined by developer + */ + paragraph.validate = function(output) { + + if (output.text == '') + return; + + return output; + }; + + /** + * @public + * * Method to extract JSON data from HTML block */ paragraph.save = function (blockContent){ var data = { - text : null, - format: "html", - introText: '<>' + "text": blockContent.innerHTML, + "format": "html", + "introText": '<>' }; - data.text = blockContent.innerHTML; - return data; }; - /** - * Validate data. - * Define which objects are important and which are not - * - * @param data - * - * @return [Boolean] - */ - paragraph.validate = function(data) { - - /** - * Do not allow: - * - Empty text - */ - if (data.text.trim() == '') - return; - - return true; - - }; - return paragraph; })({});