medialize/jQuery-contextMenu — Issue #15: Support for dynamic items
Author: endzeit
Created: 2011-12-13 01:02:27+00:00
State: open

Hi,

This is a feature request rather than an issue ticket.
I would love to have the possibility to dynamically add items to a contextmenu at runtime.

The scenario: A contextmenu gets triggered and the menu items are created depending on info from the trigger element.
Like 'Add to' > [bunch of dynamic elements]

I tried to alter the `opt.commands` and `opt.items` objects in the show event of the contextmenu but with no effect.

One way to achieve this would be a `beforeRender` event where it's possible to replace the items created at registration with new ones.
Another way (seen at jjmenu plugin) is instead of a hardcoded item object literal one can use a function which provides context (of the trigger element) and returns a dynamically created item.

As a workaround (haven't tested this yet) it should be possible to register a click event with jQuery which then (functions as wrapper and) creates a $.contextMenu with items in the context of the click event.
But this could get messy really quick with a lot of different trigger events.

I don't know if this functionality is within the designated scope of jQuery-contextMenu,
but it would greatly enhance the overall very good experience with this plugin. :)

Thanks.