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

Commit 3ecbf8e

Browse files
committed
Simplified code. Don't add data-* attr if not set by user
1 parent 553de2d commit 3ecbf8e

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

js/jquery.mobile.collapsible.js

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,36 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
3333
collapsibleHeading.next().remove();
3434
}
3535

36-
// Close others in a set
37-
if ( collapsibleSet.length && !collapsibleSet.jqmData( "collapsiblebound" ) ) {
36+
// If we are in a collapsible set
37+
if ( collapsibleSet.length ) {
3838

39-
collapsibleSet
40-
.bind( "expand", function( event ) {
39+
// Initialize the collapsible set if it's not already initialized
40+
if ( !collapsibleSet.jqmData( "collapsiblebound" ) ) {
4141

42-
$( event.target )
43-
.closest( ".ui-collapsible" )
44-
.siblings( ".ui-collapsible" )
45-
.trigger( "collapse" );
42+
collapsibleSet
43+
.jqmData( "collapsiblebound", true )
44+
.bind( "expand", function( event ) {
4645

47-
});
46+
$( event.target )
47+
.closest( ".ui-collapsible" )
48+
.siblings( ".ui-collapsible" )
49+
.trigger( "collapse" );
50+
51+
});
52+
}
53+
54+
colllapsiblesInSet.first()
55+
.find( "a:eq(0)" )
56+
.addClass( "ui-corner-top" )
57+
.find( ".ui-btn-inner" )
58+
.addClass( "ui-corner-top" );
59+
60+
colllapsiblesInSet.last()
61+
.jqmData( "collapsible-last", true )
62+
.find( "a:eq(0)" )
63+
.addClass( "ui-corner-bottom" )
64+
.find( ".ui-btn-inner" )
65+
.addClass( "ui-corner-bottom" );
4866

4967
// Inherit the theme from collapsible-set
5068
if ( !o.theme ) {
@@ -54,16 +72,6 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
5472
if ( !o.contentTheme ) {
5573
o.contentTheme = collapsibleSet.jqmData( "content-theme" );
5674
}
57-
58-
colllapsiblesInSet.each(function() {
59-
var $this = $( this );
60-
if ( !$this.jqmData( "theme" ) ) {
61-
$this.jqmData( "theme", collapsibleSet.jqmData( "theme" ) );
62-
}
63-
if ( !$this.jqmData( "content-theme" ) ) {
64-
$this.jqmData( "content-theme", collapsibleSet.jqmData( "content-theme" ) );
65-
}
66-
});
6775
}
6876

6977
collapsibleContent.addClass( ( o.contentTheme ) ? ( "ui-btn-up-" + o.contentTheme ) : "");
@@ -84,23 +92,6 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
8492
theme: o.theme
8593
})
8694

87-
if ( collapsibleSet.length && !collapsibleSet.jqmData( "collapsiblebound" ) ) {
88-
collapsibleSet.jqmData( "collapsiblebound", true );
89-
90-
colllapsiblesInSet.first()
91-
.find( "a:eq(0)" )
92-
.addClass( "ui-corner-top" )
93-
.find( ".ui-btn-inner" )
94-
.addClass( "ui-corner-top" );
95-
96-
colllapsiblesInSet.last()
97-
.jqmData( "collapsible-last", true )
98-
.find( "a:eq(0)" )
99-
.addClass( "ui-corner-bottom" )
100-
.find( ".ui-btn-inner" )
101-
.addClass( "ui-corner-bottom" );
102-
}
103-
10495
if ( !collapsibleSet.length ) {
10596
collapsibleHeading
10697
.find( "a:eq(0), .ui-btn-inner" )

0 commit comments

Comments
 (0)