fnpjs: context menu support
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 1 Jul 2014 13:16:45 +0000 (15:16 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:26:13 +0000 (16:26 +0200)
src/fnpjs/runner.js

index f3edd31..0dd52e5 100644 (file)
@@ -15,7 +15,8 @@ var Runner = function(app, modules) {
         plugins = [],
         actionDefinitions = {},
         config,
-        actionsAppObject;
+        actionsAppObject,
+        currentContextMenu;
         
     _.each(_.keys(modules || {}), function(moduleName) {
         if(_.contains(app.permissions[moduleName] || [], 'handleEvents')) {
@@ -78,9 +79,18 @@ var Runner = function(app, modules) {
         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;
     };
@@ -120,6 +130,13 @@ var Runner = function(app, modules) {
         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);
     };
 };