From: Aleksander Ɓukasz Date: Wed, 17 Apr 2013 14:48:43 +0000 (+0200) Subject: Visual editor: selecting first node on first display X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/cf7d465ce6ed2acbc2b1c028e46847ead5320e9c?ds=inline Visual editor: selecting first node on first display --- diff --git a/modules/rng.js b/modules/rng.js index 4e0ca6e..6ea6f40 100644 --- a/modules/rng.js +++ b/modules/rng.js @@ -41,6 +41,10 @@ rng.modules.rng = function(sandbox) { editor.setDirty(false); } } + }, + showed: function(slug) { + if(slug === 'visual') + sandbox.getModule('visualEditor').onShowed(); } }; @@ -53,8 +57,9 @@ rng.modules.rng = function(sandbox) { eventHandlers.visualEditor = { ready: function() { - addTab('Visual', 'visual', sandbox.getModule('visualEditor').getView()); sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument()); + addTab('Visual', 'visual', sandbox.getModule('visualEditor').getView()); + } }; diff --git a/modules/tabsManager.js b/modules/tabsManager.js index 1f0ac18..4ede9a0 100644 --- a/modules/tabsManager.js +++ b/modules/tabsManager.js @@ -26,6 +26,7 @@ rng.modules.tabsManager = function(sandbox) { tabContent[prevSlug].detach(); tabContent[slug].appendTo(view.find('#rng-tabsManager-content')); currentSlug = slug; + sandbox.publish('showed', slug); } diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 98923a5..8d77302 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -91,6 +91,13 @@ rng.modules.visualEditor = function(sandbox) { node.addClass('rng-current'); mediator.nodeSelected(node); }, + markFirstSelected: 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(); + }, _addMetaRow: function(key, value) { var newRow = $(sandbox.getTemplate('metaItem')({key: key || '', value: value || ''})); newRow.appendTo(this.metaTable); @@ -135,7 +142,7 @@ rng.modules.visualEditor = function(sandbox) { } var isDirty = false; - + var wasShownAlready = false; return { @@ -159,6 +166,12 @@ rng.modules.visualEditor = function(sandbox) { }, setDirty: function(dirty) { isDirty = dirty; + }, + onShowed: function() { + if(!wasShownAlready) { + wasShownAlready = true; + view.markFirstSelected(); + } } }