From fd01330786845fedb31dd93439bf8b1c82cd56c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 10 Apr 2013 13:59:24 +0200 Subject: [PATCH 1/1] Refactoring visualEditor module --- modules/visualEditor.js | 15 +++++---------- modules/visualEditor.transformations.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 modules/visualEditor.transformations.js 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 -- 2.20.1