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

Commit 4bf78fd

Browse files
Controlgroup: Prevent the controls from being wrapped multiple times. Fixes #4716 - Calling controlgroup constructor causes fieldset width to shrink.
1 parent ce018b2 commit 4bf78fd

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

js/jquery.mobile.controlGroup.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,25 @@ $.fn.controlgroup = function( options ) {
2525
excludeInvisible: true,
2626
mini: $el.jqmData( "mini" )
2727
}, options ),
28-
groupheading = $el.children( "legend" ),
29-
flCorners = o.direction == "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
28+
grouplegend = $el.children( "legend" ),
29+
groupheading = $el.children( ".ui-controlgroup-label" ),
30+
groupcontrols = $el.children( ".ui-controlgroup-controls" ),
31+
flCorners = o.direction === "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
3032
type = $el.find( "input" ).first().attr( "type" );
31-
33+
34+
// First unwrap the controls if the controlgroup was already enhanced
35+
if ( groupcontrols.length ) {
36+
groupcontrols.contents().unwrap();
37+
}
3238
$el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
3339

34-
// Replace legend with more stylable replacement div
35-
if ( groupheading.length ) {
36-
$( "<div role='heading' class='ui-controlgroup-label'>" + groupheading.html() + "</div>" ).insertBefore( $el.children(0) );
37-
groupheading.remove();
40+
if ( grouplegend.length ) {
41+
// Replace legend with more stylable replacement div
42+
$( "<div role='heading' class='ui-controlgroup-label'>" + grouplegend.html() + "</div>" ).insertBefore( $el.children( 0 ) );
43+
grouplegend.remove();
44+
} else if ( groupheading.length ) {
45+
// Just move the heading if the controlgroup was already enhanced
46+
$el.prepend( groupheading );
3847
}
3948

4049
$el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );

0 commit comments

Comments
 (0)