Skip to main content

Search and Top Navigation

#8283 closed bug (wontfix)

Opened May 01, 2012 04:09AM UTC

Closed May 01, 2012 05:34PM UTC

Last modified May 01, 2012 08:58PM UTC

Widgets should be accessible via ancestor names also

Reported by: fooblah Owned by: fooblah
Priority: minor Milestone: 1.9.0
Component: ui.widget Version: 1.8.19
Keywords: Cc:
Blocked by: Blocking:
Description

Because: otherwise there is no way to get polymorphic behavior which is super nice.

For example:


$.widget('foo.myWidget' {
  doCoolThing: function () {}
})
$.widget('foo.specialWidget' $.foo.myWidget, {
  doOtherCoolThing: function () {}
})

$('.thing:not(.special-thing)').myWidget()
$('.thing.special-thing').specialWidget()

I want to be able to do:

$('.thing').each(function (i,el) {
   $(el).myWidget('doCoolThing');
});

But I can't (can I?). Instead I have to track these special cases everywhere in my code, not just where the differences matter which really sort of break a central feature of the entire notion of inheritance and classes.

I realize I can get direct references to the widgets and put them in an array or something but that that sucks is the entire point of the widget bridge.

Other hacky alternative:

  • make all public widget methods available at $('.foo').winst('someMethod')? And just let multiple widgets attached to same element clobber each other...
Attachments (0)
Change History (6)

Changed May 01, 2012 12:29PM UTC by scottgonzalez comment:1

owner: → fooblah
status: newpending

This is about way more than just what method name you use to access the plugin. For example, all event names change, and we're certainly not going to double up on those. Is there a reason why you can't just extend the widget instead of inheriting?

Changed May 01, 2012 04:33PM UTC by fooblah comment:2

status: pendingnew

About extending, how exactly would that work in the example I provided? Do you mean after instantiating I would then mix-in specialWidget methods into instances that needed them?

Changed May 01, 2012 04:53PM UTC by scottgonzalez comment:3

status: newpending

In 1.8, just modify the prototype, e.g., $.foo.myWidget.newMethod = .... In 1.9, just inherit from yourself, e.g., $.widget( "foo.myWidget", $.foo.myWidget, { ... })

Changed May 01, 2012 05:22PM UTC by fooblah comment:4

status: pendingnew

But then wouldn't all myWidget basically become specialWidgets? The idea is that the behavior of *some* instances is modified. If I do that then they will all act the same right? Or is there some way to do this in a limited context where only some instances will be affected?

Changed May 01, 2012 05:34PM UTC by scottgonzalez comment:5

resolution: → wontfix
status: newclosed

Yes, it would modify all, which is fine based on your example. I'm going to close this ticket. If you'd like to discuss actual uses cases, please start a discussion on the Developing jQuery UI forum.

Changed May 01, 2012 08:58PM UTC by fooblah comment:6


$.widget('foo.myWidget' {
  doCoolThing: function () {}
})
$.widget('foo.specialWidget' $.foo.myWidget, {
  doCoolThing: function () { this._super(); this._extraCoolStuff(); }
})

$('.thing:not(.special-thing)').myWidget()
$('.thing.special-thing').specialWidget()

This won't work and extending myWidget also wont work:

$('.thing').each(function (i,el) {
   $(el).myWidget('doCoolThing');
});