Skip to content
This repository
Browse code

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

… Fixes #4716 - Calling controlgroup constructor causes fieldset width to shrink.
  • Loading branch information...
commit 352d4b347b9cf356d560044f7c4f3fa4747c5289 1 parent c0a016e
Jasper de Groot authored August 02, 2012

Showing 1 changed file with 14 additions and 5 deletions. Show diff stats Hide diff stats

  1. 19  js/jquery.mobile.controlGroup.js
19  js/jquery.mobile.controlGroup.js
@@ -25,16 +25,25 @@ $.fn.controlgroup = function( options ) {
25 25
 						excludeInvisible: true,
26 26
 						mini: $el.jqmData( "mini" )
27 27
 					}, options ),
28  
-			groupheading = $el.children( "legend" ),
  28
+			grouplegend = $el.children( "legend" ),
  29
+			groupheading = $el.children( ".ui-controlgroup-label" ),
  30
+			groupcontrols = $el.children( ".ui-controlgroup-controls" ),
29 31
 			flCorners = o.direction === "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
30 32
 			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
+		}
32 38
 		$el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
33 39
 
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 );
38 47
 		}
39 48
 
40 49
 		$el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );

0 notes on commit 352d4b3

Please sign in to comment.
Something went wrong with that request. Please try again.