swisnl / jQuery-contextMenu

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

Jquery-contextMenu does not trigger the event on the new target element #771

Open H-GhaziSultan opened 6 months ago

H-GhaziSultan commented 6 months ago

I am using the jQuery contextMenu library v2.9.2. I want to close the context menu by clicking outside the context-menu div but I also want to focus on the element where I just clicked (new target).

I know jQuery contextMenu has a hidden layer and that layer has a handler "layerClick" which hides the context menu and also gets the new target element inside this handler. But the problem is jQuery trigger method does not trigger the event on a new target element because the event points to the hidden layer (id="context-menu-layer"). Please see the attached code from the library (line no 472 & 473):

Before my changes: $(target).trigger(e); root.$layer.show();

After my changes: I need to set the new target explicitly then it triggers the event on a new target and it gets focus.

e.target = target; $(target).trigger(e); root.$layer.show();

It seems like it is a bug in jQuery-contextMenu. Please correct me if I am wrong.