2016-12-25 15:41:57 +01:00
|
|
|
/**
|
2017-01-18 16:12:50 +01:00
|
|
|
* Paragraph Plugin
|
2016-12-25 15:41:57 +01:00
|
|
|
* Creates P tag and adds content to this tag
|
|
|
|
*/
|
|
|
|
|
2017-01-18 16:12:50 +01:00
|
|
|
var paragraph = (function(paragraph) {
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-18 16:12:50 +01:00
|
|
|
* Make initial header block
|
|
|
|
* @param {object} JSON with block data
|
|
|
|
* @return {Element} element to append
|
|
|
|
*/
|
|
|
|
paragraph.make = function (data) {
|
2016-12-25 15:41:57 +01:00
|
|
|
|
2017-01-18 16:12:50 +01:00
|
|
|
/** Create Empty DIV */
|
|
|
|
var tag = codex.draw.node('DIV', ['ce-paragraph'], {});
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
if (data && data.text) {
|
|
|
|
tag.innerHTML = data.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag.contentEditable = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* if plugin need to add placeholder
|
|
|
|
* tag.setAttribute('data-placeholder', 'placehoder');
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @uses Paste tool callback.
|
|
|
|
* Function analyzes pasted data
|
|
|
|
* If pasted URL from instagram, twitter or Image
|
|
|
|
* it renders via Social widgets content or uploads image and uses Image tool to render
|
|
|
|
*/
|
|
|
|
tag.addEventListener('paste', codex.tools.paste.callbacks.pasted, false);
|
|
|
|
|
|
|
|
return tag;
|
|
|
|
|
2017-01-18 16:12:50 +01:00
|
|
|
};
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-18 16:12:50 +01:00
|
|
|
* Method to render HTML block from JSON
|
|
|
|
*/
|
|
|
|
paragraph.render = function (data) {
|
2016-12-25 15:41:57 +01:00
|
|
|
|
2017-01-18 16:12:50 +01:00
|
|
|
return this.make(data);
|
2016-12-25 15:41:57 +01:00
|
|
|
|
2017-01-18 16:12:50 +01:00
|
|
|
};
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-18 16:12:50 +01:00
|
|
|
* Method to extract JSON data from HTML block
|
|
|
|
*/
|
|
|
|
paragraph.save = function (blockContent){
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
var data = {
|
2017-01-18 16:12:50 +01:00
|
|
|
text : null,
|
|
|
|
format: "html",
|
|
|
|
introText: '<<same>>'
|
|
|
|
};
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
data.text = blockContent.innerHTML;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
2017-01-18 16:12:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2016-12-25 15:41:57 +01:00
|
|
|
|
2017-01-18 16:12:50 +01:00
|
|
|
})({});
|