/js/widgets/controlgroup.js
https://github.com/forresst/jquery-mobile-fr_FR · JavaScript · 120 lines · 82 code · 18 blank · 20 comment · 4 complexity · e3003fd4ecfdf1eefcb36c97906f0b58 MD5 · raw file
- //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
- //>>description: Visually groups sets of buttons, checks, radios, etc.
- //>>label: Controlgroups
- //>>group: Forms
- //>>css.structure: ../css/structure/jquery.mobile.controlgroup.css
- //>>css.theme: ../css/themes/default/jquery.mobile.theme.css
- define( [ "jquery",
- "../jquery.mobile.buttonMarkup",
- "./addFirstLastClasses",
- "../jquery.mobile.widget" ], function( $ ) {
- //>>excludeEnd("jqmBuildExclude");
- (function( $, undefined ) {
- $.widget( "mobile.controlgroup", $.mobile.widget, {
- options: {
- shadow: false,
- corners: true,
- excludeInvisible: true,
- type: "vertical",
- mini: false,
- initSelector: ":jqmData(role='controlgroup')"
- },
- _create: function() {
- var $el = this.element,
- ui = {
- inner: $( "<div class='ui-controlgroup-controls'></div>" ),
- legend: $( "<div role='heading' class='ui-controlgroup-label'></div>" )
- },
- grouplegend = $el.children( "legend" ),
- self = this;
- // Apply the proto
- $el.wrapInner( ui.inner );
- if ( grouplegend.length ) {
- ui.legend.append( grouplegend ).insertBefore( $el.children( 0 ) );
- }
- $el.addClass( "ui-corner-all ui-controlgroup" );
- $.extend( this, {
- _initialRefresh: true
- });
- $.each( this.options, function( key, value ) {
- // Cause initial options to be applied by their handler by temporarily setting the option to undefined
- // - the handler then sets it to the initial value
- self.options[ key ] = undefined;
- self._setOption( key, value, true );
- });
- },
- _init: function() {
- this.refresh();
- },
- _setOption: function( key, value ) {
- var setter = "_set" + key.charAt( 0 ).toUpperCase() + key.slice( 1 );
- if ( this[ setter ] !== undefined ) {
- this[ setter ]( value );
- }
- this._super( key, value );
- this.element.attr( "data-" + ( $.mobile.ns || "" ) + ( key.replace( /([A-Z])/, "-$1" ).toLowerCase() ), value );
- },
- _setType: function( value ) {
- this.element
- .removeClass( "ui-controlgroup-horizontal ui-controlgroup-vertical" )
- .addClass( "ui-controlgroup-" + value );
- this.refresh();
- },
- _setCorners: function( value ) {
- this.element.toggleClass( "ui-corner-all", value );
- },
- _setShadow: function( value ) {
- this.element.toggleClass( "ui-shadow", value );
- },
- _setMini: function( value ) {
- this.element.toggleClass( "ui-mini", value );
- },
- container: function() {
- return this.element.children( ".ui-controlgroup-controls" );
- },
- refresh: function() {
- var els = this.element.find( ".ui-btn" ).not( ".ui-slider-handle" ),
- create = this._initialRefresh;
- if ( $.mobile.checkboxradio ) {
- this.element.find( ":mobile-checkboxradio" ).checkboxradio( "refresh" );
- }
- this._addFirstLastClasses( els, this.options.excludeInvisible ? this._getVisibles( els, create ) : els, create );
- this._initialRefresh = false;
- }
- });
- $.widget( "mobile.controlgroup", $.mobile.controlgroup, $.mobile.behaviors.addFirstLastClasses );
- // TODO: Implement a mechanism to allow widgets to become enhanced in the
- // correct order when their correct enhancement depends on other widgets in
- // the page being correctly enhanced already.
- //
- // For now, we wait until dom-ready to attach the controlgroup's enhancement
- // hook, because by that time, all the other widgets' enhancement hooks should
- // already be in place, ensuring that all widgets that need to be grouped will
- // already have been enhanced by the time the controlgroup is created.
- $( function() {
- $.mobile.document.bind( "pagecreate create", function( e ) {
- $.mobile.controlgroup.prototype.enhanceWithin( e.target, true );
- });
- });
- })(jQuery);
- //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
- });
- //>>excludeEnd("jqmBuildExclude");