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

Commit

Permalink
Collapsible: Set icon options according widget factory. Use preferenc…
Browse files Browse the repository at this point in the history
…es of collapsible set for icon options.
  • Loading branch information
jaspermdegroot committed Dec 3, 2012
1 parent 2fc45e7 commit 11522e2
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions js/widgets/collapsible.js
Expand Up @@ -17,7 +17,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
heading: "h1,h2,h3,h4,h5,h6,legend",
collapsedIcon: "plus",
expandedIcon: "minus",
iconPos: "left",
iconpos: "left",
theme: null,
contentTheme: null,
inset: true,
Expand All @@ -31,8 +31,6 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
o = this.options,
collapsible = $el.addClass( "ui-collapsible" ),
collapsibleHeading = $el.children( o.heading ).first(),
collapsedIcon = $el.jqmData( "collapsed-icon" ) || o.collapsedIcon,
expandedIcon = $el.jqmData( "expanded-icon" ) || o.expandedIcon,
collapsibleContent = collapsible.wrapInner( "<div class='ui-collapsible-content'></div>" ).children( ".ui-collapsible-content" ),
collapsibleSet = $el.closest( ":jqmData(role='collapsible-set')" ).addClass( "ui-collapsible-set" ),
collapsibleClasses = "";
Expand All @@ -54,18 +52,15 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
o.contentTheme = collapsibleSet.jqmData( "content-theme" );
}

// Get the preference for collapsed icon in the set
if ( !o.collapsedIcon ) {
o.collapsedIcon = collapsibleSet.jqmData( "collapsed-icon" );
}
// Get the preference for expanded icon in the set
if ( !o.expandedIcon ) {
o.expandedIcon = collapsibleSet.jqmData( "expanded-icon" );
}
// Gets the preference icon position in the set
if ( !o.iconpos ) {
o.iconpos = collapsibleSet.jqmData( "iconpos" );
}
// Get the preference for collapsed icon in the set, but override with data- attribute on the individual collapsible
o.collapsedIcon = $el.jqmData( "collapsed-icon" ) || collapsibleSet.jqmData( "collapsed-icon" ) || o.collapsedIcon;

// Get the preference for expanded icon in the set, but override with data- attribute on the individual collapsible
o.expandedIcon = $el.jqmData( "expanded-icon" ) || collapsibleSet.jqmData( "expanded-icon" ) || o.expandedIcon;

// Gets the preference icon position in the set, but override with data- attribute on the individual collapsible
o.iconpos = $el.jqmData( "iconpos" ) || collapsibleSet.jqmData( "iconpos" ) || o.iconpos;

// Inherit the preference for inset from collapsible-set or set the default value to ensure equalty within a set
if ( collapsibleSet.jqmData( "inset" ) !== undefined ) {
o.inset = collapsibleSet.jqmData( "inset" );
Expand Down Expand Up @@ -99,9 +94,6 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
collapsible.addClass( collapsibleClasses );
}

collapsedIcon = $el.jqmData( "collapsed-icon" ) || o.collapsedIcon ;
expandedIcon = $el.jqmData( "expanded-icon" ) || o.expandedIcon ;

collapsibleHeading
//drop heading in before content
.insertBefore( collapsibleContent )
Expand All @@ -114,8 +106,8 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
.buttonMarkup({
shadow: false,
corners: false,
iconpos: $el.jqmData( "iconpos" ) || o.iconpos ,
icon: collapsedIcon,
iconpos: o.iconpos,
icon: o.collapsedIcon,
mini: o.mini,
theme: o.theme
});
Expand All @@ -135,9 +127,9 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
.text( isCollapse ? o.expandCueText : o.collapseCueText )
.end()
.find( ".ui-icon" )
.toggleClass( "ui-icon-" + expandedIcon, !isCollapse )
.toggleClass( "ui-icon-" + o.expandedIcon, !isCollapse )
// logic or cause same icon for expanded/collapsed state would remove the ui-icon-class
.toggleClass( "ui-icon-" + collapsedIcon, ( isCollapse || expandedIcon === collapsedIcon ) )
.toggleClass( "ui-icon-" + o.collapsedIcon, ( isCollapse || o.expandedIcon === o.collapsedIcon ) )
.end()
.find( "a" ).first().removeClass( $.mobile.activeBtnClass );

Expand Down

0 comments on commit 11522e2

Please sign in to comment.