append -> make()

This commit is contained in:
Peter Savchenko 2016-07-01 21:02:49 +03:00
parent cb7f92e0a3
commit f7e4d3393c
2 changed files with 33 additions and 20 deletions

View file

@ -390,6 +390,11 @@ cEditor.ui = {
continue; continue;
} }
if (typeof tool.make != 'function') {
cEditor.core.log('make method missed. Tool %o skipped', 'warn', name);
continue;
}
tool_button = cEditor.draw.toolbarButton(name, tool.iconClassname); tool_button = cEditor.draw.toolbarButton(name, tool.iconClassname);
cEditor.nodes.toolbar.appendChild(tool_button); cEditor.nodes.toolbar.appendChild(tool_button);
@ -1358,21 +1363,17 @@ cEditor.toolbar = {
appendCallback, appendCallback,
newBlock; newBlock;
/** Make block from plugin */
newBlock = tool.make();
/** Can replace? */ /** Can replace? */
if (REPLACEBLE_TOOLS.indexOf(tool.type) != -1 && workingNode) { if (REPLACEBLE_TOOLS.indexOf(tool.type) != -1 && workingNode) {
/**
* Copy plugin 'append' Element
*/
newBlock = tool.append.cloneNode(true);
/** Replace current block */ /** Replace current block */
cEditor.content.switchBlock(workingNode, newBlock, tool.type); cEditor.content.switchBlock(workingNode, newBlock, tool.type);
} else { } else {
newBlock = tool.append;
/** Insert new Block from plugin */ /** Insert new Block from plugin */
cEditor.content.insertBlock(newBlock, tool.type); cEditor.content.insertBlock(newBlock, tool.type);
@ -1844,7 +1845,7 @@ var paragraphTool = {
* @param {object} JSON to with block data * @param {object} JSON to with block data
* @return {Element} element to append * @return {Element} element to append
*/ */
makeBlockToAppend : function (data) { make : function (data) {
var tag = document.createElement('P'); var tag = document.createElement('P');
@ -1863,7 +1864,7 @@ var paragraphTool = {
*/ */
render : function (data) { render : function (data) {
return paragraphTool.makeBlockToAppend(data); return paragraphTool.make(data);
}, },
@ -1892,7 +1893,7 @@ cEditor.tools.paragraph = {
type : 'paragraph', type : 'paragraph',
iconClassname : 'ce-icon-paragraph', iconClassname : 'ce-icon-paragraph',
append : paragraphTool.makeBlockToAppend(), make : paragraphTool.make,
appendCallback : null, appendCallback : null,
settings : null, settings : null,
render : paragraphTool.render, render : paragraphTool.render,
@ -1911,7 +1912,7 @@ var headerTool = {
* @param {object} JSON to with block data * @param {object} JSON to with block data
* @return {Element} element to append * @return {Element} element to append
*/ */
makeBlockToAppend : function (data) { make : function (data) {
var availableTypes = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'], var availableTypes = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'],
tag; tag;
@ -1947,7 +1948,7 @@ var headerTool = {
*/ */
render : function (data) { render : function (data) {
return headerTool.makeBlockToAppend(data); return headerTool.make(data);
}, },
@ -2071,7 +2072,7 @@ cEditor.tools.header = {
type : 'header', type : 'header',
iconClassname : 'ce-icon-header', iconClassname : 'ce-icon-header',
append : headerTool.makeBlockToAppend(), make : headerTool.make,
appendCallback : headerTool.appendCallback, appendCallback : headerTool.appendCallback,
settings : headerTool.makeSettings(), settings : headerTool.makeSettings(),
render : headerTool.render, render : headerTool.render,

View file

@ -5,15 +5,25 @@
<title>CodeX Editor</title> <title>CodeX Editor</title>
<link rel="stylesheet" href="editor.css" /> <link rel="stylesheet" href="editor.css" />
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,700,800&subset=latin,cyrillic' rel='stylesheet' type='text/css' async=true> <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,700,800&subset=latin,cyrillic' rel='stylesheet' type='text/css' async=true>
<link href='https://fonts.googleapis.com/css?family=Lora:400,400italic,700,700italic&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
<style> <style>
body{ body{
font-family: 'Open Sans'; font-family: 'Open Sans';
/*font-family: 'Lora';*/
font-size: 14px; font-size: 14px;
} }
.article{
max-width: 900px;
margin: 0 auto;
}
h1{
font-size: 2em;
}
</style> </style>
</head> </head>
<body style="padding: 100px"> <body style="padding: 100px">
<article class="article">
<h1>CodeX Editor</h1> <h1>CodeX Editor</h1>
@ -26,6 +36,8 @@
</form> </form>
</article>
<!-- <!--
<div class="ce_wrapper"> <div class="ce_wrapper">