jQuery-contextMenu icon indicating copy to clipboard operation
jQuery-contextMenu copied to clipboard

suggestion: accept jquery selector as selector

Open fabiankessler opened this issue 11 years ago • 14 comments

this is just a suggestion. i tried this at first, and it failed with some strange error message.

    $.contextMenu({
        selector: myJquerySelectorInsteadOfAString
    });

fabiankessler avatar Apr 22 '13 00:04 fabiankessler

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.

rodneyrehm avatar Apr 22 '13 07:04 rodneyrehm

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".

mschluper avatar Jul 03 '13 00:07 mschluper

so what you actually need is a way to bind to the iframe's document, right?

rodneyrehm avatar Jul 03 '13 06:07 rodneyrehm

That's right. Is there a way? That would be great.

mschluper avatar Jul 03 '13 14:07 mschluper

well, not right now. As of today you'd have to load the contextMenu within the iframe to be able to use it properly.

rodneyrehm avatar Jul 03 '13 14:07 rodneyrehm

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.

mschluper avatar Jul 03 '13 14:07 mschluper

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 :)

rodneyrehm avatar Jul 03 '13 14:07 rodneyrehm

I need this feature too. Currently mainly for adding a menu to an iframe, but it would make also other use cases easier.

acromarco avatar Mar 04 '14 14:03 acromarco

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' });

ataft avatar Jun 30 '16 21:06 ataft

Any news on that? I would also like the abbility to use element as @ataft suggested.

psolom avatar Sep 19 '16 19:09 psolom

+1 I need this feature too.

hisune avatar Nov 25 '16 10:11 hisune

+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({
  ...
})

geudrik avatar Dec 15 '16 18:12 geudrik

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.

bbrala avatar Dec 15 '16 19:12 bbrala

We need it...

ndvbd avatar May 05 '18 19:05 ndvbd