mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 23:55:49 +01:00
new feature (#109)
* new feature method validate must be appended to codex.tools. * beta-redactor * before merge * validate is not important setting
This commit is contained in:
parent
7af56b4149
commit
a9a0992217
19 changed files with 1334 additions and 1692 deletions
|
|
@ -2,20 +2,19 @@
|
|||
* Code Plugin\
|
||||
* Creates code tag and adds content to this tag
|
||||
*/
|
||||
var codeTool = {
|
||||
|
||||
baseClass : "ce-code",
|
||||
var code = (function(code) {
|
||||
|
||||
var baseClass = "ce-code";
|
||||
|
||||
/**
|
||||
* Make initial header block
|
||||
* @param {object} JSON with block data
|
||||
* @return {Element} element to append
|
||||
*/
|
||||
make : function (data) {
|
||||
code.make = function (data) {
|
||||
|
||||
var tag = document.createElement('code');
|
||||
|
||||
tag.classList.add(codeTool.baseClass);
|
||||
var tag = codex.draw.node('CODE', [baseClass], {});
|
||||
|
||||
if (data && data.text) {
|
||||
tag.innerHTML = data.text;
|
||||
|
|
@ -24,31 +23,36 @@ var codeTool = {
|
|||
tag.contentEditable = true;
|
||||
|
||||
return tag;
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Method to render HTML block from JSON
|
||||
*/
|
||||
render : function (data) {
|
||||
code.render = function (data) {
|
||||
|
||||
return codeTool.make(data);
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Method to extract JSON data from HTML block
|
||||
*/
|
||||
save : function (blockContent){
|
||||
code.save = function (blockContent){
|
||||
|
||||
var data = {
|
||||
text : null,
|
||||
};
|
||||
|
||||
data.text = blockContent.innerHTML;
|
||||
|
||||
text : blockContent.innerHTML
|
||||
};
|
||||
return data;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
code.validate = function(data) {
|
||||
|
||||
if (data.text.trim() == '')
|
||||
return;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
return code;
|
||||
|
||||
})({});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue