1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Visually groups sets of buttons, checks, radios, etc.
3 //>>label: Controlgroups
5 //>>css.structure: ../css/structure/jquery.mobile.controlgroup.css
6 //>>css.theme: ../css/themes/default/jquery.mobile.theme.css
8 define( [ "jquery", "./jquery.mobile.buttonMarkup" ], function( $ ) {
9 //>>excludeEnd("jqmBuildExclude");
10 (function( $, undefined ) {
12 $.fn.controlgroup = function( options ) {
13 function flipClasses( els, flCorners ) {
14 els.removeClass( "ui-btn-corner-all ui-corner-top ui-corner-bottom ui-corner-left ui-corner-right ui-controlgroup-last ui-shadow" )
15 .eq( 0 ).addClass( flCorners[ 0 ] )
17 .last().addClass( flCorners[ 1 ] ).addClass( "ui-controlgroup-last" );
20 return this.each(function() {
23 direction: $el.jqmData( "type" ) || "vertical",
25 excludeInvisible: true,
26 mini: $el.jqmData( "mini" )
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" ],
32 type = $el.find( "input" ).first().attr( "type" );
34 // First unwrap the controls if the controlgroup was already enhanced
35 if ( groupcontrols.length ) {
36 groupcontrols.contents().unwrap();
38 $el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
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 ) );
44 } else if ( groupheading.length ) {
45 // Just move the heading if the controlgroup was already enhanced
46 $el.prepend( groupheading );
49 $el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );
51 flipClasses( $el.find( ".ui-btn" + ( o.excludeInvisible ? ":visible" : "" ) ).not( '.ui-slider-handle' ), flCorners );
52 flipClasses( $el.find( ".ui-btn-inner" ), flCorners );
55 $el.addClass( "ui-shadow" );
59 $el.addClass( "ui-mini" );
65 // The pagecreate handler for controlgroup is in jquery.mobile.init because of the soft-dependency on the wrapped widgets
68 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
70 //>>excludeEnd("jqmBuildExclude");