Permalink
Browse files

Controlgroup: Prevent the controls from being wrapped multiple times. F…

…ixes #4716 - Calling controlgroup constructor causes fieldset width to shrink.
  • Loading branch information...
jaspermdegroot committed Aug 2, 2012
1 parent ce018b2 commit 4bf78fdf96f90896bc009faa0eeb79dabe755eab
Showing with 16 additions and 7 deletions.
  1. +16 −7 js/jquery.mobile.controlGroup.js
@@ -25,16 +25,25 @@ $.fn.controlgroup = function( options ) {
excludeInvisible: true,
mini: $el.jqmData( "mini" )
}, options ),
groupheading = $el.children( "legend" ),
flCorners = o.direction == "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
grouplegend = $el.children( "legend" ),
groupheading = $el.children( ".ui-controlgroup-label" ),
groupcontrols = $el.children( ".ui-controlgroup-controls" ),
flCorners = o.direction === "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
type = $el.find( "input" ).first().attr( "type" );
// First unwrap the controls if the controlgroup was already enhanced
if ( groupcontrols.length ) {
groupcontrols.contents().unwrap();
}
$el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
// Replace legend with more stylable replacement div
if ( groupheading.length ) {
$( "<div role='heading' class='ui-controlgroup-label'>" + groupheading.html() + "</div>" ).insertBefore( $el.children(0) );
groupheading.remove();
if ( grouplegend.length ) {
// Replace legend with more stylable replacement div
$( "<div role='heading' class='ui-controlgroup-label'>" + grouplegend.html() + "</div>" ).insertBefore( $el.children( 0 ) );
grouplegend.remove();
} else if ( groupheading.length ) {
// Just move the heading if the controlgroup was already enhanced
$el.prepend( groupheading );
}
$el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );

0 comments on commit 4bf78fd

Please sign in to comment.