Collapsibleset Widgetversion added: 1.0
Description: Creates a set of collapsible blocks of content
Sets of collapsibles
jQuery Mobile will visually style a set of collapsibles as a group and will make the set behave like an accordion in that only one collapsible can be open at a time if you wrap the collapsibles in a div
that has the attribute data-role="collapsibleset"
.
By default, all the collapsible sections will be collapsed. To set a section to be open when the page loads, add the data-collapsed="false"
attribute to the heading of the section you want expanded.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
|
Here is an example of a collapsibleset widget with 5 sections.
Non-inset collapsibleset widgets
For full width collapsibles without corner styling add the data-inset="false"
attribute to the set.
Mini collapsibleset widgets
For a more compact version that is useful in tight spaces, add the data-mini="true"
attribute to the set to create a mini version.
Custom icons
The icon displayed when a collapsible is shown or hidden can be overridden by using the data-collapsed-icon
and data-expanded-icon
attributes. Both the collapsibleset
widget and the collapsible
widget accepts these attributes. When you set one or both of these attributes on the collapsibleset
widget all collapsible
widgets that are part of the collapsibleset
display the icon specified by the chosen value. You can override the icon displayed by individual collapsible
widgets by setting one or both of these attributes on the collapsible
widget itself.
Icon positioning
The default icon positioning for collapsible headings can be overridden by using the data-iconpos
attribute. You can set the attribute either on the collapsibleset
to affect all collapsibles in the set, or on an individual collapsible
widget to affect only the one widget.
Theming collapsible content
The standard data-theme
attribute can be used to set the color of each collapsible in a set. To provide a clearer visual grouping of the content with the headers, add the data-content-theme
attribute with a swatch letter. This adds a themed background color and border to the content block. For consistent theming, add these attributes to the parent collapsibleset widget.
1
|
|
Theming individual sections
To have individual sections in a group styled differently, add data-theme
and data-content-theme
attributes to specific collapsibles.
Providing pre-rendered markup
You can improve the load time of your page by providing the markup that the collapsibleset widget would normally create during its initialization.
By providing this markup yourself, and by indicating that you have done so by setting the attribute data-enhanced="true"
, you instruct the collapsibleset widget to skip these DOM manipulations during instantiation and to assume that the required DOM structure is already present.
When you provide such pre-rendered markup you must also set all the classes that the framework would normally set, and you must also set all data attributes whose values differ from the default to indicate that the pre-rendered markup reflects the non-default value of the corresponding widget option.
The collapsibleset widget does not require that the collapsibles it contains also be pre-rendered.
In the example below, pre-rendered markup for a collapsibleset is provided. The attribute data-corners="false"
is explicitly specified, since the absence of the ui-corner-all
class on the container element indicates that the "corners" widget option is to be false. One of the child collapsibles is provided as-is, while the other is pre-rendered.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
|
Options
collapsedIcon
"plus"
This option is also exposed as a data attribute: data-collapsed-icon="arrow-r"
.
Initialize the collapsibleset with the collapsedIcon
option specified:
1
2
3
|
|
Get or set the collapsedIcon
option, after initialization:
1
2
3
4
5
|
|
corners
true
This option is also exposed as a data attribute:data-corners="false"
.
Initialize the collapsibleset with the corners
option specified:
1
2
3
|
|
Get or set the corners
option, after initialization:
1
2
3
4
5
|
|
defaults
false
true
indicates that other widgets options have default values and causes jQuery Mobile's widget autoenhancement code to omit the step where it retrieves option values from data attributes. This can improve startup time.
This option is also exposed as a data attribute: data-defaults="true"
.
Initialize the collapsibleset with the defaults
option specified:
1
2
3
|
|
Get or set the defaults
option, after initialization:
1
2
3
4
5
|
|
disabled
false
true
.
This option is also exposed as a data attribute: data-disabled="true"
.
Initialize the collapsibleset with the disabled
option specified:
1
2
3
|
|
Get or set the disabled
option, after initialization:
1
2
3
4
5
|
|
enhanced
false
This option is also exposed as a data attribute: data-enhanced="true"
.
Initialize the collapsibleset with the enhanced
option specified:
1
2
3
|
|
Get or set the enhanced
option, after initialization:
1
2
3
4
5
|
|
expandedIcon
"minus"
This option is also exposed as a data attribute: data-expanded-icon="arrow-d"
.
Initialize the collapsibleset with the expandedIcon
option specified:
1
2
3
|
|
Get or set the expandedIcon
option, after initialization:
1
2
3
4
5
|
|
iconpos
"left"
Possible values: left, right, top, bottom, none, notext.
This option is also exposed as a data attribute: data-iconpos="right"
.
Initialize the collapsibleset with the iconpos
option specified:
1
2
3
|
|
Get or set the iconpos
option, after initialization:
1
2
3
4
5
|
|
initSelector
null
The default initSelector
for the collapsibleset widget is:
1
|
|
This option is deprecated in 1.4.0 and will be removed in 1.5.0.
The old value of the collapsibleset widget's initSelector
option (":jqmData(role='collapsible-set')"
) is deprecated. As of jQuery Mobile 1.5.0, only widgets that have the attribute data-role="collapsibleset"
will be enhanced as collapsibleset widgets.
As of jQuery Mobile 1.4.0, the initSelector
is no longer a widget option. Instead, it is declared directly on the widget prototype. Thus, you may specify a custom value by handling the mobileinit
event and overwriting the initSelector
on the prototype:
1
2
3
|
|
Note: Remember to attach the mobileinit
handler after you have loaded jQuery, but before you load jQuery Mobile, because the event is triggered as part of jQuery Mobile's loading process.
The value of this option is a jQuery selector string. The framework selects elements based on the value of this option and instantiates collapsibleset widgets on each of the resulting list of elements.
(version deprecated: 1.4.0)initSelector
See below
The default initSelector
for the collapsibleset widget is:
1
|
|
Note: This option is deprecated in 1.4.0 and will be removed in 1.5.0.
As of jQuery Mobile 1.4.0, the initSelector
is no longer a widget option. Instead, it is declared directly on the widget prototype. Thus, you may specify a custom value by handling the mobileinit
event and overwriting the initSelector
on the prototype:
1
2
3
|
|
Note: Remember to attach the mobileinit
handler after you have loaded jQuery, but before you load jQuery Mobile, because the event is triggered as part of jQuery Mobile's loading process.
The value of this option is a jQuery selector string. The framework selects elements based on the value of this option and instantiates collapsibleset widgets on each of the resulting list of elements.
(version deprecated: 1.4.0)inset
true
This option is also exposed as a data attribute: data-inset="true"
.
Initialize the collapsibleset with the inset
option specified:
1
2
3
|
|
Get or set the inset
option, after initialization:
1
2
3
4
5
|
|
mini
false
This option is also exposed as a data attribute: data-mini="false"
.
Initialize the collapsibleset with the mini
option specified:
1
2
3
|
|
Get or set the mini
option, after initialization:
1
2
3
4
5
|
|
Methods
destroy()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the destroy method:
1
|
|
disable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the disable method:
1
|
|
enable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the enable method:
1
|
|
option( optionName )Returns: Object
optionName
.-
optionNameType: StringThe name of the option to get.
Invoke the method:
1
|
|
option()Returns: PlainObject
- This signature does not accept any arguments.
Invoke the method:
1
|
|
option( optionName, value )Returns: jQuery (plugin only)
optionName
.-
optionNameType: StringThe name of the option to set.
-
valueType: ObjectA value to set for the option.
Invoke the method:
1
|
|
option( options )Returns: jQuery (plugin only)
-
optionsType: ObjectA map of option-value pairs to set.
Invoke the method:
1
|
|
refresh()Returns: jQuery (plugin only)
If you manipulate a collapsibleset widget via JavaScript (e.g. by adding new collapsibles, removing old ones, or showing/hiding existing ones), you must call the refresh method on it to update the visual styling. This method will instantiate collapsibles on child elements which are marked data-role="collapsible"
, so there is no need to manually call .collapsible()
.
- This method does not accept any arguments.
Invoke the refresh method:
1
|
|
Events
create( event, ui )Type: collapsiblesetcreate
Note: The ui
object is empty but included for consistency with other events.
Initialize the collapsibleset with the create callback specified:
1
2
3
|
|
Bind an event listener to the collapsiblesetcreate event:
1
|
|
Example:
A basic example of a collapsibleset widget.
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
|
|