You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a set of run time defined divs that each have the same context menu (interspersed with items having a second menu, and one moving item with a third menu, so putting something on an outer container doesn't seem fruitful). As items come and go, I acquire an ever expanding set of identical hidden menus at the end of the body. I'd rather have just one (of each distinct menu).
Looking at the code, it seems that binding the same mouse event handler to multiple triggering elements would just work. The correct menu is known to the handler through closure, and the handler would still get the correct triggering element as "this".
[I'm working on an approach where the final binding step is abstracted into another function defined within the jQuery.fn.contextMenu call, and is thus closed on the correct event handler, and which takes, as an argument, the jQuery object on which to call .bind() or .on(). An additional option, or additional optional argument, or calling jQuery.fn.contextMenu on an empty jQuery object would cause the binding function to be returned instead of called. So I would call contextMenu with the (currently extra option) and save the returned function, later applying it to the elements that need that menu as they came into existence. Suggestions welcome.
Indeed, this approach seems to work, tested with Chrome.]
The text was updated successfully, but these errors were encountered:
I have a set of run time defined divs that each have the same context menu (interspersed with items having a second menu, and one moving item with a third menu, so putting something on an outer container doesn't seem fruitful). As items come and go, I acquire an ever expanding set of identical hidden menus at the end of the body. I'd rather have just one (of each distinct menu).
Looking at the code, it seems that binding the same mouse event handler to multiple triggering elements would just work. The correct menu is known to the handler through closure, and the handler would still get the correct triggering element as "this".
[I'm working on an approach where the final binding step is abstracted into another function defined within the jQuery.fn.contextMenu call, and is thus closed on the correct event handler, and which takes, as an argument, the jQuery object on which to call .bind() or .on(). An additional option, or additional optional argument, or calling jQuery.fn.contextMenu on an empty jQuery object would cause the binding function to be returned instead of called. So I would call contextMenu with the (currently extra option) and save the returned function, later applying it to the elements that need that menu as they came into existence. Suggestions welcome.
Indeed, this approach seems to work, tested with Chrome.]
The text was updated successfully, but these errors were encountered: