jQuery-contextMenu
jQuery-contextMenu copied to clipboard
suggestion: accept jquery selector as selector
this is just a suggestion. i tried this at first, and it failed with some strange error message.
$.contextMenu({
selector: myJquerySelectorInsteadOfAString
});
The error is TypeError: o.selector.match is not a function
and it should be something like TypeError: selector is not a string
. I'll look into it, thank you.
In some cases it is impossible (I think) to just require a string selector. For instance, if I have a page that contains iframes that load content, e.g. charts. I can find the chart myself:
myFrame.contents().find('.chart')
But this is not a string I can assign to "selector".
so what you actually need is a way to bind to the iframe's document, right?
That's right. Is there a way? That would be great.
well, not right now. As of today you'd have to load the contextMenu within the iframe to be able to use it properly.
OK, thanks. The iframe contents is generated by an external system. I have no control over it.
Hopefully discussing this example scenario some day helps make your contextMenu even better.
In theory you'd only need to replace all document
and window
references within the plugin by something defined in opt
(registration options object). That would allow you to do register a contextMenu like this
$.contextMenu({
selector: '.with-context-menu',
window: yourIframe.contentWindow,
items: { /* ... */ }
});
feel free to hack at it :)
I need this feature too. Currently mainly for adding a menu to an iframe, but it would make also other use cases easier.
I also need this feature, but for a different reason. I'm using Backbone and I want the selector to be just one element (the view), not all elements, and this element doesn't have a unique id. What I need is one of the following:
this.$el.contextMenu({ //no selector required, as "this.$el" is a jquery selector });
$.contextMenu({ selector: this.$el, //this.$el is a jquery selector for a });
I cannot do the following because '.some-class' is the same element as this.$el this.$el.contextMenu({ selector: '.some-class' });
Any news on that? I would also like the abbility to use element as @ataft suggested.
+1 I need this feature too.
+1 this feature. This is already bound under jQuery. Why are you required a redefinition for a selector?
For example, if I want to bind a context menu to all cells in a table, EXCEPT the first two columns, I need to use the following selector. Ideally, we could just call .contextMenu
after we do our selector.
$('table[name=whatever] tr').find('td:gt(1)').contextMenu({
...
})
I'll have a go on this when i'm ready to work on a new feature. I'll put this high on the list of requests.
We need it...