X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/ce51fb7e5de8910382af08e299831714e5f0e4e4..1ffafa96f9858a9eb43d3a66d7593ae0cbf090d1:/modules/visualEditor.js diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 98923a5..8a96cb9 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -3,6 +3,7 @@ rng.modules.visualEditor = function(sandbox) { var view = { node: $(sandbox.getTemplate('main')()), + currentNode: null, setup: function() { var view = this; @@ -89,8 +90,16 @@ rng.modules.visualEditor = function(sandbox) { _markSelected: function(node) { this.node.find('.rng-current').removeClass('rng-current'); node.addClass('rng-current'); + this.currentNode = node; 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); @@ -111,6 +120,13 @@ rng.modules.visualEditor = function(sandbox) { view.selectTab(target.attr('data-content-id')); }); view.selectTab('rng-visualEditor-edit'); + + view.node.on('change', '.rng-visualEditor-editPaneNodeForm select', function(e) { + var target = $(e.target); + var attr = target.attr('id').split('-')[2].split('editPane')[1].substr(0,3) === 'Tag' ? 'tag' : 'class'; + mediator.getCurrentNode().attr('wlxml-'+attr, target.val()); + isDirty = true; + }); }, selectTab: function(id) { this.node.find('.rng-visualEditor-sidebarContentItem').hide(); @@ -129,13 +145,16 @@ rng.modules.visualEditor = function(sandbox) { sideBarView.setup(); var mediator = { + getCurrentNode: function() { + return view.currentNode; + }, nodeSelected: function(node) { sideBarView.updateEditPane(node); } } var isDirty = false; - + var wasShownAlready = false; return { @@ -159,6 +178,12 @@ rng.modules.visualEditor = function(sandbox) { }, setDirty: function(dirty) { isDirty = dirty; + }, + onShowed: function() { + if(!wasShownAlready) { + wasShownAlready = true; + view.markFirstSelected(); + } } }