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