fix problem with delete
[fnpeditor.git] / src / fnpjs / runner.js
index 6c28a61..0dd52e5 100644 (file)
@@ -15,7 +15,8 @@ var Runner = function(app, modules) {
         plugins = [],
         actionDefinitions = {},
         config,
         plugins = [],
         actionDefinitions = {},
         config,
-        actionsAppObject;
+        actionsAppObject,
+        currentContextMenu;
         
     _.each(_.keys(modules || {}), function(moduleName) {
         if(_.contains(app.permissions[moduleName] || [], 'handleEvents')) {
         
     _.each(_.keys(modules || {}), function(moduleName) {
         if(_.contains(app.permissions[moduleName] || [], 'handleEvents')) {
@@ -33,10 +34,6 @@ var Runner = function(app, modules) {
             return bootstrappedData[moduleName];
         };
         
             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) {
         this.publish = function(eventName) {
             var eventArgs = Array.prototype.slice.call(arguments, 1);
             _.each(eventListeners, function(listenerModuleName) {
@@ -82,9 +79,18 @@ var Runner = function(app, modules) {
         this.registerActionsAppObject = function(_actionsAppObject) {
             actionsAppObject = _actionsAppObject;
         };
         this.registerActionsAppObject = function(_actionsAppObject) {
             actionsAppObject = _actionsAppObject;
         };
+
+        this.showContextMenu = function(menu, coors) {
+            if(currentContextMenu) {
+                currentContextMenu.close();
+            }
+            currentContextMenu = menu;
+            $(config.rootSelector).append(menu.dom);
+            menu.dom.css({top: coors.y, left: coors.x});
+            menu.show();
+        };
     };
     };
-    
-    
+      
     this.setBootstrappedData = function(moduleName, data) {
         bootstrappedData[moduleName] = data;
     };
     this.setBootstrappedData = function(moduleName, data) {
         bootstrappedData[moduleName] = data;
     };
@@ -124,6 +130,13 @@ var Runner = function(app, modules) {
         app.initModules.forEach(function(moduleName) {
             getModuleInstance(moduleName).start();
         });
         app.initModules.forEach(function(moduleName) {
             getModuleInstance(moduleName).start();
         });
+
+        $(config.rootSelector)[0].addEventListener('click', function(e) {
+            if(currentContextMenu && !currentContextMenu.dom[0].contains(e.target)) {
+                currentContextMenu.close();
+                currentContextMenu = null;
+            }
+        }, true);
     };
 };
 
     };
 };