← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13074: make sure that only 1 click handler is attached in the .context namespace

 

------------------------------------------------------------
revno: 13074
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-11-29 15:59:00 +0100
message:
  make sure that only 1 click handler is attached in the .context namespace
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-11-28 10:34:47 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js	2013-11-29 14:59:00 +0000
@@ -60,7 +60,12 @@
   var $menu = $('#' + config.menuId);
   var $menuItems = $menu.find('ul');
 
-  $menuItems.on('touchend click', 'li', function( e ) {
+  // make sure that all old event handler are removed (with .context namespace)
+  $(document).off('click.context');
+  $list.off('click.context');
+  $menuItems.off('click.context');
+
+  $menuItems.on('click.context', 'li', function( e ) {
     var context = {};
 
     $.each(config.listItemProps, function( idx, val ) {
@@ -73,9 +78,11 @@
 
     $menu.hide();
     fn(context);
+
+    return false;
   });
 
-  $list.on('click', 'td', function( e ) {
+  $list.on('click.context', 'td', function( e ) {
     $menu.show();
     $menu.css({left: e.pageX, top: e.pageY});
 
@@ -91,7 +98,7 @@
     return false;
   });
 
-  $(document).on('touchend click', function() {
+  $(document).on('click.context', function() {
     if( $menu.is(":visible") ) {
       $menu.hide();
     }