X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/0022318acaf4767c0b70052ccbd0c0a86effc691..c0e11a8f6d0d9a4c030aa90fe91f0fc49cd05e0e:/modules/visualEditor.js?ds=sidebyside diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 06a5ab6..f3c0a5c 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -93,12 +93,27 @@ 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(); + var node; if(firstNodeWithText.length) - $(firstNodeWithText[0]).click().focus(); + node = $(firstNodeWithText[0]) + else { + node = this.node.find('[wlxml-class|="p"]') + } + this.selectNode(node); }, _addMetaRow: function(key, value) { var newRow = $(sandbox.getTemplate('metaItem')({key: key || '', value: value || ''})); @@ -173,15 +188,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) {