Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit a0e62d7

Browse files
author
Gabriel Schulhof
committed
Collapsible set: Implement "enhanced" option and address #6163.
1 parent 451bd0b commit a0e62d7

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

js/widgets/collapsibleSet.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,39 @@ define( [
1717
var childCollapsiblesSelector = ":mobile-collapsible, " + $.mobile.collapsible.initSelector;
1818

1919
$.widget( "mobile.collapsibleset", $.extend( {
20-
options: $.extend( {}, $.mobile.collapsible.defaults ),
20+
options: $.extend( {
21+
enhanced: false,
22+
}, $.mobile.collapsible.defaults ),
23+
24+
_handleCollapsibleExpand: function( event ) {
25+
var closestCollapsible = $( event.target ).closest( ".ui-collapsible" );
26+
27+
if ( closestCollapsible.parent().is( ":mobile-collapsibleset, :jqmData(role='collapsible-set')" ) ) {
28+
closestCollapsible
29+
.siblings( ".ui-collapsible:not(.ui-collapsible-collapsed)" )
30+
.collapsible( "collapse" );
31+
}
32+
},
2133

2234
_create: function() {
23-
var $el = this.element.addClass( "ui-collapsible-set" );
35+
var elem = this.element,
36+
opts = this.options;
2437

2538
$.extend( this, {
2639
_classes: ""
2740
});
2841

29-
this._updateClasses( this.options );
30-
31-
// Initialize the collapsible set if it's not already initialized
32-
if ( !$el.jqmData( "collapsiblebound" ) ) {
33-
$el
34-
.jqmData( "collapsiblebound", true )
35-
.bind( "collapsibleexpand", function( event ) {
36-
var closestCollapsible = $( event.target ).closest( ".ui-collapsible" );
37-
38-
if ( closestCollapsible.parent().is( ":mobile-collapsibleset, :jqmData(role='collapsible-set')" ) ) {
39-
closestCollapsible
40-
.siblings( ".ui-collapsible:not(.ui-collapsible-collapsed)" )
41-
.collapsible( "collapse" );
42-
}
43-
});
42+
if ( !opts.enhanced ) {
43+
elem.addClass( "ui-collapsible-set" )
4444
}
45+
46+
this
47+
._updateClasses( opts, opts.enhanced )
48+
._on( elem, { collapsibleexpand: "_handleCollapsibleExpand" } );
4549
},
4650

4751
_init: function() {
48-
this._refresh( "true" );
52+
this._refresh( true );
4953

5054
// Because the corners are handled by the collapsible itself and the default state is collapsed
5155
// That was causing https://github.com/jquery/jquery-mobile/issues/4116
@@ -55,7 +59,7 @@ $.widget( "mobile.collapsibleset", $.extend( {
5559
.collapsible( "expand" );
5660
},
5761

58-
_updateClasses: function( options ) {
62+
_updateClasses: function( options, internal ) {
5963
var opts = {
6064
theme: options.theme || this.options.theme,
6165
corners: options.corners || this.options.corners,
@@ -71,7 +75,13 @@ $.widget( "mobile.collapsibleset", $.extend( {
7175
classes += " ui-corner-all";
7276
}
7377

74-
this._toggleClasses( this.element, "_classes", classes );
78+
if ( internal ) {
79+
this._classes = classes;
80+
} else {
81+
this._toggleClasses( this.element, "_classes", classes );
82+
}
83+
84+
return this;
7585
},
7686

7787
_setOptions: function( options ) {

0 commit comments

Comments
 (0)