1c2b71d0f25e57fe045e38413db41139ae9871b6
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / js / jquery.mobile.controlGroup.js
1 /* 
2 * "controlgroup" plugin - corner-rounding for groups of buttons, checks, radios, etc
3 */
4
5 (function( $, undefined ) {
6
7 $.fn.controlgroup = function( options ) {
8
9         return this.each(function() {
10
11                 var $el = $( this ),
12                         o = $.extend({
13                                                 direction: $el.jqmData( "type" ) || "vertical",
14                                                 shadow: false,
15                                                 excludeInvisible: true
16                                         }, options ),
17                         groupheading = $el.children( "legend" ),
18                         flCorners = o.direction == "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
19                         type = $el.find( "input" ).first().attr( "type" );
20
21                 // Replace legend with more stylable replacement div
22                 if ( groupheading.length ) {
23                         $el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
24                         $( "<div role='heading' class='ui-controlgroup-label'>" + groupheading.html() + "</div>" ).insertBefore( $el.children(0) );
25                         groupheading.remove();
26                 }
27
28                 $el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );
29
30                 // TODO: This should be moved out to the closure
31                 // otherwise it is redefined each time controlgroup() is called
32                 function flipClasses( els ) {
33                         els.removeClass( "ui-btn-corner-all ui-shadow" )
34                                 .eq( 0 ).addClass( flCorners[ 0 ] )
35                                 .end()
36                                 .last().addClass( flCorners[ 1 ] ).addClass( "ui-controlgroup-last" );
37                 }
38
39                 flipClasses( $el.find( ".ui-btn" + ( o.excludeInvisible ? ":visible" : "" ) ) );
40                 flipClasses( $el.find( ".ui-btn-inner" ) );
41
42                 if ( o.shadow ) {
43                         $el.addClass( "ui-shadow" );
44                 }
45         });
46 };
47
48 //auto self-init widgets
49 $( document ).bind( "pagecreate create", function( e ){
50         $( ":jqmData(role='controlgroup')", e.target ).controlgroup({ excludeInvisible: false });
51 });
52
53 })(jQuery);