4

I was studying the code for the plugin below and wondering where and when does it tie the "Right Click" event. All it does is

Plugin reference link : http://www.javascripttoolbox.com/lib/contextmenu/

$(this).bind('contextmenu',function(e){cmenu.show(this,e);return false;});

and "contextmenu" is a custom jquery event type.

Can someone please explain how all this works

I did check there are click events but those are tied to the menu items and not the element to which the menu is tied.

Thanks

Answer: "contextmenu" is not a custom event type. It is actually another name (mapping etc) for 'right click'

Nilesh
  • 2,015
  • 3
  • 19
  • 21

2 Answers2

2

contextmenu is not a custom jQuery event (check out the MDC article on it here). All the plugin is doing is binding an event handler to this event and showing/hiding a menu.

Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
1

contextmenu is a javascript event that is triggered when the user right clicks on an element, if you want to use this event to implement your own function you can do something like this:

$("element").bind("contextmenu",function(){
    //your code here
});

what happens in the plug in code is the following:

$(this).bind('contextmenu',function(e){ //capture right click on "this" which 
                                        //is the element being clicked
   cmenu.show(this,e); //call function cmenu.show to show the menu and pass two arguments
                       //the element clicked "this: and the event data "e"

   return false; //this cancels the default context menu
});
amosrivera
  • 26,114
  • 9
  • 67
  • 76