1 rng.modules.rng = function(sandbox) {
\r
3 function addTab(title, slug, view) {
\r
4 sandbox.getModule('tabsManager').addTab(title, slug, view);
\r
7 /* Events handling */
\r
11 eventHandlers.skelton = {
\r
13 sandbox.getModule('tabsManager').start();
\r
15 'cmd.save': function() {
\r
16 var editorSlugs = ['visual', 'source'];
\r
17 var slug = sandbox.getModule('tabsManager').getCurrentSlug();
\r
18 if(_.contains(editorSlugs, slug)) {
\r
19 var editor = sandbox.getModule(slug+'Editor');
\r
20 if(editor.isDirty()) {
\r
21 sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit');
\r
22 editor.setDirty(false);
\r
25 sandbox.getModule('data').saveDocument();
\r
29 eventHandlers.tabsManager = {
\r
31 sandbox.getModule('skelton').setMainView(sandbox.getModule('tabsManager').getView());
\r
32 _.each(['visualEditor', 'sourceEditor'], function(moduleName) {
\r
33 sandbox.getModule(moduleName).start();
\r
36 leaving: function(slug) {
\r
37 if(slug === 'source' || slug === 'visual') {
\r
38 var editor = sandbox.getModule(slug+'Editor');
\r
39 if(editor.isDirty()) {
\r
40 sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit');
\r
41 editor.setDirty(false);
\r
47 eventHandlers.sourceEditor = {
\r
49 addTab('Source', 'source', sandbox.getModule('sourceEditor').getView());
\r
50 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
54 eventHandlers.visualEditor = {
\r
56 addTab('Visual', 'visual', sandbox.getModule('visualEditor').getView());
\r
57 sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument());
\r
61 eventHandlers.data = {
\r
63 sandbox.getModule('skelton').start();
\r
65 documentChanged: function(document, reason) {
\r
66 var slug = (reason === 'visual_edit' ? 'source' : 'visual');
\r
67 sandbox.getModule(slug+'Editor').setDocument(document);
\r
76 sandbox.getModule('data').start();
\r
78 handleEvent: function(moduleName, eventName, args) {
\r
79 if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
80 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r