swisnl / jQuery-contextMenu

jQuery contextMenu plugin & polyfill
https://swisnl.github.io/jQuery-contextMenu/
MIT License
2.25k stars 746 forks source link

Conditional Submenu #569

Closed mtwallet closed 7 years ago

mtwallet commented 7 years ago

Hi All,

I am using the context menu for as a means to switch layout on a page. I want the menu to only show options that are relevant to the number of items that are on the page because of the sheer number of options that will be available to the user. For example if there are 3 items on a page I only want to display the layouts available that are combinations of 3 (vertical, horizontal, diagonal, hero etc). Please see attached image.

screen shot 2017-09-26 at 10 51 59

Is there a way to render out conditional submenus or hide submenus based on the returned item length when the user right clicks on the page?

I hope that makes sense and many thanks in advance.

bbrala commented 7 years ago

There are multiple ways to do this. One wat is a callback for visibility another is to build the submenu items dynamicly on open.

You can also maybe use the update command to refresh visibility if you just want to use the visibility callback.

Demos: https://swisnl.github.io/jQuery-contextMenu/demo/dynamic-create.html