Merge branch 'master' into quotes

This commit is contained in:
khaydarov 2016-07-01 19:55:10 +03:00
commit db6ad166a7

View file

@ -516,7 +516,11 @@ cEditor.callback = {
cEditor.content.workingNodeChanged();
if ( cEditor.toolbar.opened && event.target == cEditor.content.currentNode) {
var isEnterPressedOnToolbar = cEditor.toolbar.opened &&
cEditor.toolbar.current &&
event.target == cEditor.content.currentNode;
if ( isEnterPressedOnToolbar ) {
event.preventDefault();
cEditor.toolbar.toolClicked(event);
@ -601,7 +605,7 @@ cEditor.callback = {
break;
case cEditor.core.keys.ENTER:
cEditor.callback.enterPressed(block);
cEditor.callback.enterPressedOnBlock(block, event);
break;
case cEditor.core.keys.BACKSPACE:
@ -733,7 +737,7 @@ cEditor.callback = {
},
enterPressed: function (block) {
enterPressedOnBlock: function (block, event) {
var selection = window.getSelection(),
currentNode = selection.anchorNode,
@ -748,7 +752,7 @@ cEditor.callback = {
&& parentOfFocusedNode.childNodes.length == cEditor.caret.focusedNodeIndex + 1) {
/** Prevent <div></div> creation */
// event.preventDefault();
event.preventDefault();
/** Create new Block and append it after current */
var newBlock = cEditor.draw.block('p');
@ -952,7 +956,7 @@ cEditor.content = {
/**
* @deprecated with replaceBlock()
*/
switchBlock : function (targetBlock, newBlockTagname) {
_switchBlock : function (targetBlock, newBlockTagname) {
if (!targetBlock || !newBlockTagname) return;
@ -1028,6 +1032,25 @@ cEditor.content = {
cEditor.caret.set(nodeCreated);
},
/**
* Replaces blocks with saving content
* @param {Element} noteToReplace
* @param {Element} newNode
* @param {Element} blockType
*/
switchBlock : function(nodeToReplace, newNode, blockType){
/** Saving content */
newNode.innerHTML = nodeToReplace.innerHTML;
/** Replacing */
cEditor.content.replaceBlock(nodeToReplace, newNode, blockType);
/** Add event listeners */
cEditor.ui.addBlockHandlers(newNode);
},
/**
* Iterates between child noted and looking for #text node on deepest level
@ -1340,29 +1363,32 @@ cEditor.toolbar = {
*/
toolClicked : function() {
var workingNode = cEditor.content.currentNode,
newTag,
appendCallback;
var REPLACEBLE_TOOLS = ['paragraph', 'header', 'code'],
tool = cEditor.tools[cEditor.toolbar.current],
workingNode = cEditor.content.currentNode,
appendCallback,
newBlock;
/** Can replace? */
if (REPLACEBLE_TOOLS.indexOf(tool.type) != -1 && workingNode) {
/**
* Copy plugin 'append' Element
*/
newBlock = tool.append.cloneNode(true);
/** Replace current block */
cEditor.content.switchBlock(workingNode, newBlock, tool.type);
} else {
newBlock = tool.append;
/** Insert new Block from plugin */
cEditor.content.insertBlock(newBlock, tool.type);
switch (cEditor.toolbar.current) {
case 'paragraph' : newTag = 'P'; break;
case 'header' : newTag = 'H1'; break;
case 'quote' : newTag = 'BLOCKQUOTE'; break;
case 'code' : newTag = 'CODE'; break;
case 'list' : newTag = 'LI'; break;
}
/**
* @todo
* use insertBlock or replaceBlock instead of switchBlock
*/
// cEditor.content.switchBlock(workingNode, newTag);
var tools = cEditor.tools[cEditor.toolbar.current];
/** Insert new Block from plugin */
cEditor.content.insertBlock(tools.append, tools.type);
/** Fire tool append callback */
appendCallback = cEditor.tools[cEditor.toolbar.current].appendCallback;