From: Aleksander Ɓukasz Date: Fri, 19 Apr 2013 13:47:54 +0000 (+0200) Subject: Visual editor: refactoring X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/fc68f216c84ebb1cba54a1d7cc2b90c5f2923443?ds=sidebyside Visual editor: refactoring --- diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 06a5ab6..73622f9 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -93,12 +93,22 @@ rng.modules.visualEditor = function(sandbox) { this.currentNode = node; mediator.nodeSelected(node); }, + selectNode: function(node) { + view._markSelected(node); + var range = document.createRange(); + range.selectNodeContents(node[0]); + range.collapse(false); + + var selection = document.getSelection(); + selection.removeAllRanges() + selection.addRange(range); + }, selectFirstNode: function() { var firstNodeWithText = this.node.find('[wlxml-tag]').filter(function() { return $(this).clone().children().remove().end().text().trim() !== ''; }).first(); if(firstNodeWithText.length) - $(firstNodeWithText[0]).click().focus(); + this.selectNode($(firstNodeWithText[0])); }, _addMetaRow: function(key, value) { var newRow = $(sandbox.getTemplate('metaItem')({key: key || '', value: value || ''})); @@ -173,15 +183,7 @@ rng.modules.visualEditor = function(sandbox) { return view.currentNode; }, nodeCreated: function(node) { - view._markSelected(node); - - var range = document.createRange(); - range.selectNodeContents(node[0]); - range.collapse(false); - - var selection = document.getSelection(); - selection.removeAllRanges() - selection.addRange(range); + view.selectNode(node); }, nodeSelected: function(node) {