3 return function(sandbox) {
\r
6 function addTab(title, slug, view) {
\r
7 sandbox.getModule('tabsManager').addTab(title, slug, view);
\r
10 /* Events handling */
\r
12 var eventHandlers = {};
\r
14 eventHandlers.skelton = {
\r
16 sandbox.getModule('tabsManager').start();
\r
18 'cmd.save': function() {
\r
19 var editorSlugs = ['visual', 'source'];
\r
20 var slug = sandbox.getModule('tabsManager').getCurrentSlug();
\r
21 if(_.contains(editorSlugs, slug)) {
\r
22 var editor = sandbox.getModule(slug+'Editor');
\r
23 if(editor.isDirty()) {
\r
24 sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit');
\r
25 editor.setDirty(false);
\r
28 sandbox.getModule('data').saveDocument();
\r
32 eventHandlers.tabsManager = {
\r
34 sandbox.getModule('skelton').setMainView(sandbox.getModule('tabsManager').getView());
\r
35 _.each(['visualEditor', 'sourceEditor', 'rng2'], function(moduleName) {
\r
36 sandbox.getModule(moduleName).start();
\r
39 leaving: function(slug) {
\r
40 if(slug === 'source' || slug === 'visual') {
\r
41 var editor = sandbox.getModule(slug+'Editor');
\r
42 if(editor.isDirty()) {
\r
43 sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit');
\r
44 editor.setDirty(false);
\r
48 showed: function(slug) {
\r
49 if(slug === 'visual')
\r
50 sandbox.getModule('visualEditor').onShowed();
\r
54 eventHandlers.sourceEditor = {
\r
56 addTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView());
\r
57 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
61 eventHandlers.visualEditor = {
\r
63 sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument());
\r
64 addTab(gettext('Visual'), 'visual', sandbox.getModule('visualEditor').getView());
\r
69 eventHandlers.data = {
\r
71 sandbox.getModule('skelton').start();
\r
73 documentChanged: function(document, reason) {
\r
74 var slug = (reason === 'visual_edit' ? 'source' : 'visual');
\r
75 sandbox.getModule(slug+'Editor').setDocument(document);
\r
77 savingStarted: function() {
\r
78 sandbox.getModule('skelton').deactivateCommand('save');
\r
79 sandbox.getModule('skelton').showMessage(gettext('Saving...'));
\r
81 savingEnded: function(status) {
\r
82 sandbox.getModule('skelton').activateCommand('save');
\r
83 sandbox.getModule('skelton').clearMessage();
\r
87 eventHandlers.rng2 = {
\r
89 addTab('rng2 test', 'rng2test', sandbox.getModule('rng2').getView());
\r
98 sandbox.getModule('data').start();
\r
100 handleEvent: function(moduleName, eventName, args) {
\r
102 wysiwigHandler.handleEvent(moduleName, eventName, args);
\r
103 else if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
104 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r