From: Aleksander Ɓukasz Date: Wed, 29 May 2013 07:43:26 +0000 (+0200) Subject: Cleaning up files structure X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/39aef1850307018fab6670a2c64b6f2ba0f574ae?ds=sidebyside Cleaning up files structure --- diff --git a/entrypoint.js b/entrypoint.js index 70659e9..ac80979 100644 --- a/entrypoint.js +++ b/entrypoint.js @@ -19,7 +19,7 @@ requirejs([ 'libs/jquery-1.9.1.min', - 'runner', + 'fnpjs/runner', 'rng', './modules', 'libs/bootstrap/js/bootstrap.min' diff --git a/fnpjs/runner.js b/fnpjs/runner.js new file mode 100644 index 0000000..8cce7d2 --- /dev/null +++ b/fnpjs/runner.js @@ -0,0 +1,77 @@ +define(['libs/jquery-1.9.1.min', 'libs/underscore-min'], function($, _) { + +var Runner = function(app, modules) { + + function getModuleInstance(moduleName) { + var module = moduleInstances[moduleName] = (moduleInstances[moduleName] || modules[moduleName](new Sandbox(moduleName))); + return module; + } + + var bootstrappedData = {}, + options = {}, + moduleInstances = {}, + eventListeners = []; + + _.each(_.keys(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) { + console.log(moduleName + ': ' + 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(); + }); + } +} + +return { + Runner: Runner +} + +}); \ No newline at end of file diff --git a/runner.js b/runner.js deleted file mode 100644 index 8cce7d2..0000000 --- a/runner.js +++ /dev/null @@ -1,77 +0,0 @@ -define(['libs/jquery-1.9.1.min', 'libs/underscore-min'], function($, _) { - -var Runner = function(app, modules) { - - function getModuleInstance(moduleName) { - var module = moduleInstances[moduleName] = (moduleInstances[moduleName] || modules[moduleName](new Sandbox(moduleName))); - return module; - } - - var bootstrappedData = {}, - options = {}, - moduleInstances = {}, - eventListeners = []; - - _.each(_.keys(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) { - console.log(moduleName + ': ' + 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(); - }); - } -} - -return { - Runner: Runner -} - -}); \ No newline at end of file