editor.js/plugins/ceditor-tool-code/ceditor-tool-code.js
Menshikov Alexander 0626ca1f07 Tool code (#67)
* Add error background

* Add tool code
Fix switch block and insert block for new system with div wrappers

* Remove unneccessary appendChild

* Fix css in tool code
2016-07-02 19:18:38 +03:00

70 lines
1.2 KiB
JavaScript

/**
* Code Plugin\
* Creates code tag and adds content to this tag
*/
var codeTool = {
baseClass : "tool-code",
/**
* Make initial header block
* @param {object} JSON with block data
* @return {Element} element to append
*/
make : function (data) {
var tag = document.createElement('code');
tag.classList += codeTool.baseClass;
if (data && data.text) {
tag.innerHTML = data.text;
}
tag.contentEditable = true;
return tag;
},
/**
* Method to render HTML block from JSON
*/
render : function (data) {
return codeTool.make(data);
},
/**
* Method to extract JSON data from HTML block
*/
save : function (block){
var data = {
text : null
};
data.text = blockData.textContent;
return data;
},
};
/**
* Now plugin is ready.
* Add it to redactor tools
*/
cEditor.tools.code = {
type : 'code',
iconClassname : 'ce-icon-code',
make : codeTool.make,
appendCallback : null,
settings : null,
render : codeTool.render,
save : codeTool.save
};