1

I'm trying to integrate this plugin into my app: https://github.com/mar10/jquery-ui-contextmenu/blob/master/jquery.ui-contextmenu.js

I'm completely baffled as to how right-clicking an element that matches the delegate selector on an initialized element ends up firing the 'contextmenu' event on the bound element... I've been reading this code for HOURS and I'm still not seeing anything like:

ui.target.on('right-click', opt.selector, function(){ this._tigger('contextmenu')});

or something along those lines.. I see no references to event.which() (for mouse button detection) etc..

I can see the custom "contextmenu" event being bound to the delegate on line 79, but I'm not seeing anywhere in the code that shows how this custom even actually gets FIRED upon right-clicking an element...

Since I can't see any triggering code.. I'm assuming the jQuery-UI widget factory is somehow "automagically" doing the triggering.. but that still begs the question, how is this plugin telling the jquery-ui framework, "use right click event as my 'trigger'"??

how in the world is this working????? PLEASE HELP!

RavenHursT
  • 2,336
  • 1
  • 25
  • 46
  • 2
    The event used is [oncontextmenu](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.oncontextmenu) – adeneo Dec 06 '13 at 22:41
  • https://github.com/mar10/jquery-ui-contextmenu/blob/master/jquery.ui-contextmenu.js#L75 and taphold – Kevin B Dec 06 '13 at 22:42
  • So @adeneo, doing something like: `$(window).on('contextmenu', function(){ .. });` is essentially the same thing as: `window.oncontextmenu = function(){ .. }` ? – RavenHursT Dec 06 '13 at 22:47
  • Yes, when using jQuery (or addEventListener) you remove the leading "on" and just use the event name, so that seems right. – adeneo Dec 06 '13 at 22:50
  • wow.. thank you! this has had my development stalled for two days now! – RavenHursT Dec 06 '13 at 22:53
  • @adeneo can you add that as an answer.. something like "he's piggy-backing on the window's native "oncontextmenu" event so I can mark it as correct and get you credit? – RavenHursT Dec 06 '13 at 22:54

1 Answers1

1

The plugin isn't listening for click events, it's listening for the oncontextmenu event which fires whenever the context menu is triggered, which most of the time is whenever something is right clicked

adeneo
  • 312,895
  • 29
  • 395
  • 388