0

I'm trying to listen to a right-click event on a document, on which a pop-up menu (goog.ui.popupmenu) should be created. The very first time, the menu is created on right-click, but after that its created even on left clicks.

I tried detaching the object from the element when the first time event is received. But that doesnt seem to work.

Here's what I'm doing:

goog.events.listen(element, goog.events.EventType.CONTEXTMENU, function(e) {
     e.preventDefault();
     this.menu();
}, true, this);

I'm testing this code on Chrome.

Sushanth --
  • 55,259
  • 9
  • 66
  • 105
SherinThomas
  • 1,881
  • 4
  • 16
  • 20
  • You could try listenonce: http://docs.closure-library.googlecode.com/git/closure_goog_events_events.js.html – HMR Jun 18 '13 at 08:55

1 Answers1

0

Your code works fine for me (at least the part which you shared). It reacts to the first and every other right click and never reacts to left click.

But you can make the element to react to right click by supplying true as the opt_contextMenu parameter of the attach method, such as like this:

popupMenu.attach(element, goog.positioning.Corner.TOP_LEFT, goog.positioning.Corner.BOTTOM_LEFT, true);
Erlik
  • 658
  • 8
  • 24