-
Notifications
You must be signed in to change notification settings - Fork 746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage when selector isn't available #88
Comments
This is currently not possible. We would have to "calculate" a selector matching the given element and create the menu for that. I don't like this at all, though. It allows sloppy integration that will ultimately lead to bad things happening. That said, I'm open for discussion… so |
Thanks for the info. It sounds like this simply isn't going to be possible without significant reengineering of the contextMenu. I believe jquery plugins can, do, and should sandbox to a specific dom element, or set of elements. Calling $("#foo").bar() should only modify or change the behavior of #foo, and should not affect other things on the page unexpectedly. If you're curious - let's say, for example, the other plugin is something that makes tables editable (it's not, but hopefully this is a simple example to illustrate the problem)" Unfortunately if it simply passed "td" as the selector, this would be a brazen violation of the user's expectations: i.e. ALL "td" elements on the page would be given a context menu, rather than simply the one on which editable() was called. It might be tempting to suggest it should simply provide "table.editable td" as the selector, but editable() cannot always know what its selector was: e.g. This is one of the primary reasons why the jquery plugin convention is to operate on a jquery object rather than pass it a selector. i.e. |
Actually, this might be a simpler way to illustrate the problem:
|
While I agree with you on this front - it simply isn't the case. In some circumstances it's even impossible (consider breaking out of an
true, which is why I suggested "calulating" a (rather specific) selector for the root-node a menu is to be registered on. But that just feels ugly. Instead I would keep the selector as it is ( nice, now that I've answered your first comment, I see you've had the same idea in the next. There are some limitations, though. One of them being that you can't access menus created for Objections? Thoughts? |
Unfortunately this is a tough situation, and I'm not sure there's a clear or best answer. I'm just going to hold off using this contextmenu in this situation for now. I'll probably revisit this when I have more time to invest in getting familiar with the guts of this plugin. |
I'm interested in what alternative you've settled for. |
Right now I'm using this old one: http://www.trendskitchens.co.nz/jquery/contextmenu/ I was recently evaluating your contextMenu since it makes it easier to visually disable menu items, and because it's more actively developed (and just all-around cleaner and nicer, especially the api). But switching is not a pressing need since what we have works. |
jQuery.ui.widget duck punches jQuery.cleanData() (apparently not publicly documented, function to handle data-cleanups for removed dom nodes). jQueryUI adds the triggering of a custom So in theory this change shouldn't have a very high impact. Duck punch |
I see, you're not interested in supporting Firefox then, right? That demo-page doesn't show a menu on Firefox (but does on Safari, Chrome, Opera) |
I'm glad you point that out - I didn't realize it had problems. I'll have to look into it. Thanks! |
(removed obsolete Firefox 12 hack in the process)
Well… I've implemented it and it seems to work fine. As I only push complete releases to gh-pages on github, I've pushed you the mstratman-preview branch. check it out and tell me if that works for you. (no docs, but there is a demo-page showing it off) The next official release will take a while, so play with the branch for now :) |
That's great! :) Very cool - I'll give it a try very soon and let you know what I find. |
I haven't yet had time to investigate it (so sorry for no patch or test case), but I just wanted to give you a heads-up that it seems to not be backwards compatible. e.g. $.contextMenu({ selector : "li" }); won't cause menus for all "li" elements like it does in the gh-pages branch. I'll try to look at this closer later, and follow up when I can. Thanks again. |
yes, there was a bug I fixed a couple of minutes ago… |
Have you tried it out? does it work as expected? |
Sorry for the long delay. I haven't forgotten about your hard work! I did a quick, cursory trial with some examples and so far it seems great. Unfortunately, I haven't yet tested it in my larger app, since we still haven't been able to upgrade jquery (stuck on 1.6.4 temporarily) - and it seems this plugin uses on() which comes from 1.7. As soon as we get this upgraded I'll give it a try - or maybe sooner if possible. Thanks again. |
I've given it a closer look and everything seems to work great. Thanks again. |
If a selector isn't available, is there any other way to use this plugin?
For example, given:
If anotherPlugin wants to create a context menu, there appears to be no way to limit its effects to only the .thing elements in #container, since anotherPlugin() does not get a selector.
If contextMenu() can't behave like other jquery plugins (i.e. $(selector).contextMenu()), then can its 'selector' attribute also allow objects in addition to string selectors?
e.g. I could, within anotherPlugin, do something like:
Or am I missing an altogether better solution? thanks,
The text was updated successfully, but these errors were encountered: