Skip to content

Commit bee5fec

Browse files
committed
All: Document classes option
Fixes #256
1 parent be643e2 commit bee5fec

20 files changed

+371
-19
lines changed

entries/accordion.xml

+21-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@
3939
<li>
4040
<code>ui-accordion</code>: The outer container of the accordion.
4141
<ul>
42-
<li><code>ui-accordion-header</code>: The headers of the accordion. The headers will additionally have a <code>ui-accordion-icons</code> class if they contain <a href="#option-icons"><code>icons</code></a>.</li>
43-
<li><code>ui-accordion-content</code>: The content panels of the accordion.</li>
42+
<li>
43+
<code>ui-accordion-header</code>: The headers of the accordion. The active header will additionally have a <code>ui-accordion-content-active</code> class, the inactive headers will have a <code>ui-accordion-header-collapsed</code> class. The headers will also have a <code>ui-accordion-icons</code> class if they contain <a href="#option-icons"><code>icons</code></a>.
44+
<ul>
45+
<li><code>ui-accordion-header-icon</code>: Icon elements within each accordion header.</li>
46+
</ul>
47+
</li>
48+
<li><code>ui-accordion-content</code>: The content panels of the accordion. The active content panel will additionally have a <code>ui-accordion-content-active</code> class.</li>
4449
</ul>
4550
</li>
4651
</ul>
@@ -86,6 +91,15 @@
8691
</desc>
8792
</type>
8893
</option>
94+
<option name="classes" type="Object">
95+
<default>{
96+
"ui-accordion-header": "ui-corner-top",
97+
"ui-accordion-header-collapsed": "ui-corner-all",
98+
"ui-accordion-content": "ui-corner-bottom"
99+
}</default>
100+
<xi:include href="../includes/classes-option-desc.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
101+
<xi:include href="../includes/classes-option-example.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
102+
</option>
89103
<option name="collapsible" type="Boolean" default="false" example-value="true">
90104
<desc>Whether all the sections can be closed at once. Allows collapsing the active section.</desc>
91105
</option>
@@ -108,7 +122,11 @@
108122
</ul>
109123
</desc>
110124
</option>
111-
<option name="icons" type="Object" default='{ "header": "ui-icon-triangle-1-e", "activeHeader": "ui-icon-triangle-1-s" }' example-value='{ "header": "ui-icon-plus", "activeHeader": "ui-icon-minus" }'>
125+
<option name="icons" type="Object" example-value='{ "header": "ui-icon-plus", "activeHeader": "ui-icon-minus" }'>
126+
<default>{
127+
"header": "ui-icon-triangle-1-e",
128+
"activeHeader": "ui-icon-triangle-1-s"
129+
}</default>
112130
<desc>
113131
<p>Icons to use for headers, matching <a href="/theming/icons/">an icon provided by the jQuery UI CSS Framework</a>. Set to <code>false</code> to have no icons displayed.</p>
114132
<ul>

entries/autocomplete.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<ul>
3434
<li><code>ui-autocomplete</code>: The <a href="/menu/#theming">menu</a> used to display matches to the user.</li>
35-
<li><code>ui-autocomplete-input</code>: The input element that the Autocomplete widget was instantiated with.</li>
35+
<li><code>ui-autocomplete-input</code>: The input element that the autocomplete widget was instantiated with. While requesting data to display to the user, the <code>ui-autocomplete-loading</code> class is also added to this element.</li>
3636
</ul>
3737

3838
<h3>Dependencies</h3>
@@ -55,6 +55,10 @@
5555
<option name="autoFocus" type="Boolean" default="false" example-value="true">
5656
<desc>If set to <code>true</code> the first item will automatically be focused when the menu is shown.</desc>
5757
</option>
58+
<option name="classes" type="Object" default="{}">
59+
<xi:include href="../includes/classes-option-desc.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
60+
<xi:include href="../includes/classes-option-example.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
61+
</option>
5862
<option name="delay" type="Integer" default="300" example-value="500">
5963
<desc>The delay in milliseconds between when a keystroke occurs and when a search is performed. A zero-delay makes sense for local data (more responsive), but can produce a lot of load for remote data, while being less responsive.</desc>
6064
</option>

entries/button.xml

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
<note id="functional-css"/>
4040
<added>1.8</added>
4141
<options>
42+
<option name="classes" type="Object">
43+
<default>{
44+
"ui-button": "ui-corner-all",
45+
}</default>
46+
<xi:include href="../includes/classes-option-desc.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
47+
<xi:include href="../includes/classes-option-example.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
48+
</option>
4249
<xi:include href="../includes/widget-option-disabled.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
4350
<option name="icons" default="{ primary: null, secondary: null }" example-value='{ primary: "ui-icon-gear", secondary: "ui-icon-triangle-1-s" }'>
4451
<desc>

entries/dialog.xml

+9-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
<ul>
5757
<li>
58-
<code>ui-dialog</code>: The outer container of the dialog.
58+
<code>ui-dialog</code>: The outer container of the dialog. If the <a href="#option-draggable"><code>draggable</code> option</a> is set, the <code>ui-dialog-dragging</code> class is added during a drag. If the <a href="#option-resizable"><code>resizable</code> option</a> is set, the <code>ui-dialog-resizing</code> class is added during a resize. If the <a href="#option-buttons"><code>buttons</code> option</a> is set, the <code>ui-dialog-buttons</code> class is added.
5959
<ul>
6060
<li>
6161
<code>ui-dialog-titlebar</code>: The title bar containing the dialog's title and close button.
@@ -125,6 +125,14 @@
125125
<desc>Each element of the array must be an object defining the attributes, properties, and event handlers to set on the button. In addition, a key of <code>icons</code> can be used to control <a href="/button/#option-icons">button's <code>icons</code> option</a>, and a key of <code>showText</code> can be used to control <a href="/button/#option-text">button's <code>text</code> option</a>.</desc>
126126
</type>
127127
</option>
128+
<option name="classes" type="Object">
129+
<default>{
130+
"ui-dialog": "ui-corner-all",
131+
"ui-dialog-titlebar": "ui-corner-all",
132+
}</default>
133+
<xi:include href="../includes/classes-option-desc.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
134+
<xi:include href="../includes/classes-option-example.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
135+
</option>
128136
<option name="closeOnEscape" default="true" example-value="false">
129137
<desc>Specifies whether the dialog should close when it has focus and the user presses the escape (ESC) key.</desc>
130138
<type name="Boolean" />

entries/draggable.xml

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
<longdesc>
66
<p>Make the selected elements draggable by mouse. If you want not just drag, but drag &amp; drop, see the <a href="/droppable/">jQuery UI Droppable plugin</a>, which provides a drop target for draggables.</p>
77

8+
<xi:include href="../includes/widget-theming.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
9+
10+
<ul>
11+
<li><code>ui-draggable</code>: The draggable element. When the draggable is disabled, the <code>ui-draggable-disabled</code> class is added. While dragging, the <code>ui-draggable-dragging</code> class is added.</li>
12+
<li><code>ui-draggable-handle</code>: The handle of the draggable, specified using the <a href="#option-handle"><code>handle</code> option</a>. By default, the draggable element itself is also the handle.</li>
13+
</ul>
14+
815
<h3>Dependencies</h3>
916
<ul>
1017
<li><a href="/category/ui-core/">UI Core</a></li>
@@ -41,6 +48,10 @@
4148
<option name="cancel" type="Selector" default='"input,textarea,button,select,option"' example-value='".title"'>
4249
<desc>Prevents dragging from starting on specified elements.</desc>
4350
</option>
51+
<option name="classes" type="Object" default="{}">
52+
<xi:include href="../includes/classes-option-desc.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
53+
<xi:include href="../includes/classes-option-example.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
54+
</option>
4455
<option name="connectToSortable" type="Selector" default="false" example-value='"#my-sortable"'>
4556
<desc>Allows the draggable to be dropped onto the specified sortables. If this option is used, a draggable can be dropped onto a sortable list and then becomes part of it. Note: The <a href="#option-helper"><code>helper</code></a> option must be set to <code>"clone"</code> in order to work flawlessly. Requires the <a href="/sortable/">jQuery UI Sortable plugin</a> to be included.</desc>
4657
</option>

entries/droppable.xml

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<longdesc>
66
<p>The jQuery UI Droppable plugin makes selected elements droppable (meaning they accept being dropped on by <a href="/draggable/">draggables</a>). You can specify which draggables each will accept.</p>
77

8+
<xi:include href="../includes/widget-theming.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
9+
10+
<ul>
11+
<li><code>ui-droppable</code>: The droppable element. When a draggable that can be dropped on this dropppable is activated, the <code>ui-droppable-active</code> class is added. When dragging a draggable over this droppable, the <code>ui-droppable-hover</code> class is added.</li>
12+
</ul>
13+
814
<h3>Dependencies</h3>
915
<ul>
1016
<li><a href="/category/ui-core/">UI Core</a></li>
@@ -29,6 +35,10 @@
2935
<option name="addClasses" type="Boolean" default="true" example-value="false">
3036
<desc>If set to <code>false</code>, will prevent the <code>ui-droppable</code> class from being added. This may be desired as a performance optimization when calling <code>.droppable()</code> init on hundreds of elements.</desc>
3137
</option>
38+
<option name="classes" type="Object" default="{}">
39+
<xi:include href="../includes/classes-option-desc.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
40+
<xi:include href="../includes/classes-option-example.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
41+
</option>
3242
<xi:include href="../includes/widget-option-disabled.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
3343
<option name="greedy" type="Boolean" default="false" example-value="true">
3444
<desc>By default, when an element is dropped on nested droppables, each droppable will receive the element. However, by setting this option to <code>true</code>, any parent droppables will not receive the element. The <code>drop</code> event will still bubble normally, but the <code>event.target</code> can be checked to see which droppable received the draggable element.</desc>

entries/jQuery.widget.xml

+135
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,38 @@
192192
<xi:include href="../includes/widget-option-disabled.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
193193
<xi:include href="../includes/widget-option-hide.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
194194
<xi:include href="../includes/widget-option-show.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
195+
<option name="classes" default="{}">
196+
<desc>
197+
<p>Additional (thematic) classes to add to the widget, in addition to the structural classes. The structural classes are used as keys of this option and the thematic classes are the values. See the <a href="#method-_addClass"><code>_addClass()</code> method</a> for using this in custom widgets. Check out the documentation of individual widgets to see which classes they support.</p>
198+
<p>The primary motivation of this option is to map structural classes to theme classes. In other words, any class prefixed with namespace and widget, like <code>"ui-progressbar-"</code>, is considered a structural class. These are always added to the widget. In contrast to that, any class not specific to the widget is considered a theme class. These could be part of jQuery UI's CSS framework, but can also come from other CSS frameworks or be defined in custom stylesheets.</p>
199+
<p class="warning">Setting the <code>classes</code> option after creation will override all default properties. To only change specific values, use deep setters, e.g. <code>.option( "classes.ui-progressbar-value", null )</code>.</p>
200+
</desc>
201+
<type name="Object" />
202+
<example>
203+
<desc>Initialize a progressbar widget with the <code>classes</code> option specified, changing the theming for the <code>ui-progressbar</code> class:</desc>
204+
<code>
205+
$( ".selector" ).progressbar({
206+
classes: {
207+
"ui-progressbar": "highlight"
208+
}
209+
});
210+
</code>
211+
</example>
212+
<example>
213+
<desc>Get or set the <code>classes</code> option, after initialization:</desc>
214+
<code>
215+
// Getter
216+
var classes = $( ".selector" ).widget( "option", "classes" );
217+
218+
// Setter, override all classes
219+
$( ".selector" ).widget( "option", "classes", { "custom-header": "icon-warning" } );
220+
221+
// Setter, override just one class
222+
$( ".selector" ).widget( "option", "classes.custom-header", "icon-warning" );
223+
</code>
224+
</example>
225+
</option>
226+
195227
</options>
196228
<methods suppress-auto-examples="true">
197229
<xi:include href="../includes/widget-method-destroy.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
@@ -200,6 +232,109 @@
200232
<xi:include href="../includes/widget-method-instance.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
201233
<xi:include href="../includes/widget-method-option.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
202234
<xi:include href="../includes/widget-method-widget.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
235+
<method name="_addClass">
236+
<desc>
237+
Add classes to an element of the widget.
238+
<p>This provides a hook for the user to add additional classes or replace default styling classes, through the <a href="#option-classes"><code>classes</code> option</a>.</p>
239+
<p>It also provides automatic removal of these classes when a widget is destroyed, as long as you're using <a href="#method-_addClass"><code>_addClass()</code></a>, <a href="#method-_removeClass"><code>_removeClass()</code></a> and <a href="#method-_toggleClass"><code>_toggleClass()</code></a> together. This can heavily simplify the implementation of custom <a href="#method-_destroy"><code>_destroy()</code></a> methods.</p>
240+
</desc>
241+
<argument name="element" type="jQuery" optional="true">
242+
<desc>The element to add the classes to. Defaults to <code>this.element</code>.</desc>
243+
</argument>
244+
<argument name="keys" type="String">
245+
<desc>
246+
The classes to add, as a space-delimited list. If a property of the <a href="#option-classes"><code>classes</code> option</a> matches a key, the value will be added as well.
247+
<p>When you only need the <code>extra</code> argument, you can skip this argument by specifying <code>null</code>.</p>
248+
</desc>
249+
</argument>
250+
<argument name="extra" type="String" optional="true">
251+
<desc>Additional classes to add, required for layout or other reasons. Unlike the <code>keys</code> argument, these aren't associated with any properties of the <a href="#option-classes"><code>classes</code> option</a>. Just like <code>keys</code>, they will also be automatically removed when destroying the widget.</desc>
252+
</argument>
253+
<example>
254+
<desc>Add the <code>ui-progressbar</code> class to the widget's element (<code>this.element</code>). Will also add any additional classes specified through the <a href="#option-classes"><code>classes</code> option</a> for the given class.</desc>
255+
<code><![CDATA[
256+
this._addClass( "ui-progressbar" );
257+
]]></code>
258+
</example>
259+
<example>
260+
<desc>Add the <code>demo-popup-header</code> class to the specified element (here referencing <code>this.popup</code>). Will also add any additional classes specified through the <a href="#option-classes"><code>classes</code> option</a> for the given class. In addition, it will always add the <code>ui-front</code> class.</desc>
261+
<code><![CDATA[
262+
this._addClass( this.popup, "demo-popup-header", "ui-front" );
263+
]]></code>
264+
</example>
265+
<example>
266+
<desc>Adds the <code>ui-helper-hidden-accessible</code> class to the specified element. Uses <code>null</code> for the <code>keys</code> argument to skip it.</desc>
267+
<code><![CDATA[
268+
this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" );
269+
]]></code>
270+
</example>
271+
</method>
272+
<method name="_removeClass">
273+
<desc>
274+
Remove classes from an element of the widget.
275+
<p>The arguments are the same as for the <a href="#method-_addClass"><code>_addClass()</code> method</a>, the same semantics apply, just in reverse.</p>
276+
</desc>
277+
<argument name="element" type="jQuery" optional="true">
278+
<desc>The element to remove the classes from. Defaults to <code>this.element</code>.</desc>
279+
</argument>
280+
<argument name="keys" type="String">
281+
<desc>
282+
The classes to remove, as a space-delimited list. If a property of the <a href="#option-classes"><code>classes</code> option</a> matches a key, the value will be removed as well.
283+
<p>When you only need the <code>extra</code> argument, you can skip this argument by specifying <code>null</code>.</p>
284+
</desc>
285+
</argument>
286+
<argument name="extra" type="String" optional="true">
287+
<desc>Additional classes to remove, required for layout or other reasons. Unlike the <code>keys</code> argument, these aren't associated with any properties of the <a href="#option-classes"><code>classes</code> option</a>.</desc>
288+
</argument>
289+
<example>
290+
<desc>Remove the <code>ui-progressbar</code> class from the widget's element (<code>this.element</code>). Will also remove any additional classes specified through the <a href="#option-classes"><code>classes</code> option</a> for the given class.</desc>
291+
<code><![CDATA[
292+
this._removeClass( "ui-progressbar" );
293+
]]></code>
294+
</example>
295+
<example>
296+
<desc>Remove the <code>demo-popup-header</code> class from the specified element (here referencing <code>this.popup</code>). Will also remove any additional classes specified through the <a href="#option-classes"><code>classes</code> option</a> for the given class. In addition, it will also remove the <code>ui-front</code> class.</desc>
297+
<code><![CDATA[
298+
this._removeClass( this.popup, "demo-popup-header", "ui-front" );
299+
]]></code>
300+
</example>
301+
<example>
302+
<desc>Remove the <code>ui-helper-hidden-accessible</code> class from the specified element. Uses <code>null</code> for the <code>keys</code> argument to skip it.</desc>
303+
<code><![CDATA[
304+
this._removeClass( this.liveRegion, null, "ui-helper-hidden-accessible" );
305+
]]></code>
306+
</example>
307+
</method>
308+
<method name="_toggleClass">
309+
<desc>
310+
Toggle classes of an element of the widget.
311+
<p>The arguments are the same as for the <a href="#method-_addClass"><code>_addClass()</code></a> and <a href="#method-_removeClass"><code>_removeClass()</code></a> methods, except for the additional boolean argument that specifies to add or remove classes.</p>
312+
<p class="warning">Unlike jQuery's <code>.toggleClass()</code> method, the boolean <code>add</code> argument is always required.</p>
313+
</desc>
314+
<argument name="element" type="jQuery" optional="true">
315+
<desc>The element to toogle the classes on. Defaults to <code>this.element</code>.</desc>
316+
</argument>
317+
<argument name="keys" type="String">
318+
<desc>
319+
The classes to toogle, as a space-delimited list. If a property of the <a href="#option-classes"><code>classes</code> option</a> matches a key, the value will be toggled as well.
320+
<p>When you only need the <code>extra</code> argument, you can skip this argument by specifying <code>null</code>.</p>
321+
</desc>
322+
</argument>
323+
<argument name="extra" type="String" optional="true">
324+
<desc>Additional classes to toggle, required for layout or other reasons. Unlike the <code>keys</code> argument, these aren't associated with any properties of the <a href="#option-classes"><code>classes</code> option</a>. Just like <code>keys</code>, they will also be automatically removed when destroying the widget.</desc>
325+
</argument>
326+
<argument name="add" type="Boolean">
327+
<desc>
328+
<p>Indicates whether to add or remove the specified classes, where a boolean <code>true</code> indicates that classes should be added, a boolean <code>false</code> indicates that classes should be removed.</p>
329+
</desc>
330+
</argument>
331+
<example>
332+
<desc>Toggle the <code>ui-state-disabled</code> class on the widget's element (<code>this.element</code>).</desc>
333+
<code><![CDATA[
334+
this._toggleClass( null, "ui-state-disabled", !!value );
335+
]]></code>
336+
</example>
337+
</method>
203338
<method name="_create">
204339
<desc>
205340
The <code>_create()</code> method is the widget's constructor.

0 commit comments

Comments
 (0)