@@ -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