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', 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
33 getMetaData: function() {
\r
35 this.node.find('#rng-visualEditor-meta table tr').each(function() {
\r
37 var key = $(tr.find('td')[0]).html();
\r
38 var value = $(tr.find('td input')[0]).val();
\r
44 setMetaData: function(metadata) {
\r
45 var table = this.node.find('#rng-visualEditor-meta table');
\r
47 _.each(_.keys(metadata), function(key) {
\r
48 $(sandbox.getTemplate('metaItem')({key: key, value: metadata[key]})).appendTo(table);
\r
51 setBody: function(HTMLTree) {
\r
52 this.node.find('#rng-visualEditor-content').html(HTMLTree);
\r
54 getBody: function() {
\r
55 return this.node.find('#rng-visualEditor-content').html();
\r
57 _markSelected: function(node) {
\r
58 this.node.find('.rng-current').removeClass('rng-current');
\r
59 node.addClass('rng-current');
\r
64 var isDirty = false;
\r
69 sandbox.publish('ready');
\r
71 getView: function() {
\r
74 setDocument: function(xml) {
\r
75 var transformed = transformations.fromXML.getDocumentDescription(xml);
\r
76 view.setBody(transformed.HTMLTree);
\r
77 view.setMetaData(transformed.metadata);
\r
80 getDocument: function() {
\r
81 return transformations.toXML.getXML({HTMLTree: view.getBody(), metadata: view.getMetaData()});
\r
83 isDirty: function() {
\r
86 setDirty: function(dirty) {
\r