← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13114: hide contextmenu on escape keypres event

 

------------------------------------------------------------
revno: 13114
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-12-03 09:37:21 +0100
message:
  hide contextmenu on escape keypres event
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js	2013-12-03 08:20:15 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js	2013-12-03 08:37:21 +0000
@@ -53,8 +53,11 @@
   functionResolver: dhis2.contextmenu.utils.findFnInWindowScope
 };
 
+dhis2.contextmenu.config = dhis2.contextmenu.defaultOptions;
+
 dhis2.contextmenu.makeContextMenu = function( options ) {
-  var config = $.extend({}, dhis2.contextmenu.defaultOptions, options);
+  dhis2.contextmenu.config = $.extend({}, dhis2.contextmenu.defaultOptions, options);
+  var config = dhis2.contextmenu.config;
 
   var $list = $('#' + config.listId);
   var $menu = $('#' + config.menuId);
@@ -105,12 +108,26 @@
   });
 
   $(document).on('click.context', function() {
-    if( $menu.is(":visible") ) {
-      $menu.hide();
-    }
-
-    $list.find('td').removeClass(config.menuItemActiveClass);
-
+    dhis2.contextmenu.disable();
     $menu.removeData('id');
   });
+
+  $(document).keyup(function( e ) {
+    if( e.keyCode == 27 ) {
+      dhis2.contextmenu.disable();
+    }
+  });
+};
+
+dhis2.contextmenu.disable = function() {
+  var config = dhis2.contextmenu.config;
+
+  var $list = $('#' + config.listId);
+  var $menu = $('#' + config.menuId);
+
+  if( $menu.is(":visible") ) {
+    $menu.hide();
+  }
+
+  $list.find('td').removeClass(config.menuItemActiveClass);
 };