X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/dcfd364712eefa84d96a477149f34a623cf7ddde..0add3b13ce4ef42557d9ca33342a159b80a4f42f:/modules/rng.js diff --git a/modules/rng.js b/modules/rng.js index e6f3c26..baa400d 100644 --- a/modules/rng.js +++ b/modules/rng.js @@ -20,27 +20,48 @@ rng.modules.rng = function(sandbox) { _.each(['visualEditor', 'sourceEditor'], function(moduleName) { sandbox.getModule(moduleName).start(); }); + }, + leaving: function(slug) { + if(slug === 'source' || slug === 'visual') { + var editor = sandbox.getModule(slug+'Editor'); + if(editor.isDirty()) { + sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit'); + editor.setDirty(false); + } + } } }; eventHandlers.sourceEditor = { ready: function() { addTab('Source', 'source', sandbox.getModule('sourceEditor').getView()); + sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument()); } }; eventHandlers.visualEditor = { ready: function() { addTab('Visual', 'visual', sandbox.getModule('visualEditor').getView()); + sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument()); } }; + eventHandlers.data = { + ready: function() { + sandbox.getModule('skelton').start(); + }, + documentChanged: function(document, reason) { + var slug = (reason === 'visual_edit' ? 'source' : 'visual'); + sandbox.getModule(slug+'Editor').setDocument(document); + } + } + /* api */ return { start: function() { - sandbox.getModule('skelton').start(); + sandbox.getModule('data').start(); }, handleEvent: function(moduleName, eventName, args) { if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {