aratcliffe/Leaflet.contextmenu

command to enable/disable the entire context menu

Closed this issue · 3 comments

Hi - lovely plugin. I'd like to be able to disable an entire context menu at will - i.e. I'd like a map with a custom context-menu, but then to have a javascript call that will disable the entire context menu and allow fallthrough to the browser's standard contextmenu. Is this possible? I don't see an obvious call there in the source code. Maybe there's a way to do it.

(The reason is that I'd like to add a keyboard shortcut to allow users to fallthrough to the default contextmenu when they want to. On firefox holding shift does this, but not other browsers.)

You could listen for the keydown event of your shortcut to remove the context menu and recreate on keyup?

Aha one thing I've found: map.contextmenu.enable() and map.contextmenu.disable(). I found these just by hacking around - they're not in your source-code so they must be a leaflet thing. Seems to work! Thanks for the response though

Hi Dan that's a good solution. The contextmenu is implemented as a map interaction handler so it inherits the enable() and disable() methods from L.Handler. These methods call Map.ContextMenu.addHooks() and Map.ContextMenu.removeHooks() respectively.