X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/6312e8b640d0aa87fa8c2bdac6132f6d3a7d1e7b..690fb9ef0a8964fb7b7f18eb8c7243ac03cf4b47:/modules/visualEditor.js diff --git a/modules/visualEditor.js b/modules/visualEditor.js index bd90b0a..d152acd 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -33,7 +33,7 @@ rng.modules.visualEditor = function(sandbox) { var metaTable = this.metaTable = this.node.find('#rng-visualEditor-meta table'); - this.metaTable.find('.rng-visualEditor-metaAddBtn').click(function() { + this.node.find('.rng-visualEditor-metaAddBtn').click(function() { var newRow = view._addMetaRow('', ''); $(newRow.find('td div')[0]).focus(); isDirty = true; @@ -52,7 +52,7 @@ rng.modules.visualEditor = function(sandbox) { } else { var input = $(''); input.appendTo('body').focus() - metaTable.find('.rng-visualEditor-metaAddBtn').focus(); + view.node.find('.rng-visualEditor-metaAddBtn').focus(); input.remove(); } e.preventDefault(); @@ -63,7 +63,7 @@ rng.modules.visualEditor = function(sandbox) { }, getMetaData: function() { var toret = {}; - this.metaTable.find('tr').not('.rng-visualEditor-addMetaRow').each(function() { + this.metaTable.find('tr').each(function() { var tr = $(this); var inputs = $(this).find('td [contenteditable]'); var key = $(inputs[0]).text(); @@ -75,7 +75,7 @@ rng.modules.visualEditor = function(sandbox) { }, setMetaData: function(metadata) { var view = this; - this.metaTable.find('tr').not('.rng-visualEditor-addMetaRow').remove(); + this.metaTable.find('tr').remove(); _.each(_.keys(metadata), function(key) { view._addMetaRow(key, metadata[key]); }); @@ -91,13 +91,38 @@ rng.modules.visualEditor = function(sandbox) { node.addClass('rng-current'); }, _addMetaRow: function(key, value) { - var addRow = this.metaTable.find('.rng-visualEditor-addMetaRow'); var newRow = $(sandbox.getTemplate('metaItem')({key: key || '', value: value || ''})); - newRow.insertBefore(addRow); + newRow.appendTo(this.metaTable); return newRow; } }; + + + var sideBarView = { + node: view.node.find('#rng-visualEditor-sidebar'), + setup: function() { + var view = this; + this.node.find('#rng-visualEditor-sidebarButtons a').click(function(e) { + e.preventDefault(); + var target = $(e.currentTarget); + if(!target.attr('data-content-id')) + return; + view.selectTab(target.attr('data-content-id')); + }); + view.selectTab('rng-visualEditor-edit'); + }, + selectTab: function(id) { + this.node.find('.rng-visualEditor-sidebarContentItem').hide(); + this.node.find('#'+id).show(); + this.node.find('#rng-visualEditor-sidebarButtons li').removeClass('active'); + this.node.find('#rng-visualEditor-sidebarButtons li a[data-content-id=' + id + ']').parent().addClass('active'); + + } + + } + view.setup(); + sideBarView.setup(); var isDirty = false;