editor.js/plugins/code/code.js
George Berezhnoy d2e755086a Destroy module (#157)
* listeners module added

* Destroy method added

* Destroy method for plugins added

* Delete plugins properties from window obj

* Revert "Delete plugins properties from window obj"

This reverts commit 6c91f81229.

* Twitter and instagram api's destroy

* Scripts destoy added

* Fix

* Replace regex with String.indexOf

* Settings for destroyer
2017-02-13 20:54:18 +03:00

65 lines
1.1 KiB
JavaScript

/**
* Code Plugin\
* Creates code tag and adds content to this tag
*/
var code = (function(code_plugin) {
var baseClass = "ce-code";
/**
* Make initial header block
* @param {object} JSON with block data
* @return {Element} element to append
*/
var make_ = function (data) {
var tag = codex.editor.draw.node('CODE', [baseClass], {});
if (data && data.text) {
tag.innerHTML = data.text;
}
tag.contentEditable = true;
return tag;
};
/**
* Method to render HTML block from JSON
*/
code_plugin.render = function (data) {
return make_(data);
};
/**
* Method to extract JSON data from HTML block
*/
code_plugin.save = function (blockContent) {
var data = {
text : blockContent.innerHTML
};
return data;
};
code_plugin.validate = function (data) {
if (data.text.trim() == '')
return;
return true;
};
code_plugin.destroy = function () {
code = null;
};
return code_plugin;
})({});