syntax errors free
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 8 Apr 2013 08:34:14 +0000 (10:34 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 8 Apr 2013 08:34:14 +0000 (10:34 +0200)
editor.css [new file with mode: 0644]
editor.js [deleted file]
modules/rng.js [new file with mode: 0644]
modules/skelton.js [new file with mode: 0644]
modules/sourceEditor.js [new file with mode: 0644]
modules/tabsManager.js [new file with mode: 0644]
modules/visualEditor.js [new file with mode: 0644]
rng.js [new file with mode: 0644]
runner.js [new file with mode: 0644]

diff --git a/editor.css b/editor.css
new file mode 100644 (file)
index 0000000..b426734
--- /dev/null
@@ -0,0 +1,12 @@
+body {\r
+    padding-top: 30px;\r
+}\r
+\r
+#publication_content {\r
+    height: 300px;\r
+    overflow-y: scroll;\r
+}\r
+\r
+.rng-tab-content {\r
+    display: none;\r
+}
\ No newline at end of file
diff --git a/editor.js b/editor.js
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/modules/rng.js b/modules/rng.js
new file mode 100644 (file)
index 0000000..0d40c2e
--- /dev/null
@@ -0,0 +1,45 @@
+rng.modules.rng = function(sandbox) {\r
+\r
+    function addTab(title, view) {\r
+        sandbox.getModule('tabsModule').addTab(title, view);\r
+    }\r
+    \r
+    /* Events handling */\r
+    \r
+    eventHandlers = {};\r
+    \r
+    eventHandlers.skelton = {\r
+        ready: function() {\r
+            sandbox.getModule('tabsManager').start();\r
+        }\r
+    };\r
+    \r
+    eventHandlers.tabsManager = {\r
+        ready: function() {\r
+            sandbox.getModule('skelton').setMainView(sandbox.getModule('tabsManager').getView());\r
+            _.each(['sourceEditor', 'visualEditor'], function(moduleName) {\r
+                sandbox.getModule(moduleName).start();\r
+            });\r
+        }\r
+    };\r
+    \r
+    eventHandlers.sourceEditor = {\r
+        ready: function() {\r
+            addTab('Source', sandbox.getModule('sourceEditor').getView());\r
+        }\r
+    };\r
+    \r
+    \r
+    /* api */\r
+    \r
+    return {\r
+        start: function() {\r
+            sandbox.getModule('skelton').start();\r
+        },\r
+        handleEvent: function(moduleName, eventName, args) {\r
+            if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {\r
+                eventHandlers[moduleName][eventName].apply(eventHandlers, args);\r
+            }\r
+        }\r
+    }\r
+};
\ No newline at end of file
diff --git a/modules/skelton.js b/modules/skelton.js
new file mode 100644 (file)
index 0000000..2dbd948
--- /dev/null
@@ -0,0 +1,10 @@
+rng.modules.skelton = function(sandbox) {\r
+    return {\r
+        start: function() {\r
+            sandbox.publish('ready');\r
+        },\r
+        setMainView: function(view) {\r
+            sandbox.getDOM().html(view);\r
+        }\r
+    }\r
+};
\ No newline at end of file
diff --git a/modules/sourceEditor.js b/modules/sourceEditor.js
new file mode 100644 (file)
index 0000000..59b663e
--- /dev/null
@@ -0,0 +1,8 @@
+rng.modules.sourceEditor = function(sandbox) {\r
+\r
+    return {\r
+        start: function() {\r
+        }\r
+    \r
+    }\r
+};
\ No newline at end of file
diff --git a/modules/tabsManager.js b/modules/tabsManager.js
new file mode 100644 (file)
index 0000000..a57a47e
--- /dev/null
@@ -0,0 +1,36 @@
+rng.modules.tabsManager = function(sandbox) {\r
+\r
+    var $ = sandbox.$;\r
+    \r
+    var view = $(sandbox.getTemplate('main')());\r
+    \r
+    var tabContent = {};\r
+    \r
+    function selectTab(tabCode) {\r
+        var tabBar = $(view, '#rng-main-tabs');\r
+        var prevTabCode = tabBar.find('li.active a').attr('href').substr(1);\r
+        tabBar.find('li').removeClass('active');\r
+        tabBar.find('a[href=#' + tabCode + ']').parent().addClass('active');\r
+        $(view, '.rng-tab-content').hide();\r
+        $(view, '#rng-tab-content-' + tabCode).show();\r
+    }\r
+    \r
+    $('#rng-main-tabs li a').click(function(e) {\r
+        selectTab($(e.target).attr('href').substr(1));\r
+    });\r
+    \r
+    return {\r
+        start: function() {\r
+            sandbox.publish('ready');\r
+        },\r
+        \r
+        getView: function() {\r
+            return view;\r
+        },\r
+        \r
+        addTab: function(title, view) {\r
+            tabContent[title] = view;\r
+        }\r
+    }\r
+\r
+};
\ No newline at end of file
diff --git a/modules/visualEditor.js b/modules/visualEditor.js
new file mode 100644 (file)
index 0000000..29506a5
--- /dev/null
@@ -0,0 +1,8 @@
+rng.modules.visualEditor = function(sandbox) {\r
+\r
+    return {\r
+        start: function() {\r
+        }\r
+    \r
+    }\r
+};
\ No newline at end of file
diff --git a/rng.js b/rng.js
new file mode 100644 (file)
index 0000000..09ca0e4
--- /dev/null
+++ b/rng.js
@@ -0,0 +1,8 @@
+var rng = {
+    modules: {}, 
+    initModules: ['rng'],
+    permissions: {
+        'skelton': ['getDOM'],
+        'rng': ['getModule', 'handleEvents']
+    }
+};
\ No newline at end of file
diff --git a/runner.js b/runner.js
new file mode 100644 (file)
index 0000000..e03d577
--- /dev/null
+++ b/runner.js
@@ -0,0 +1,68 @@
+var Runner = function($, _, app) {\r
+\r
+    function getModuleInstance(moduleName) {\r
+        var module = moduleInstances[moduleName] = (moduleInstances[moduleName] || app.modules[moduleName](new Sandbox(moduleName)));\r
+        return module;\r
+    }\r
+\r
+    var bootstrappedData = {},\r
+        options = {},\r
+        moduleInstances = {},\r
+        eventListeners = [];\r
+        \r
+    _.each(_.keys(app.modules || {}), function(moduleName) {\r
+        if(_.contains(app.permissions[moduleName] || [], 'handleEvents')) {\r
+            eventListeners.push(moduleName)\r
+        }\r
+    });\r
+\r
+    \r
+        \r
+    var Sandbox = function(moduleName) {\r
+        this.$ = $;\r
+        this._ = _;\r
+        \r
+        this.getBootstrappedData = function() {\r
+            return bootstrappedData[moduleName];\r
+        }\r
+        \r
+        this.getTemplate = function(templateName) {\r
+            return _.template($('[data-template-name="' + moduleName + '.' + templateName + '"]').html().trim());\r
+        }\r
+        \r
+        this.publish = function(eventName) {\r
+            var eventArgs = Array.prototype.slice.call(arguments, 1)\r
+            _.each(eventListeners, function(listenerModuleName) {\r
+                var listener = moduleInstances[listenerModuleName];\r
+                if(listener) {\r
+                    listener.handleEvent(moduleName, eventName, eventArgs);\r
+                }\r
+            });\r
+        }\r
+        \r
+        var permissions = app.permissions[moduleName];\r
+        \r
+        this.getModule = _.contains(permissions, 'getModule') ? function(requestedModuleName) {\r
+            return getModuleInstance(requestedModuleName);\r
+        } : undefined;\r
+        \r
+        this.getDOM = _.contains(permissions, 'getDOM') ? function() {\r
+            return $(options.rootSelector);\r
+        } : undefined;\r
+        \r
+    };\r
+    \r
+    \r
+    this.setBootstrappedData = function(moduleName, data) {\r
+        bootstrappedData[moduleName] = data;\r
+    };\r
+    \r
+    this.start = function(_options) {\r
+        options = _.extend({\r
+            rootSelector: 'body'\r
+        }, _options);\r
+        app.initModules.forEach(function(moduleName) {\r
+            getModuleInstance(moduleName).start();\r
+        });\r
+    }\r
+};
\ No newline at end of file