浏览代码

HUE-2381 [fb] Right click menu is not always hidden when clicking outside

Added event handler to determine if context click occurs outside of file list in order to close the context menu
Paul McCaughtry 11 年之前
父节点
当前提交
b6edd5ce00
共有 1 个文件被更改,包括 16 次插入7 次删除
  1. 16 7
      apps/filebrowser/src/filebrowser/templates/listdir_components.mako

+ 16 - 7
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -1254,6 +1254,15 @@ from django.utils.translation import ugettext as _
       };
     };
 
+    // hide the context menu based on specific events
+    var hideContextMenu = function () {
+      var cm = $('.context-menu');
+
+      if (cm.is(':visible')) {
+        cm.css({ display: 'none' });
+      }
+    };
+
     var viewModel = new FileBrowserModel([], null, [], "/");
     ko.applyBindings(viewModel);
 
@@ -1274,17 +1283,17 @@ from django.utils.translation import ugettext as _
 
       // hide context menu
       $('body').on('click', function (e) {
-        var cm = $('.context-menu');
-        if (cm.is(':visible')) {
-          cm.css({ display: 'none' });
+        hideContextMenu();
+      });
+
+      $('body').on('contextmenu', function (e) {
+        if ($.inArray(e.toElement, $('.datatables *')) === -1) {
+          hideContextMenu();
         }
       });
 
       $('body').on('contextmenu', '.context-menu', function (e) {
-        var cm = $('.context-menu');
-        if (cm.is(':visible')) {
-          cm.css({ display: 'none' });
-        }
+        hideContextMenu();
       });
 
       // Drag and drop uploads from anywhere on filebrowser screen