Permalink
Browse files

Collapsible: Set icon options according widget factory. Use preferenc…

…es of collapsible set for icon options.
  • Loading branch information...
1 parent 2fc45e7 commit 11522e2879fa62ee4cc6983be81562ee213b5acc @jaspermdegroot jaspermdegroot committed Dec 3, 2012
Showing with 14 additions and 22 deletions.
  1. +14 −22 js/widgets/collapsible.js
@@ -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,
@@ -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 = "";
@@ -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" );
@@ -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 )
@@ -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
});
@@ -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 );

0 comments on commit 11522e2

Please sign in to comment.