From: Aleksander Ɓukasz Date: Wed, 17 Apr 2013 09:15:17 +0000 (+0200) Subject: Visual editor: adding/removing meta data X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/ebaba7ac4948ae4280dea0a623045ffb6d5a722f?ds=sidebyside Visual editor: adding/removing meta data --- diff --git a/editor.css b/editor.css index a6691f2..651b58b 100644 --- a/editor.css +++ b/editor.css @@ -24,7 +24,7 @@ body { border-style: solid; border-width: 1px; float:left; - width: 620px; + width: 600px; height: 500px; overflow-y: scroll; padding: 5px 10px; @@ -60,6 +60,20 @@ body { float:right; } +#rng-visualEditor-meta table input { + font-size: 11px; + line-height:13px; + +} + +#rng-visualEditor-meta table tr td:nth-child(1) input { + width:90px; +} + +#rng-visualEditor-meta table tr td:nth-child(2) input { + width:150px; +} + #rng-sourceEditor-editor { width: 940px; height: 500px; diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 132c70f..5833b71 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -28,24 +28,39 @@ rng.modules.visualEditor = function(sandbox) { if(!anchor.is('[wlxml-tag]')) return; view._markSelected(anchor); - }); + }); + + + this.metaTable = this.node.find('#rng-visualEditor-meta table'); + + this.metaTable.find('.rng-visualEditor-metaAddBtn').click(function() { + view._addMetaRow(); + isDirty = true; + }); + + this.metaTable.on('click', '.rng-visualEditor-metaRemoveBtn', function(e) { + $(e.target).closest('tr').remove(); + isDirty = true; + }); + }, getMetaData: function() { var toret = {}; - this.node.find('#rng-visualEditor-meta table tr').each(function() { + this.metaTable.find('tr').not('.rng-visualEditor-addMetaRow').each(function() { var tr = $(this); - var key = $(tr.find('td')[0]).html(); - var value = $(tr.find('td input')[0]).val(); + var inputs = $(this).find('td input'); + var key = $(inputs[0]).val() + var value = $(inputs[1]).val() toret[key] = value; }); console.log(toret); return toret; }, setMetaData: function(metadata) { - var table = this.node.find('#rng-visualEditor-meta table'); - table.empty(); + var view = this; + this.metaTable.find('tr').not('.rng-visualEditor-addMetaRow').remove(); _.each(_.keys(metadata), function(key) { - $(sandbox.getTemplate('metaItem')({key: key, value: metadata[key]})).appendTo(table); + view._addMetaRow(key, metadata[key]); }); }, setBody: function(HTMLTree) { @@ -57,6 +72,10 @@ rng.modules.visualEditor = function(sandbox) { _markSelected: function(node) { this.node.find('.rng-current').removeClass('rng-current'); node.addClass('rng-current'); + }, + _addMetaRow: function(key, value) { + var addRow = this.metaTable.find('.rng-visualEditor-addMetaRow'); + $(sandbox.getTemplate('metaItem')({key: key || '', value: value || ''})).insertBefore(addRow); } }; view.setup();