@@ -174,7 +174,7 @@ $.widget( "mobile.collapsible", {
174174 } ,
175175
176176 _applyOptions : function ( options ) {
177- var isCollapsed , newTheme , oldTheme , hasCorners ,
177+ var isCollapsed , newTheme , oldTheme , hasCorners , hasIcon ,
178178 elem = this . element ,
179179 currentOpts = this . _renderedOptions ,
180180 ui = this . _ui ,
@@ -191,41 +191,61 @@ $.widget( "mobile.collapsible", {
191191
192192 isCollapsed = elem . hasClass ( "ui-collapsible-collapsed" ) ;
193193
194- // Only options referring to the current state need to be applied right away
195- // It is enough to store options covering the alternate in this.options.
194+ // We only need to apply the cue text for the current state right away.
195+ // The cue text for the alternate state will be stored in the options
196+ // and applied the next time the collapsible's state is toggled
196197 if ( isCollapsed ) {
197198 if ( opts . expandCueText !== undefined ) {
198199 status . text ( opts . expandCueText ) ;
199200 }
200- if ( opts . collapsedIcon !== undefined ) {
201- if ( currentOpts . collapsedIcon ) {
202- anchor . removeClass ( "ui-icon-" + currentOpts . collapsedIcon ) ;
203- }
204- if ( / f a l s e / i. test ( opts . collapsedIcon ) ) {
205- anchor . removeClass ( "ui-btn-icon-" + ( currentOpts . iconPos === "right" ? "right" : "left" ) ) ;
206- } else {
207- anchor . addClass ( "ui-icon-" + opts . collapsedIcon )
208- . toggleClass ( "ui-btn-icon-" + ( currentOpts . iconPos === "right" ? "right" : "left" ) , true ) ;
209- }
210- }
211201 } else {
212202 if ( opts . collapseCueText !== undefined ) {
213203 status . text ( opts . collapseCueText ) ;
214204 }
215- if ( opts . expandedIcon !== undefined ) {
216- if ( currentOpts . expandedIcon ) {
217- anchor . removeClass ( "ui-icon-" + currentOpts . expandedIcon ) ;
218- }
219- if ( opts . expandedIcon ) {
220- anchor . addClass ( "ui-icon-" + opts . expandedIcon ) ;
221- }
222- }
223205 }
224206
225- if ( opts . iconpos !== undefined ) {
226- anchor
227- . removeClass ( iconposClass ( currentOpts . iconpos ) )
228- . addClass ( iconposClass ( opts . iconpos ) ) ;
207+ // Update icon
208+
209+ // Is it supposed to have an icon?
210+ hasIcon =
211+
212+ // If the collapsedIcon is being set, consult that
213+ ( opts . collapsedIcon !== undefined ? opts . collapsedIcon !== false :
214+
215+ // Otherwise consult the existing option value
216+ currentOpts . collapsedIcon !== false ) ;
217+
218+
219+ // If any icon-related options have changed, make sure the new icon
220+ // state is reflected by first removing all icon-related classes
221+ // reflecting the current state and then adding all icon-related
222+ // classes for the new state
223+ if ( ! ( opts . iconpos === undefined &&
224+ opts . collapsedIcon === undefined &&
225+ opts . expandedIcon === undefined ) ) {
226+
227+ // Remove all current icon-related classes
228+ anchor . removeClass ( [ iconposClass ( currentOpts . iconpos ) ]
229+ . concat ( ( currentOpts . expandedIcon ?
230+ [ "ui-icon-" + currentOpts . expandedIcon ] : [ ] ) )
231+ . concat ( ( currentOpts . collapsedIcon ?
232+ [ "ui-icon-" + currentOpts . collapsedIcon ] : [ ] ) )
233+ . join ( " " ) ) ;
234+
235+ // Add new classes if an icon is supposed to be present
236+ if ( hasIcon ) {
237+ anchor . addClass (
238+ [ iconposClass ( opts . iconpos !== undefined ?
239+ opts . iconpos : currentOpts . iconpos ) ]
240+ . concat ( isCollapsed ?
241+ [ "ui-icon-" + ( opts . collapsedIcon !== undefined ?
242+ opts . collapsedIcon :
243+ currentOpts . collapsedIcon ) ] :
244+ [ "ui-icon-" + ( opts . expandedIcon !== undefined ?
245+ opts . expandedIcon :
246+ currentOpts . expandedIcon ) ] )
247+ . join ( " " ) ) ;
248+ }
229249 }
230250
231251 if ( opts . theme !== undefined ) {
0 commit comments