2016-12-25 15:41:57 +01:00
|
|
|
/**
|
|
|
|
* Code Plugin\
|
|
|
|
* Creates code tag and adds content to this tag
|
|
|
|
*/
|
|
|
|
|
2017-02-13 18:54:18 +01:00
|
|
|
var code = (function(code_plugin) {
|
2017-01-18 16:12:50 +01:00
|
|
|
|
|
|
|
var baseClass = "ce-code";
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make initial header block
|
|
|
|
* @param {object} JSON with block data
|
|
|
|
* @return {Element} element to append
|
|
|
|
*/
|
2017-02-01 18:25:59 +01:00
|
|
|
var make_ = function (data) {
|
2016-12-25 15:41:57 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
var tag = codex.editor.draw.node('CODE', [baseClass], {});
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
if (data && data.text) {
|
|
|
|
tag.innerHTML = data.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag.contentEditable = true;
|
|
|
|
|
|
|
|
return tag;
|
2017-01-18 16:12:50 +01:00
|
|
|
};
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to render HTML block from JSON
|
|
|
|
*/
|
2017-02-13 18:54:18 +01:00
|
|
|
code_plugin.render = function (data) {
|
2016-12-25 15:41:57 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
return make_(data);
|
2017-01-18 16:12:50 +01:00
|
|
|
};
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to extract JSON data from HTML block
|
|
|
|
*/
|
2017-02-13 18:54:18 +01:00
|
|
|
code_plugin.save = function (blockContent) {
|
2016-12-25 15:41:57 +01:00
|
|
|
|
|
|
|
var data = {
|
2017-01-18 16:12:50 +01:00
|
|
|
text : blockContent.innerHTML
|
|
|
|
};
|
|
|
|
return 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-02-13 18:54:18 +01:00
|
|
|
code_plugin.validate = function (data) {
|
2017-01-18 16:12:50 +01:00
|
|
|
|
|
|
|
if (data.text.trim() == '')
|
|
|
|
return;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
2016-12-25 15:41:57 +01:00
|
|
|
|
2017-02-13 18:54:18 +01:00
|
|
|
code_plugin.destroy = function () {
|
|
|
|
|
|
|
|
code = null;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return code_plugin;
|
2016-12-25 15:41:57 +01:00
|
|
|
|
2017-01-18 16:12:50 +01:00
|
|
|
})({});
|