1 rng.modules.visualEditor = function(sandbox) {
\r
2 var transformations = rng.modules.visualEditor.transformations;
\r
5 node: $(sandbox.getTemplate('main')()),
\r
9 this.node.find('#rng-visualEditor-content').on('keyup', function() {
\r
13 this.node.find('#rng-visualEditor-meta').on('keyup', function() {
\r
17 this.node.on('mouseover', '[wlxml-tag]', function(e) { $(e.target).addClass('rng-hover')});
\r
18 this.node.on('mouseout', '[wlxml-tag]', function(e) { $(e.target).removeClass('rng-hover')});
\r
19 this.node.on('click', '[wlxml-tag]', function(e) {
\r
20 console.log('clicked node type: '+e.target.nodeType);
\r
21 view._markSelected($(e.target));
\r
24 this.node.on('keyup', '#rng-visualEditor-contentWrapper', function(e) {
\r
25 var anchor = $(window.getSelection().anchorNode);
\r
26 if(anchor[0].nodeType === Node.TEXT_NODE)
\r
27 anchor = anchor.parent();
\r
28 if(!anchor.is('[wlxml-tag]'))
\r
30 view._markSelected(anchor);
\r
34 var metaTable = this.metaTable = this.node.find('#rng-visualEditor-meta table');
\r
36 this.node.find('.rng-visualEditor-metaAddBtn').click(function() {
\r
37 var newRow = view._addMetaRow('', '');
\r
38 $(newRow.find('td div')[0]).focus();
\r
42 this.metaTable.on('click', '.rng-visualEditor-metaRemoveBtn', function(e) {
\r
43 $(e.target).closest('tr').remove();
\r
47 this.metaTable.on('keydown', '[contenteditable]', function(e) {
\r
48 console.log(e.which);
\r
49 if(e.which === 13) {
\r
50 if($(document.activeElement).hasClass('rng-visualEditor-metaItemKey')) {
\r
51 metaTable.find('.rng-visualEditor-metaItemValue').focus();
\r
53 var input = $('<input>');
\r
54 input.appendTo('body').focus()
\r
55 view.node.find('.rng-visualEditor-metaAddBtn').focus();
\r
64 getMetaData: function() {
\r
66 this.metaTable.find('tr').each(function() {
\r
68 var inputs = $(this).find('td [contenteditable]');
\r
69 var key = $(inputs[0]).text();
\r
70 var value = $(inputs[1]).text();
\r
76 setMetaData: function(metadata) {
\r
78 this.metaTable.find('tr').remove();
\r
79 _.each(_.keys(metadata), function(key) {
\r
80 view._addMetaRow(key, metadata[key]);
\r
83 setBody: function(HTMLTree) {
\r
84 this.node.find('#rng-visualEditor-content').html(HTMLTree);
\r
86 getBody: function() {
\r
87 return this.node.find('#rng-visualEditor-content').html();
\r
89 _markSelected: function(node) {
\r
90 this.node.find('.rng-current').removeClass('rng-current');
\r
91 node.addClass('rng-current');
\r
92 mediator.nodeSelected(node);
\r
94 _addMetaRow: function(key, value) {
\r
95 var newRow = $(sandbox.getTemplate('metaItem')({key: key || '', value: value || ''}));
\r
96 newRow.appendTo(this.metaTable);
\r
102 var sideBarView = {
\r
103 node: view.node.find('#rng-visualEditor-sidebar'),
\r
104 setup: function() {
\r
106 this.node.find('#rng-visualEditor-sidebarButtons a').click(function(e) {
\r
107 e.preventDefault();
\r
108 var target = $(e.currentTarget);
\r
109 if(!target.attr('data-content-id'))
\r
111 view.selectTab(target.attr('data-content-id'));
\r
113 view.selectTab('rng-visualEditor-edit');
\r
115 selectTab: function(id) {
\r
116 this.node.find('.rng-visualEditor-sidebarContentItem').hide();
\r
117 this.node.find('#'+id).show();
\r
118 this.node.find('#rng-visualEditor-sidebarButtons li').removeClass('active');
\r
119 this.node.find('#rng-visualEditor-sidebarButtons li a[data-content-id=' + id + ']').parent().addClass('active');
\r
122 updateEditPane: function(node) {
\r
123 var pane = this.node.find('#rng-visualEditor-edit');
\r
124 pane.html( $(sandbox.getTemplate('editPane')({tag: node.attr('wlxml-tag'), klass: node.attr('wlxml-class')})));
\r
129 sideBarView.setup();
\r
132 nodeSelected: function(node) {
\r
133 sideBarView.updateEditPane(node);
\r
137 var isDirty = false;
\r
142 start: function() {
\r
143 sandbox.publish('ready');
\r
145 getView: function() {
\r
148 setDocument: function(xml) {
\r
149 var transformed = transformations.fromXML.getDocumentDescription(xml);
\r
150 view.setBody(transformed.HTMLTree);
\r
151 view.setMetaData(transformed.metadata);
\r
154 getDocument: function() {
\r
155 return transformations.toXML.getXML({HTMLTree: view.getBody(), metadata: view.getMetaData()});
\r
157 isDirty: function() {
\r
160 setDirty: function(dirty) {
\r