1 (function( $, undefined ) {
3 $.fn.controlgroup = function( options ) {
4 function flipClasses( els, flCorners ) {
5 els.removeClass( "ui-btn-corner-all ui-corner-top ui-corner-bottom ui-corner-left ui-corner-right ui-controlgroup-last ui-shadow" )
6 .eq( 0 ).addClass( flCorners[ 0 ] )
8 .last().addClass( flCorners[ 1 ] ).addClass( "ui-controlgroup-last" );
11 return this.each(function() {
14 direction: $.mobile.getAttrFixed( $el[0], "data-"+ $.mobile.ns + "type" ) || "vertical",
16 excludeInvisible: true,
17 mini: $.mobile.getAttrFixed( $el[0], "data-"+ $.mobile.ns + "mini" )
19 grouplegend = $el.children( "legend" ),
20 groupheading = $el.children( ".ui-controlgroup-label" ),
21 groupcontrols = $el.children( ".ui-controlgroup-controls" ),
22 flCorners = o.direction === "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
23 type = $el.find( "input" ).first().attr( "type" );
25 // First unwrap the controls if the controlgroup was already enhanced
26 if ( groupcontrols.length ) {
27 groupcontrols.contents().unwrap();
29 $el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
31 if ( grouplegend.length ) {
32 // Replace legend with more stylable replacement div
33 $( "<div role='heading' class='ui-controlgroup-label'>" + grouplegend.html() + "</div>" ).insertBefore( $el.children( 0 ) );
35 } else if ( groupheading.length ) {
36 // Just move the heading if the controlgroup was already enhanced
37 $el.prepend( groupheading );
40 $el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );
42 flipClasses( $el.find( ".ui-btn" + ( o.excludeInvisible ? ":visible" : "" ) ).not( '.ui-slider-handle' ), flCorners );
43 flipClasses( $el.find( ".ui-btn-inner" ), flCorners );
46 $el.addClass( "ui-shadow" );
50 $el.addClass( "ui-mini" );
56 // The pagecreate handler for controlgroup is in jquery.mobile.init because of the soft-dependency on the wrapped widgets