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', '.rng', function(e) { $(e.target).addClass('rng-hover')});
\r
18 this.node.on('mouseout', '.rng', function(e) { $(e.target).removeClass('rng-hover')});
\r
19 this.node.on('click', '.rng', function(e) {
\r
20 view._markSelected($(e.target));
\r
23 this.node.on('keyup', function(e) {
\r
24 var anchor = $(window.getSelection().anchorNode);
\r
25 if(anchor[0].nodeType === Node.TEXT_NODE)
\r
26 anchor = anchor.parent();
\r
27 if(!anchor.hasClass('rng'))
\r
29 view._markSelected(anchor);
\r
32 getMetaData: function() {
\r
34 this.node.find('#rng-visualEditor-meta table tr').each(function() {
\r
36 var key = $(tr.find('td')[0]).html();
\r
37 var value = $(tr.find('td input')[0]).val();
\r
43 setMetaData: function(metadata) {
\r
44 var table = this.node.find('#rng-visualEditor-meta table');
\r
46 _.each(_.keys(metadata), function(key) {
\r
47 $(sandbox.getTemplate('metaItem')({key: key, value: metadata[key]})).appendTo(table);
\r
50 setBody: function(HTMLTree) {
\r
51 this.node.find('#rng-visualEditor-content').html(HTMLTree);
\r
53 getBody: function() {
\r
54 return this.node.find('#rng-visualEditor-content').html();
\r
56 _markSelected: function(node) {
\r
57 this.node.find('.rng').removeClass('rng-current');
\r
58 node.addClass('rng-current');
\r
63 var isDirty = false;
\r
68 sandbox.publish('ready');
\r
70 getView: function() {
\r
73 setDocument: function(xml) {
\r
74 var transformed = transformations.fromXML.getDocumentDescription(xml);
\r
75 view.setBody(transformed.HTMLTree);
\r
76 view.setMetaData(transformed.metadata);
\r
79 getDocument: function() {
\r
80 return transformations.toXML.getXML({HTMLTree: view.getBody(), metadata: view.getMetaData()});
\r
82 isDirty: function() {
\r
85 setDirty: function(dirty) {
\r