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
{{ message }}
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.
Thanks for sharing this code, its exactly what I was looking for. I have it setup to display the context menu when items within a <ul> are clicked. However the click event target only allows me to access the menu dom element and not the underlying <li> that was clicked when the menu was spawned.
Do you have any recommendations for passing through the target that originally triggered the menu to display? That way I could pick an ID out of the html tag and know what item the user wants to perform operations on.
The text was updated successfully, but these errors were encountered:
You could use your on contextmenu event to show the menu, instead of the contextmenu.attach function:
var target = null;
$("ul li").bind("contextmenu", function (e) {
target = e.target;
contextmenu.show(menu, e.target);
}
Then use the target variable in your menu events.
I haven't tested the above code, and I'm not sure if jquery supports the conextmenu event, but hopefully you can get it to work.
I should add this functionally to the .attach and .show method, perhaps setting contextmenu.target, but I would also like a way to maintain compatibility with the browser-native HTML contextmenu API, but I don't know how you could retrieve the underlying target with that. Do you know how?
Thank you for the suggestion. I ended up getting it to work using your recommendation. jQuery does have an event for "contextmenu" or at least it does in Chrome Canary and Safari 6, hopefully it works in other browsers too. LIke you suggested I basically stash the original event object in a place that the context menu event listeners can access.
Tinkering with the code it still isn't clear to me how you would add support for this in show or attach. I'm only seeing the original element in oncontextmenu and contextMenufor. Before I posted this I was trying to figure out how to stash the event object in one of those methods and pass it along when a menu item is clicked but I couldn't seem to make that happen.
I created a JSFiddle and a post on StackOverflow to see if anyone has ideas about getting the event to be passed through for the native html5 contextmenu but the best answer so far is the same approach you suggested.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Thanks for sharing this code, its exactly what I was looking for. I have it setup to display the context menu when items within a
<ul>
are clicked. However the click event target only allows me to access the menu dom element and not the underlying<li>
that was clicked when the menu was spawned.Do you have any recommendations for passing through the target that originally triggered the menu to display? That way I could pick an ID out of the html tag and know what item the user wants to perform operations on.
The text was updated successfully, but these errors were encountered: