Better way to tell if widget already rendered?

Showing 1-7 of 7 messages
Better way to tell if widget already rendered? Keith 3/1/09 8:02 AM
Seems like this is an easy one, but I'm not having luck.

Currently I do this.

if( ! $("#widget-id").hasClass("ui-dialog-content") ) {

   // setup dialog and do other expensive stuff

}

But of course that depends on the CSS class names used.  Is there a
better way, using only the public API?

Thanks.

Re: [jquery-ui] Better way to tell if widget already rendered? Richard D. Worth 3/2/09 1:15 AM
Using the CSS class names seem fairly reasonable, if imperfact. One could make (in fact I would make) quite a strong argument that they are in fact part of our public API. In this particular use, the example you show (dialog) points out one of few gotchas. The element on which you call .dialog gets a class of ui-dialog-content and gets wrapped by a ui-dialog element. This is a bit of an exception, as the norm is for the class 'ui-{pluginname}' to be added to the same element on which .{pluginname}([options]) is called.

That said, I don't know that there is a way currently to check (via pluginname, reliably) whether a plugin has been initialized on an element. You could enter a feature request ticket for this here:

http://dev.jqueryui.com/newticket (note: requires registration)

- Richard
Re: Better way to tell if widget already rendered? Scott González 3/2/09 5:04 AM
The most reliable and least likely to change would be

$('#widget-id').is(':data(dialog)')

This is interesting in the sense that we haven't promoted this and we
explicitly state that any and all direct use of the plugin instance is
unsupported (may change at any time).  However, since this isn't
actually doing anything with the instance, just checking that it
exists, I think it would be okay.

Perhaps an even better solution would be for us to bring back the
custom selectors that existed in 1.0, so you could just do:

$('#widget').is(':dialog')

Both solutions have potential naming conflicts, so maybe introduce:

$('#widget').is(':ui-dialog')

I'll bring this up on jquery-ui-dev.


On Mar 2, 4:15 am, "Richard D. Worth" <rdwo...@gmail.com> wrote:
> Using the CSS class names seem fairly reasonable, if imperfact. One could
> make (in fact I would make) quite a strong argument that they are in fact
> part of our public API. In this particular use, the example you show
> (dialog) points out one of few gotchas. The element on which you call
> .dialog gets a class of ui-dialog-content and gets wrapped by a ui-dialog
> element. This is a bit of an exception, as the norm is for the class
> 'ui-{pluginname}' to be added to the same element on which
> .{pluginname}([options]) is called.
>
> That said, I don't know that there is a way currently to check (via
> pluginname, reliably) whether a plugin has been initialized on an element.
> You could enter a feature request ticket for this here:
>
> http://dev.jqueryui.com/newticket(note: requires registration)
>
> - Richard
Re: [jquery-ui] Re: Better way to tell if widget already rendered? Richard D. Worth 3/2/09 5:13 AM

On Mon, Mar 2, 2009 at 8:04 AM, Scott González <scott.g...@gmail.com> wrote:

The most reliable and least likely to change would be

$('#widget-id').is(':data(dialog)')

This is interesting in the sense that we haven't promoted this and we
explicitly state that any and all direct use of the plugin instance is
unsupported (may change at any time).  However, since this isn't
actually doing anything with the instance, just checking that it
exists, I think it would be okay.

Yeah, I thought of that, but didn't mention it for just the reason you stated, it's not part of our public API, even if fairly stable.



Perhaps an even better solution would be for us to bring back the
custom selectors that existed in 1.0, so you could just do:

$('#widget').is(':dialog')

Both solutions have potential naming conflicts, so maybe introduce:

$('#widget').is(':ui-dialog')

I'll bring this up on jquery-ui-dev.

Thanks.

- Richard
 



On Mar 2, 4:15 am, "Richard D. Worth" <rdwo...@gmail.com> wrote:
> Using the CSS class names seem fairly reasonable, if imperfact. One could
> make (in fact I would make) quite a strong argument that they are in fact
> part of our public API. In this particular use, the example you show
> (dialog) points out one of few gotchas. The element on which you call
> .dialog gets a class of ui-dialog-content and gets wrapped by a ui-dialog
> element. This is a bit of an exception, as the norm is for the class
> 'ui-{pluginname}' to be added to the same element on which
> .{pluginname}([options]) is called.
>
> That said, I don't know that there is a way currently to check (via
> pluginname, reliably) whether a plugin has been initialized on an element.
> You could enter a feature request ticket for this here:
>
> http://dev.jqueryui.com/newticket(note: requires registration)
>
> - Richard
>
> On Sun, Mar 1, 2009 at 11:02 AM, Keith <keithdwink...@gmail.com> wrote:
>
> > Seems like this is an easy one, but I'm not having luck.
>
> > Currently I do this.
>
> > if( ! $("#widget-id").hasClass("ui-dialog-content") ) {
>
> >   // setup dialog and do other expensive stuff
>
> > }
>
> > But of course that depends on the CSS class names used.  Is there a
> > better way, using only the public API?
>
> > Thanks.


Re: Better way to tell if widget already rendered? Scott González 3/2/09 3:54 PM
On Mar 2, 8:04 am, Scott González <scott.gonza...@gmail.com> wrote:
> I'll bring this up on jquery-ui-dev.

Here's the thread: http://groups.google.com/group/jquery-ui-dev/browse_thread/thread/5842ffd1c6622b46#

Everyone's in agreement to add new selectors with names matching the
plugin, e.g., :ui-draggable and :ui-dialog.  You can track progress
here: http://dev.jqueryui.com/ticket/4266
Re: Better way to tell if widget already rendered? Paradime Web 3/9/09 9:21 AM
$('#widget').is(':ui-accordion')  does not work in 1.7

This returns true before I even render the accordion.

Why?

Thanks,

On Mar 2, 6:54 pm, Scott González <scott.gonza...@gmail.com> wrote:
> On Mar 2, 8:04 am, Scott González <scott.gonza...@gmail.com> wrote:
>
> > I'll bring this up on jquery-ui-dev.
>
> Here's the thread:http://groups.google.com/group/jquery-ui-dev/browse_thread/thread/584...
Re: [jquery-ui] Re: Better way to tell if widget already rendered? Richard D. Worth 3/9/09 10:08 AM
Because that ticket is still open. This feature hasn't been implemented yet.

- Richard