Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / js / jquery.mobile.controlGroup.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Visually groups sets of buttons, checks, radios, etc.
3 //>>label: Controlgroups
4 //>>group: Forms
5 //>>css.structure: ../css/structure/jquery.mobile.controlgroup.css
6 //>>css.theme: ../css/themes/default/jquery.mobile.theme.css
7
8 define( [ "jquery", "./jquery.mobile.buttonMarkup" ], function( $ ) {
9 //>>excludeEnd("jqmBuildExclude");
10 (function( $, undefined ) {
11
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 ] )
16                         .end()
17                         .last().addClass( flCorners[ 1 ] ).addClass( "ui-controlgroup-last" );
18         }
19
20         return this.each(function() {
21                 var $el = $( this ),
22                         o = $.extend({
23                                                 direction: $el.jqmData( "type" ) || "vertical",
24                                                 shadow: false,
25                                                 excludeInvisible: true,
26                                                 mini: $el.jqmData( "mini" )
27                                         }, options ),
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" );
33
34                 // First unwrap the controls if the controlgroup was already enhanced
35                 if ( groupcontrols.length ) {
36                         groupcontrols.contents().unwrap();
37                 }
38                 $el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
39
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 );
47                 }
48
49                 $el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );
50
51                 flipClasses( $el.find( ".ui-btn" + ( o.excludeInvisible ? ":visible" : "" ) ).not( '.ui-slider-handle' ), flCorners );
52                 flipClasses( $el.find( ".ui-btn-inner" ), flCorners );
53
54                 if ( o.shadow ) {
55                         $el.addClass( "ui-shadow" );
56                 }
57
58                 if ( o.mini ) {
59                         $el.addClass( "ui-mini" );
60                 }
61
62         });
63 };
64
65 // The pagecreate handler for controlgroup is in jquery.mobile.init because of the soft-dependency on the wrapped widgets
66
67 })(jQuery);
68 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
69 });
70 //>>excludeEnd("jqmBuildExclude");