-
Notifications
You must be signed in to change notification settings - Fork 5.3k
jQuery UI Widget Namespace Extensions #23
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
Conversation
Example: cb_widget(); to access the widget defined by $.widget(cb.widget, {});
Example: $(".tab").custom().tab(); will use the widget defined by $.widget("custom.tab", {});
There seem to be two things here. One is the ability to include multiple widgets with the same name. This seems extremely uncommon, and can already be done in a noConflict type rewrite, e.g., The second is an attempt to actually add namespaces to jQuery which isn't something we want to do in the widget factory. |
Then why is there a namespace concept at all? Why do you define $.widget("ui.draggable"), and have the widget code parse out the namespace, and place the code in a different spot based on that namespace? I figure half implemented code is not optimal, so I finished out the namespace support. What is the motivation for the existing code that handles namespaces in widgets? |
The namespaces are mostly for code organization and to provide an object for collecting utility methods in packages/libraries/whatever. jQuery doesn't support namespaces for methods and there's no clean way to implement them. Exposing namespaces breaks a key pattern that jQuery is built on. |
Sure, I can buy that fine (it does break chaining to some extent), it just bothers me that I had to write this in a blog post describing jQuery-ui widgets used for custom purposes.
It's not technically true, you're not required to use 'ui'. But it doesn't matter, it's still not a namespace. And if you don't define a namespace string, the widget doesn't work. Perhaps instead of having the mostly-useless to the outside world namespace string, we could add a check to the beginning of $.widget() that provides a default namespace name ( This is the code that always assumes a namespace is in the string:
|
It definitely is a namespace. The fact that we don't use two namespaces ( |
Thank you for the discussion here. I will be writing a followup blog post discussing the namespaces as implemented. I'll link it here when I'm done so you can review for accuracy if you'd like. To sum up, it is:
It does still rub me the wrong way to have namespaces that don't allow much separation after the definition (the widgets with the same name situation), but I understand that the complexity added to handle that would far outshadow the ease of the user just not doing that in the first place. |
Thanks for taking the time to write a follow up post, what you've listed out is correct. |
I have two commits here. The first enables an underscore version of widget namespaces.
It also enables $("#tab1").data("cb.tab") to get at the attached instance (in addition to the older key of just "tab"
The second commit builds on the first to enable a different syntax for reaching into the namespace, since I don't particularly like the underscore approach.
Both of the approaches are backwards compatible, and maintain the bare widget name approach that uses the most recently defined widget.
Ping me on #freenode (cschneid), here, or my email (chris.schneider@citrusbyte.com) to discuss any revisions. I expect to revise these commits to use only one of the two methods, and flesh out tests a bit further based on your feedback.
Thank you,
Chris