1 var Runner = function($, _, app) {
\r
3 function getModuleInstance(moduleName) {
\r
4 var module = moduleInstances[moduleName] = (moduleInstances[moduleName] || app.modules[moduleName](new Sandbox(moduleName)));
\r
8 var bootstrappedData = {},
\r
10 moduleInstances = {},
\r
11 eventListeners = [];
\r
13 _.each(_.keys(app.modules || {}), function(moduleName) {
\r
14 if(_.contains(app.permissions[moduleName] || [], 'handleEvents')) {
\r
15 eventListeners.push(moduleName)
\r
21 var Sandbox = function(moduleName) {
\r
25 this.getBootstrappedData = function() {
\r
26 return bootstrappedData[moduleName];
\r
29 this.getTemplate = function(templateName) {
\r
30 return _.template($('[data-template-name="' + moduleName + '.' + templateName + '"]').html().trim());
\r
33 this.publish = function(eventName) {
\r
34 var eventArgs = Array.prototype.slice.call(arguments, 1)
\r
35 _.each(eventListeners, function(listenerModuleName) {
\r
36 var listener = moduleInstances[listenerModuleName];
\r
38 listener.handleEvent(moduleName, eventName, eventArgs);
\r
43 var permissions = app.permissions[moduleName];
\r
45 this.getModule = _.contains(permissions, 'getModule') ? function(requestedModuleName) {
\r
46 return getModuleInstance(requestedModuleName);
\r
49 this.getDOM = _.contains(permissions, 'getDOM') ? function() {
\r
50 return $(options.rootSelector);
\r
56 this.setBootstrappedData = function(moduleName, data) {
\r
57 bootstrappedData[moduleName] = data;
\r
60 this.start = function(_options) {
\r
61 options = _.extend({
\r
62 rootSelector: 'body'
\r
64 app.initModules.forEach(function(moduleName) {
\r
65 getModuleInstance(moduleName).start();
\r