From 0a6810b18fe51c2ceff45a7a73a973d55d4165fb Mon Sep 17 00:00:00 2001 From: neSpecc Date: Wed, 11 May 2016 07:29:33 +0300 Subject: [PATCH] some improvements - mouse click handler on tools - closing toolbar on toolclicked --- codex-editor.js | 50 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/codex-editor.js b/codex-editor.js index dc53cb70..e4046069 100644 --- a/codex-editor.js +++ b/codex-editor.js @@ -217,9 +217,18 @@ cEditor.ui = { cEditor.callback.redactorInputEvent(event); }, false ); - // for (button in cEditor.nodes.toolbarButtons){ - // cEditor.nodes.toolbarButtons[button].addEventListener('click', cEditor.toolbar. toolClicked, false); - // } + for (button in cEditor.nodes.toolbarButtons){ + cEditor.nodes.toolbarButtons[button].addEventListener('click', function (event) { + + console.log(this.dataset.type); + + cEditor.toolbar.current = this.dataset.type; + + cEditor.toolbar.toolClicked(event); + cEditor.toolbar.close(); + + }, false); + } } @@ -268,10 +277,12 @@ cEditor.callback = { if (cEditor.toolbar.opened && event.target == cEditor.nodes.redactor) { + console.log('preventDefault'); + event.preventDefault(); cEditor.toolbar.toolClicked(event); - // cEditor.toolbar.close(); + cEditor.toolbar.close(); }; @@ -289,7 +300,7 @@ cEditor.callback = { cEditor.content.workingNodeChanged(); - // cEditor.toolbar.close(); + cEditor.toolbar.close(); cEditor.toolbar.move(); }, @@ -395,6 +406,8 @@ cEditor.content = { var nodeToReplace; + console.log('0 %o', cEditor.content.currentNode); + /** * First-level nodes replaces as-is, * otherwise we need to replace parent node @@ -405,11 +418,15 @@ cEditor.content = { nodeToReplace = targetBlock.parentNode; } + console.log('1 %o', cEditor.content.currentNode); + /** * Make new node with original content */ var nodeCreated = cEditor.draw.block(newBlockTagname, targetBlock.innerHTML); + console.log('2 %o', cEditor.content.currentNode); + /** * If it is a first-level node, replace as-is. */ @@ -417,13 +434,16 @@ cEditor.content = { cEditor.nodes.redactor.replaceChild(nodeCreated, nodeToReplace); + console.log('3 %o', cEditor.content.currentNode); + /** * Set new node as current */ cEditor.content.workingNodeChanged(nodeCreated); - setTimeout(function() { - cEditor.content.currentNode.focus(); - }, 100); + // setTimeout(function() { + // cEditor.content.currentNode.focus(); + // }, 100); + console.log('4 %o', cEditor.content.currentNode); return; } @@ -440,18 +460,26 @@ cEditor.content = { default : newNodeWrapperTagname = 'P'; break; } + console.log('5 %o', cEditor.content.currentNode); + newNodeWrapper = cEditor.draw.block(newNodeWrapperTagname); newNodeWrapper.appendChild(nodeCreated); + console.log('6 %o', cEditor.content.currentNode); + cEditor.nodes.redactor.replaceChild(newNodeWrapper, nodeToReplace); + console.log('7 %o', cEditor.content.currentNode); + /** * Set new node as current */ cEditor.content.workingNodeChanged(nodeCreated); - setTimeout(function() { - cEditor.content.currentNode.focus(); - }, 100); + // setTimeout(function() { + // cEditor.content.currentNode.focus(); + // }, 100); + + console.log('8 %o', cEditor.content.currentNode); }