/
jQuery.widget.xml
283 lines (259 loc) · 13.9 KB
/
jQuery.widget.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?xml version="1.0"?>
<entries>
<entry type="method" name="jQuery.widget">
<title>Widget Factory</title>
<signature>
<argument name="name" type="String">
<desc>The name of the widget to create, including the namespace.</desc>
</argument>
<argument name="base" type="Function" optional="true">
<desc>The base widget to inherit from. This must be a constructor that can be instantiated with the `new` keyword. Defaults to <code>jQuery.Widget</code>.</desc>
</argument>
<argument name="prototype" type="PlainObject">
<desc>The object to use as a prototype for the widget.</desc>
</argument>
</signature>
<desc>Create stateful jQuery plugins using the same abstraction as all jQuery UI widgets.</desc>
<longdesc>
<p>You can create new widgets from scratch, using just the <code>$.Widget</code> object as a base to inherit from, or you can explicitly inherit from existing jQuery UI or third-party widgets. Defining a widget with the same name as you inherit from even allows you to extend widgets in place.</p>
<p>jQuery UI contains many widgets that maintain state and therefore have a slightly different usage pattern than typical jQuery plugins. All of jQuery UI's widgets use the same patterns, which is defined by the widget factory. So if you learn how to use one widget, then you'll know how to use all of them.</p>
<p><em>Note: This documentation shows examples using the <a href="/progressbar">progressbar widget</a> but the syntax is the same for every widget.</em></p>
<h3>Initialization</h3>
<p>In order to track the state of the widget, we must introduce a full life cycle for the widget. The life cycle starts when the widget is initalized. To initialize a widget, we simply call the plugin on one or more elements.</p>
<pre><code>
$( "#elem" ).progressbar();
</code></pre>
<p>This will initialize each element in the jQuery object, in this case the element with an id of <code>"elem"</code>. Because we called the <code>progressbar()</code> method with no parameters, the widget is initialized with its default options. We can pass a set of options during initialization in order to override the default options.</p>
<pre><code>
$( "#elem" ).progressbar({ value: 20 });
</code></pre>
<p>We can pass as many or as few options as we want during initialization. Any options that we don't pass will just use their default values.</p>
<p>The options are part of the widget's state, so we can set options after initialization as well. We'll see this later with the option method.</p>
<h3>Methods</h3>
<p>Now that the widget is initialized, we can query its state or perform actions on the widget. All actions after initialization take the form of a method call. To call a method on a widget, we pass the name of the method to the jQuery plugin. For example, to call the <code>value()</code> method on our progressbar widget, we would use:</p>
<pre><code>
$( "#elem" ).progressbar( "value" );
</code></pre>
<p>If the method accepts parameters, we can pass them after the method name. For example, to pass the parameter <code>40</code> to the <code>value()</code> method, we can use:</p>
<pre><code>
$( "#elem" ).progressbar( "value", 40 );
</code></pre>
<p>Just like other methods in jQuery, most widget methods return the jQuery object for chaining.</p>
<pre><code>
$( "#elem" )
.progressbar( "value", 90 )
.addClass( "almost-done" );
</code></pre>
<p>Each widget will have its own set of methods based on the functionality that the widget provides. However, there are a few methods that exist on all widgets, which are documented below.</p>
<h3>Events</h3>
<p>All widgets have events associated with their various behaviors to notify you when the state is changing. For most widgets, when the events are triggered, the names are prefixed with the widget name. For example, we can bind to progressbar's <code>change</code> event which is triggered whenever the value changes.</p>
<pre><code>
$( "#elem" ).bind( "progressbarchange", function() {
alert( "The value has changed!" );
});
</code></pre>
<p>Each event has a corresponding callback, which is exposed as an option. We can hook into progressbar's <code>change</code> callback instead of binding to the <code>progressbarchange</code> event, if we want to.</p>
<pre><code>
$( "#elem" ).progressbar({
change: function() {
alert( "The value has changed!" );
}
});
</code></pre>
<p>All widgets have a <code>create</code> event which is triggered upon instantiation.</p>
</longdesc>
<category slug="utilities"/>
</entry>
<entry type="widget" name="jQuery.Widget" widget-name="widget" animated-element="element"
widget-element="original element or other relevant generated element">
<title>Base Widget</title>
<desc>The base widget used by the widget factory.</desc>
<options>
<xi:include href="../includes/widget-option-disabled.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-option-hide.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-option-show.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
</options>
<methods suppress-examples="true">
<xi:include href="../includes/widget-method-destroy.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-method-disable.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-method-enable.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-method-option.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<xi:include href="../includes/widget-method-widget.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
<method name="_create">
<desc>
The <code>_create()</code> method is the widget's constructor.
There are no parameters, but <code>this.element</code> and <code>this.options</code> are already set.
</desc>
</method>
<method name="_destroy">
<desc>
The public <a href="#method-destroy"><code>destroy()</code></a> method cleans up all common data, events, etc. and then delegates out to <code>_destroy()</code> for custom, widget-specific, cleanup.
</desc>
</method>
<method name="_getCreateEventData" return="Object">
<desc>
All widgets trigger the <a href="#event-create"><code>create</code></a> event. By default, no data is provided in the event, but this method can return an object which will be passed as the <code>create</code> event's data.
</desc>
</method>
<method name="_getCreateOptions" return="Object">
<desc>
This method allows the widget to define a custom method for defining options during instantiation. This user-provided options override the options returned by this method which override the default options.
</desc>
</method>
<method name="_init">
<desc>
Widgets have the concept of initialization that is distinct from creation. Any time the plugin is called with no arguments or with only an option hash, the widget is initialized; this includes when the widget is created.
<p><em>Note: Initialization should only be handled if there is a logical action to perform on successive calls to the widget with no arguments.</em></p>
</desc>
</method>
<method name="_setOptions">
<desc>
Called whenever the <a href="#method-option"><code>option()</code></a> method is called, regardless of the form in which the <code>option()</code> method was called.
<p>Overriding this is useful if you can defer processor-intensive changes for multiple option changes.</p>
</desc>
<argument name="options" type="Object">
<desc>A map of option-value pairs to set.</desc>
</argument>
</method>
<method name="_setOption">
<desc>
Called from the <a href="#method-_setOptions"><code>_setOptions()</code></a> method for each individual option. Widget state should be updated based on changes.
</desc>
<argument name="key" type="String">
<desc>The name of the option to set.</desc>
</argument>
<argument name="value" type="Object">
<desc>A value to set for the option.</desc>
</argument>
</method>
<method name="_on">
<desc>
Binds event handlers to the specified element(s). Delegation is supported via selectors inside the event names, e.g., "<code>click .foo</code>". The <code>_on()</code> method provides several benefits of direct event binding:
<ul>
<li>Maintains proper <code>this</code> context inside the handlers.</li>
<li>Automatically handles disabled widgets: If the widget is disabled or the event occurs on an element with the <code>ui-state-disabled</code> class, the event handler is not invoked.</li>
<li>Event handlers are automatically namespaced and cleaned up on destroy.</li>
</ul>
</desc>
<argument name="element" type="jQuery" optional="true">
<desc>Which element(s) to bind the event handlers to. If no element is provided, <code>this.element</code> is used.</desc>
</argument>
<argument name="handlers" type="Object">
<desc>
A map in which the string keys represent the event type and optional selector for delegation, and the values represent a handler function to be called for the event.
</desc>
</argument>
</method>
<method name="_off">
<desc>
Unbinds event handlers from the specified element(s).
</desc>
<argument name="element" type="jQuery">
<desc>
The element(s) to unbind the event handlers from. Unlike the <code>_on()</code> method, the elements are required for <code>_off()</code>.
</desc>
</argument>
<argument name="eventName" type="String">
<desc>One or more space-separated event types.</desc>
</argument>
</method>
<method name="_super">
<desc>
Invokes the method of the same name from the parent widget, with any specified arguments. Essentially <code>.call()</code>.
</desc>
</method>
<method name="_superApply">
<desc>
Invokes the method of the same name from the parent widget, with the array of arguments. Essentially <code>.apply()</code>.
</desc>
<argument name="arguments" type="Array">
<desc>Array of arguments to pass to the parent method.</desc>
</argument>
</method>
<method name="_delay" return="Number">
<desc>
Invokes the provided function after a specified delay. Keeps <code>this</code> context correct. Essentially <code>setTimeout()</code>.
<p>Returns the timeout ID for use with <code>clearTimeout()</code>.</p>
</desc>
<argument name="fn">
<desc>The function to invoke. Can also be the name of a method on the widget.</desc>
<type name="Function"/>
<type name="String"/>
</argument>
<argument name="delay" type="Number" optional="true">
<desc>The number of milliseconds to wait before invoking the function. Deafults to <code>0</code>.</desc>
</argument>
</method>
<method name="_hoverable">
<desc>
Sets up <code>element</code> to apply the <code>ui-state-hover</code> class on hover.
<p>The event handlers are automatically cleaned up on destroy.</p>
</desc>
<argument name="element" type="jQuery">
<desc>The element(s) to apply the hoverable behavior to.</desc>
</argument>
</method>
<method name="_focusable">
<desc>
Sets up <code>element</code> to apply the <code>ui-state-focus</code> class on focus.
<p>The event handlers are automatically cleaned up on destroy.</p>
</desc>
<argument name="element" type="jQuery">
<desc>The element(s) to apply the focusable behavior to.</desc>
</argument>
</method>
<method name="_trigger">
<desc>
Triggers an event and its associated callback.
<p>The option with the name equal to type is invoked as the callback.</p>
<p>The event name is the widget name + type.</p>
<p><em>Note: When providing data, you must provide all three parameters. If there is no event to pass along, just pass <code>null</code>.</em></p>
</desc>
<argument name="type" type="String">
<desc>The <code>type</code> should match the name of a callback option. The full event type will be generated automatically.</desc>
</argument>
<argument name="event" type="Event" optional="true">
<desc>The original event that caused this event to occur; useful for providing context to the listener.</desc>
</argument>
<argument name="data" type="Object" optional="true">
<desc>A hash of data associated with the event.</desc>
</argument>
</method>
<method name="_show">
<desc>
Shows an element immediately, using built-in animation methods, or using custom effects.
See the <a href="#option-show">show</a> option for possible <code>option</code> values.
</desc>
<argument name="element" type="jQuery">
<desc>The element(s) to show.</desc>
</argument>
<argument name="option" type="Object">
<desc>The settings defining how to show the element.</desc>
</argument>
<argument name="callback" type="Function" optional="true">
<desc>Callback to invoke after the element has been fully shown.</desc>
</argument>
</method>
<method name="_hide">
<desc>
Hides an element immediately, using built-in animation methods, or using custom effects.
See the <a href="#option-hide">hide</a> option for possible <code>option</code> values.
</desc>
<argument name="element" type="jQuery">
<desc>The element(s) to hide.</desc>
</argument>
<argument name="option" type="Object">
<desc>The settings defining how to hide the element.</desc>
</argument>
<argument name="callback" type="Function" optional="true">
<desc>Callback to invoke after the element has been fully hidden.</desc>
</argument>
</method>
</methods>
<events>
<xi:include href="../includes/widget-event-create.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
</events>
<category slug="utilities"/>
<category slug="widgets"/>
</entry>
</entries>