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

Commit 11522e2

Browse files
Collapsible: Set icon options according widget factory. Use preferences of collapsible set for icon options.
1 parent 2fc45e7 commit 11522e2

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

js/widgets/collapsible.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
1717
heading: "h1,h2,h3,h4,h5,h6,legend",
1818
collapsedIcon: "plus",
1919
expandedIcon: "minus",
20-
iconPos: "left",
20+
iconpos: "left",
2121
theme: null,
2222
contentTheme: null,
2323
inset: true,
@@ -31,8 +31,6 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
3131
o = this.options,
3232
collapsible = $el.addClass( "ui-collapsible" ),
3333
collapsibleHeading = $el.children( o.heading ).first(),
34-
collapsedIcon = $el.jqmData( "collapsed-icon" ) || o.collapsedIcon,
35-
expandedIcon = $el.jqmData( "expanded-icon" ) || o.expandedIcon,
3634
collapsibleContent = collapsible.wrapInner( "<div class='ui-collapsible-content'></div>" ).children( ".ui-collapsible-content" ),
3735
collapsibleSet = $el.closest( ":jqmData(role='collapsible-set')" ).addClass( "ui-collapsible-set" ),
3836
collapsibleClasses = "";
@@ -54,18 +52,15 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
5452
o.contentTheme = collapsibleSet.jqmData( "content-theme" );
5553
}
5654

57-
// Get the preference for collapsed icon in the set
58-
if ( !o.collapsedIcon ) {
59-
o.collapsedIcon = collapsibleSet.jqmData( "collapsed-icon" );
60-
}
61-
// Get the preference for expanded icon in the set
62-
if ( !o.expandedIcon ) {
63-
o.expandedIcon = collapsibleSet.jqmData( "expanded-icon" );
64-
}
65-
// Gets the preference icon position in the set
66-
if ( !o.iconpos ) {
67-
o.iconpos = collapsibleSet.jqmData( "iconpos" );
68-
}
55+
// Get the preference for collapsed icon in the set, but override with data- attribute on the individual collapsible
56+
o.collapsedIcon = $el.jqmData( "collapsed-icon" ) || collapsibleSet.jqmData( "collapsed-icon" ) || o.collapsedIcon;
57+
58+
// Get the preference for expanded icon in the set, but override with data- attribute on the individual collapsible
59+
o.expandedIcon = $el.jqmData( "expanded-icon" ) || collapsibleSet.jqmData( "expanded-icon" ) || o.expandedIcon;
60+
61+
// Gets the preference icon position in the set, but override with data- attribute on the individual collapsible
62+
o.iconpos = $el.jqmData( "iconpos" ) || collapsibleSet.jqmData( "iconpos" ) || o.iconpos;
63+
6964
// Inherit the preference for inset from collapsible-set or set the default value to ensure equalty within a set
7065
if ( collapsibleSet.jqmData( "inset" ) !== undefined ) {
7166
o.inset = collapsibleSet.jqmData( "inset" );
@@ -99,9 +94,6 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
9994
collapsible.addClass( collapsibleClasses );
10095
}
10196

102-
collapsedIcon = $el.jqmData( "collapsed-icon" ) || o.collapsedIcon ;
103-
expandedIcon = $el.jqmData( "expanded-icon" ) || o.expandedIcon ;
104-
10597
collapsibleHeading
10698
//drop heading in before content
10799
.insertBefore( collapsibleContent )
@@ -114,8 +106,8 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
114106
.buttonMarkup({
115107
shadow: false,
116108
corners: false,
117-
iconpos: $el.jqmData( "iconpos" ) || o.iconpos ,
118-
icon: collapsedIcon,
109+
iconpos: o.iconpos,
110+
icon: o.collapsedIcon,
119111
mini: o.mini,
120112
theme: o.theme
121113
});
@@ -135,9 +127,9 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
135127
.text( isCollapse ? o.expandCueText : o.collapseCueText )
136128
.end()
137129
.find( ".ui-icon" )
138-
.toggleClass( "ui-icon-" + expandedIcon, !isCollapse )
130+
.toggleClass( "ui-icon-" + o.expandedIcon, !isCollapse )
139131
// logic or cause same icon for expanded/collapsed state would remove the ui-icon-class
140-
.toggleClass( "ui-icon-" + collapsedIcon, ( isCollapse || expandedIcon === collapsedIcon ) )
132+
.toggleClass( "ui-icon-" + o.collapsedIcon, ( isCollapse || o.expandedIcon === o.collapsedIcon ) )
141133
.end()
142134
.find( "a" ).first().removeClass( $.mobile.activeBtnClass );
143135

0 commit comments

Comments
 (0)