swisnl / jQuery-contextMenu

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

Feature request: being able to manually trigger contextMenu update #555

Closed dwitvliet closed 7 years ago

dwitvliet commented 7 years ago

Hi, There are various triggers for manually manipulating the contextMenu. However, there is currently no easy way to trigger an update of the elements in the contextMenu. It would be great for plugins to be able to update the elements, e.g. with $(".some-selector").contextMenu("update");.

bbrala commented 7 years ago

When using the build option, the menu is built every time you open the menu, wouldn't that fix your problem?

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

dwitvliet commented 7 years ago

Hi, thank you for the quick response! Sorry, I wasn't specific enough in my original post. I am looking for a function that allows updating the contextMenu elements while the contextMenu is visible (so the visible and disabled functions are run again). The build option would require the menu to be hidden and then be rebuilt in order to update the menu.

hybridwebdev commented 7 years ago

First off, thanks for such an amazing plugin. To add to this topic, I believe an update option would be wonderful, as I've noticed that if you do something div class='something' Stuff and thangs. div

And then bind a context menu on the something class, all works well. However, this only occurs if the element is already in the dom. For dynamically created elements, or for elements that may get moved in and out of the dom via ajax calls, the context menu no longer works as the element was in the dom during the initial context menu call.

I've been through the documentation of the plugin, and as far as I can tell no method for this desired behavior works. Perhaps I'm just missing something, but it seems like a way to update element binds is the way to go.

bbrala commented 7 years ago

I've added a feature to support updating the menu. See: http://swisnl.github.io/jQuery-contextMenu/docs.html#update-contextmenu-state