Skip to content

Commit 68854c1

Browse files
teo1978tjvantoll
authored andcommitted
jQuery UI: Fix plugin instance retrieval code
The part about retrieving the plugin instance from the dom element using .data() was vague about the key used: it said "the plugin name" without mentioning that the full name is needed, including the namespace and a hyphen as a separator. The code example was plain wrong, using only the bare plugin name, which would not work. Fixes jquery#515 Closes jquery#516
1 parent 94d96e8 commit 68854c1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

page/plugins/stateful-plugins-with-widget-factory.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ bar.progressbar( "option", "value", 100 );
229229

230230
### The Widget Factory: Under the Hood
231231

232-
When you call `jQuery.widget`, it creates a constructor function for your plugin and sets the object literal that you pass in as the prototype for your plugin instances. All of the functionality that automatically gets added to your plugin comes from a base widget prototype, which is defined as `jQuery.Widget.prototype`. When a plugin instance is created, it is stored on the original DOM element using `jQuery.data`, with the plugin name as the key.
232+
When you call `jQuery.widget`, it creates a constructor function for your plugin and sets the object literal that you pass in as the prototype for your plugin instances. All of the functionality that automatically gets added to your plugin comes from a base widget prototype, which is defined as `jQuery.Widget.prototype`. When a plugin instance is created, it is stored on the original DOM element using `jQuery.data`, with the plugin's full name (the plugin's namespace, plus a hyphen, plus the plugin's name) as the key. For example the jQuery UI dialog widget uses a key of `"ui-dialog"`.
233233

234234
Because the plugin instance is directly linked to the DOM element, you can access the plugin instance directly instead of going through the exposed plugin method if you want. This will allow you to call methods directly on the plugin instance instead of passing method names as strings and will also give you direct access to the plugin's properties.
235235

236236
```
237237
var bar = $( "<div />")
238238
.appendTo( "body" )
239239
.progressbar()
240-
.data( "progressbar" );
240+
.data( "nmk-progressbar" );
241241
242242
// Call a method directly on the plugin instance.
243243
bar.option( "value", 50 );

0 commit comments

Comments
 (0)