From: Aleksander Ɓukasz Date: Wed, 10 Apr 2013 11:59:24 +0000 (+0200) Subject: Refactoring visualEditor module X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/fd01330786845fedb31dd93439bf8b1c82cd56c6 Refactoring visualEditor module --- diff --git a/modules/visualEditor.js b/modules/visualEditor.js index b22aa7d..2fecfde 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -1,15 +1,9 @@ rng.modules.visualEditor = function(sandbox) { + var transformations = rng.modules.visualEditor.transformations; var view = $(sandbox.getTemplate('main')()); var isDirty = false; - var document2html = function(document) { - return document; - } - - var html2document = function() { - return $('#rng-visualEditor-content').text(); - } $('#rng-visualEditor-content', view).on('keyup', function() { isDirty = true; @@ -22,12 +16,13 @@ rng.modules.visualEditor = function(sandbox) { getView: function() { return view; }, - setDocument: function(document) { - $('#rng-visualEditor-content', view).html(document2html(document)); + setDocument: function(xml) { + var transformed = transformations.fromXML.getDocumentDescription(xml); + $('#rng-visualEditor-content', view).html(transformed.HTMLTree); isDirty = false; }, getDocument: function() { - return html2document(); + return transformations.toXML.getXML({HTMLTree: $('#rng-visualEditor-content').text(), metadata: {}}); }, isDirty: function() { return isDirty; diff --git a/modules/visualEditor.transformations.js b/modules/visualEditor.transformations.js new file mode 100644 index 0000000..c317314 --- /dev/null +++ b/modules/visualEditor.transformations.js @@ -0,0 +1,23 @@ +rng.modules.visualEditor.transformations = {}; + +rng.modules.visualEditor.transformations.fromXML = { + getHTMLTree: function(xml) { + return xml; + }, + getMetaData: function(xml) { + return {}; + }, + getDocumentDescription: function(xml) { + return { + HTMLTree: this.getHTMLTree(xml), + metadata: this.getMetaData(xml) + } + } + +} + +rng.modules.visualEditor.transformations.toXML = { + getXML: function(documentDescription) { + return documentDescription.HTMLTree; + } +} \ No newline at end of file