mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 15:45:47 +01:00
New project structure (#214)
This commit is contained in:
parent
7263a16055
commit
ed28a85db6
48 changed files with 0 additions and 800 deletions
30
example/plugins/code/code.css
Normal file
30
example/plugins/code/code.css
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
.ce-code {
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: 100px;
|
||||
border: 1px solid #ebeef3;
|
||||
border-radius: 3px;
|
||||
background: #fdfdff !important;
|
||||
|
||||
margin: 1em 0 !important;
|
||||
padding: .5em .8em;
|
||||
box-sizing: border-box;
|
||||
white-space: pre-wrap;
|
||||
|
||||
font-family: 'monospace', 'monaco', 'consolas', 'courier';
|
||||
line-height: 1.5em;
|
||||
color: #325179;
|
||||
font-size: .8em;
|
||||
|
||||
resize: vertical;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* CodeX Editor styles overlay
|
||||
* @todo change for ce-tool-wrapper__code
|
||||
*/
|
||||
.ce_block[data-type="code"]{
|
||||
padding: 1em 0 !important;
|
||||
}
|
||||
82
example/plugins/code/code.js
Normal file
82
example/plugins/code/code.js
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* 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('TEXTAREA', [baseClass], {});
|
||||
|
||||
if (data && data.text) {
|
||||
tag.value = data.text;
|
||||
}
|
||||
|
||||
return tag;
|
||||
};
|
||||
|
||||
/**
|
||||
* Escapes HTML chars
|
||||
*
|
||||
* @param {string} input
|
||||
* @return {string} — escaped string
|
||||
*/
|
||||
var escapeHTML_ = function (input) {
|
||||
|
||||
var div = document.createElement('DIV'),
|
||||
text = document.createTextNode(input);
|
||||
|
||||
div.appendChild(text);
|
||||
|
||||
return div.innerHTML;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 escaped = escapeHTML_(blockContent.value),
|
||||
data = {
|
||||
text : escaped
|
||||
};
|
||||
|
||||
|
||||
return data;
|
||||
|
||||
};
|
||||
|
||||
code_plugin.validate = function (data) {
|
||||
|
||||
if (data.text.trim() == '')
|
||||
return;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
code_plugin.destroy = function () {
|
||||
|
||||
code = null;
|
||||
|
||||
};
|
||||
|
||||
return code_plugin;
|
||||
|
||||
})({});
|
||||
Loading…
Add table
Add a link
Reference in a new issue