swisnl / jQuery-contextMenu

jQuery contextMenu plugin & polyfill
https://swisnl.github.io/jQuery-contextMenu/
MIT License
2.24k stars 744 forks source link

Enhancement to allow dblclick to pass through when left-click is bound to context menu #255

Open mnewnham opened 9 years ago

mnewnham commented 9 years ago

This code allows dblclick to be bound to another event when using left-click for the context menu. Ive tested it in chrome,firefox, IE9 and IE11. Obviously there is a 500ms delay in opening the menu , and it appears for half a second when the doubleclick event fires. but I can live with that. I'm no expert in jquery so it could probably stand improving. like making the dblclick function clear the timer interval for the context menu but thats beyond my expertise:

At about line 275:

dblclick: function(e){
       /*
        * this suppresses the menu 
       */
    copyOfObject= $(this);
    setTimeout(function(){
        copyOfObject.contextMenu("hide");
    },1000);

},

// contextMenu left-click trigger
click: function(e) {

    e.preventDefault();
    e.stopImmediatePropagation();

        /*
         * Why do we need to use a copy of the object in the timeout, I've no idea
        * but it doesn't work if we dont
        */
    copyOfObject = $(this);
       /* 
        * Adding the timeout allows the click function to pass through doubleclick events
       */
    setTimeout(function() {
        copyOfObject.trigger($.Event("contextmenu", { data: e.data, pageX: e.pageX, pageY: e.pageY }));
    },500);
},

At about line 1360:

case 'left':
         $context.on('click' + o.ns, o.selector, o, handle.click);
         $context.on('dblclick' + o.ns, o.selector, o, handle.dblclick);
          break;
bbrala commented 9 years ago

I really dont like adding a delay to the whole menu for this really. And if not then it would need to be an option or something, but i feel this might not really be a common usecase.

mnewnham commented 9 years ago
  1. I agree that it is a little unusual, although I'm not the first person to ask for this requirement.
  2. I agree totally that it should not be a standard feature, as the slight delay when showing the menu is noticeable, My use of this is not for an internet-accessible application, so for me that's not a problem.
  3. I think with a little expertise in cleaning up my code, it might be useful to have it available as a separate plug-in, extension, etc. It might even be possible to reduce the delay