|
| 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", |
| 9 | + "../jquery.mobile.buttonMarkup", |
| 10 | + "forms/button", |
| 11 | + "../jquery.mobile.widget" ], function( $ ) { |
| 12 | +//>>excludeEnd("jqmBuildExclude"); |
| 13 | +(function( $, undefined ) { |
| 14 | + |
| 15 | + function flipClasses( els, flCorners ) { |
| 16 | + els.removeClass( "ui-controlgroup-last" ) |
| 17 | + .buttonMarkup( { corners: false, shadow: false } ) |
| 18 | + .eq( 0 ).buttonMarkup( { corners: flCorners[ 0 ] } ) |
| 19 | + .end() |
| 20 | + .last().buttonMarkup( { corners: flCorners[ 1 ] } ).addClass( "ui-controlgroup-last" ); |
| 21 | + } |
| 22 | + |
| 23 | + $.widget( "mobile.controlgroup", $.mobile.widget, { |
| 24 | + options: { |
| 25 | + shadow: false, |
| 26 | + excludeInvisible: false, |
| 27 | + type: "vertical", |
| 28 | + mini: false, |
| 29 | + initSelector: ":jqmData(role='controlgroup')" |
| 30 | + }, |
| 31 | + |
| 32 | + _create: function() { |
| 33 | + var $el = this.element, |
| 34 | + ui = { |
| 35 | + inner: $( "<div class='ui-controlgroup-controls'></div>" ), |
| 36 | + legend: $( "<div role='heading' class='ui-controlgroup-label'></div>" ) |
| 37 | + }, |
| 38 | + grouplegend = $el.children( "legend" ), |
| 39 | + groupcontrols = $el.children( ".ui-controlgroup-controls" ), |
| 40 | + self = this; |
| 41 | + |
| 42 | + // Apply the proto |
| 43 | + $el.wrapInner( ui.inner ); |
| 44 | + if ( grouplegend.length ) { |
| 45 | + ui.legend.append( grouplegend ).insertBefore( $el.children( 0 ) ); |
| 46 | + } |
| 47 | + $el.addClass( "ui-btn-corner-all ui-controlgroup" ); |
| 48 | + |
| 49 | + $.each( this.options, function( key, value ) { |
| 50 | + // Cause initial options to be applied by their handler by temporarily setting the option to undefined |
| 51 | + // - the handler then sets it to the initial value |
| 52 | + self.options[ key ] = undefined; |
| 53 | + self._setOption( key, value, true ); |
| 54 | + }); |
| 55 | + |
| 56 | + this.refresh(); |
| 57 | + }, |
| 58 | + |
| 59 | + _setOption: function( key, value ) { |
| 60 | + var setter = "_set" + key.charAt( 0 ).toUpperCase() + key.slice( 1 ); |
| 61 | + |
| 62 | + if ( this[ setter ] !== undefined ) { |
| 63 | + this[ setter ]( value ); |
| 64 | + } |
| 65 | + |
| 66 | + this._super( "_setOption", key, value ); |
| 67 | + this.element.attr( "data-" + ( $.mobile.ns || "" ) + ( key.replace( /([A-Z])/, "-$1" ).toLowerCase() ), value ); |
| 68 | + }, |
| 69 | + |
| 70 | + _setType: function( value ) { |
| 71 | + this.element |
| 72 | + .removeClass( "ui-controlgroup-horizontal ui-controlgroup-vertical" ) |
| 73 | + .addClass( "ui-controlgroup-" + value ); |
| 74 | + this.options.type = value; |
| 75 | + this.refresh(); |
| 76 | + }, |
| 77 | + |
| 78 | + _setShadow: function( value ) { |
| 79 | + this.element.toggleClass( "ui-shadow", value ); |
| 80 | + }, |
| 81 | + |
| 82 | + _setMini: function( value ) { |
| 83 | + this.element.toggleClass( "ui-mini", value ); |
| 84 | + }, |
| 85 | + |
| 86 | + refresh: function() { |
| 87 | + var els = this.element |
| 88 | + .find( ".ui-btn" + ( this.options.excludeInvisible ? ":visible" : "" ) ) |
| 89 | + .not( '.ui-slider-handle' ), |
| 90 | + corners = [ true, true ]; |
| 91 | + |
| 92 | + if ( els.length > 1 ) { |
| 93 | + corners = ( this.options.type === "horizontal" ? [ "left", "right" ] : [ "top", "bottom" ] ); |
| 94 | + } |
| 95 | + |
| 96 | + flipClasses( els, corners ); |
| 97 | + } |
| 98 | + }); |
| 99 | + |
| 100 | + $( document ).bind( "pagecreate create", function( e ) { |
| 101 | + $.mobile.controlgroup.prototype.enhanceWithin( e.target, true ); |
| 102 | + }); |
| 103 | +})(jQuery); |
| 104 | +//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude); |
| 105 | +}); |
| 106 | +//>>excludeEnd("jqmBuildExclude"); |
0 commit comments