Skip to content

Documenting 1.11's instance method for all widgets. #114

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

Closed
wants to merge 4 commits into from

Conversation

tjvantoll
Copy link
Member

No description provided.

<?xml version="1.0"?>
<method name="instance">
<desc>
Retrieves the <placeholder name="name"/>'s instance object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should mention that it also works when the widget isn't initialized, unlike all other methods. It'll return undefined though (right?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. And actually that's a much better way to detect whether an element is a widget than going through :data. I'll update this tonight.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure everyone understands: .foo( "instance" ) can't be used if the foo plugin hasn't been loaded, but :data(ns-foo) will always work. .foo( "instance" ) is preferred if you know the plugin exists.

@tjvantoll
Copy link
Member Author

Updated.

I think this now sufficiently covers #77 as well. @scottgonzalez @jzaefferer Let me know if this addresses your comments.

@jzaefferer
Copy link
Member

This addresses my comment, but not the one from Scott, since there's no mention of the method being unvailable if the plugin isn't loaded.

@tjvantoll
Copy link
Member Author

Well, it is on the instance method docs for each widget, Unlike other widget methods, instance is safe to call on any element after the plugin has loaded. (https://github.com/jquery/api.jqueryui.com/pull/114/files#L16R4).

But it does look like the instance section on jQuery.widget doesn't mention that.

@jzaefferer
Copy link
Member

Okay, I see. I missed that even when specifically looking for it. Let's make that more explicit? For example, put that part on its own line. The instance method description doesn't have to be a single line.

@@ -87,13 +87,19 @@

<h3>Instance</h3>

<p>The widget's instance is stored using <a href="http://api.jquery.com/jQuery.data/"><code>jQuery.data()</code></a> with the widget's full name as the key. Therefore, you can use the following to retrieve the progressbar widget's instance object from the element.</p>
<p>The widget's instance can be retrieved from a given element using the <a href="#method-instance"><code>instance</code> method</a>.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<a href="#method-instance"><code>instance()</code></a> method for consistency with other links.

Though I think we should do a pass to include the word option/method/event in the link.

@tjvantoll
Copy link
Member Author

@scottgonzalez @jzaefferer Updates made per your comments.

@jzaefferer
Copy link
Member

Alright, looks good to me.

$( "#not-a-progressbar" ).progressbar( "instance" ); // undefined
</code></pre>

<p>The instance is stored using <a href="http://api.jquery.com/jQuery.data/"><code>jQuery.data()</code></a> with the widget's full name as the key. Therefore, the <a href="/data-selector"><code>:data</code></a> selector can also determine whether an element has a given widget bound to it.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/data-selector/ (trailing slash)

@scottgonzalez
Copy link
Member

Just one minor change to make. This look good to land.

@tjvantoll
Copy link
Member Author

Landed in 06d80fe & cde5d57.

@tjvantoll tjvantoll closed this Mar 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants