2016-07-13 19:08:53 +02:00
|
|
|
/**
|
|
|
|
* Paragraph Plugin\
|
|
|
|
* Creates P tag and adds content to this tag
|
|
|
|
*/
|
|
|
|
var paragraphTool = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make initial header block
|
|
|
|
* @param {object} JSON with block data
|
|
|
|
* @return {Element} element to append
|
|
|
|
*/
|
|
|
|
make : function (data) {
|
|
|
|
|
|
|
|
var tag = document.createElement('DIV');
|
|
|
|
|
|
|
|
if (data && data.text) {
|
|
|
|
tag.innerHTML = data.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag.contentEditable = true;
|
|
|
|
|
|
|
|
return tag;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to render HTML block from JSON
|
|
|
|
*/
|
|
|
|
render : function (data) {
|
|
|
|
|
|
|
|
return paragraphTool.make(data);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to extract JSON data from HTML block
|
|
|
|
*/
|
2016-07-16 00:37:01 +02:00
|
|
|
save : function (blockContent){
|
|
|
|
|
|
|
|
var block = blockContent[0],
|
|
|
|
json = {
|
|
|
|
type : 'paragraph',
|
|
|
|
data : {
|
|
|
|
text : null,
|
|
|
|
}
|
|
|
|
};
|
2016-07-13 19:08:53 +02:00
|
|
|
|
2016-07-15 17:29:54 +02:00
|
|
|
json.data.text = block.innerHTML;
|
|
|
|
return json;
|
2016-07-13 19:08:53 +02:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Now plugin is ready.
|
|
|
|
* Add it to redactor tools
|
|
|
|
*/
|
|
|
|
cEditor.tools.paragraph = {
|
|
|
|
|
|
|
|
type : 'paragraph',
|
|
|
|
iconClassname : 'ce-icon-paragraph',
|
|
|
|
make : paragraphTool.make,
|
|
|
|
appendCallback : null,
|
|
|
|
settings : null,
|
|
|
|
render : paragraphTool.render,
|
|
|
|
save : paragraphTool.save
|
|
|
|
|
|
|
|
};
|