Skip to content

Commit

Permalink
improved: disable optgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
fnagel committed Nov 23, 2012
1 parent 56a7e61 commit d347aa5
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions ui/jquery.ui.selectmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ $.widget("ui.selectmenu", {
this._setOption( 'disabled', true );
} else {
if ( type == "optgroup" ) {
this._disableOptgroup( index );
this._toggleOptgroup( index, false );
} else {
this._disableOption( index );
}
Expand All @@ -734,7 +734,7 @@ $.widget("ui.selectmenu", {
this._setOption( 'disabled', false );
} else {
if ( type == "optgroup" ) {
this._enableOptgroup( index );
this._toggleOptgroup( index, true );
} else {
this._enableOption( index );
}
Expand Down Expand Up @@ -764,22 +764,18 @@ $.widget("ui.selectmenu", {
}
},

_disableOptgroup: function( index ) {
// true = enabled, false = disabled
_toggleOptgroup: function( index, flag ) {
var optGroupElem = this.list.find( 'li.ui-selectmenu-group-' + index );
if ( optGroupElem ) {
if ( optGroupElem ) {
optGroupElem
.addClass( this.namespace + '-state-disabled' )
.attr( "aria-disabled", true );
this.element.find( "optgroup" ).eq( index ).attr( "disabled", "disabled" );
}
},

_enableOptgroup: function( index ) {
var optGroupElem = this.list.find( 'li.ui-selectmenu-group-' + index );
if ( optGroupElem ) {
optGroupElem.removeClass( this.namespace + '-state-disabled' )
.attr( "aria-disabled", false);
this.element.find( "optgroup" ).eq( index ).removeAttr( "disabled" );
.toggleClass( this.namespace + '-state-disabled', flag )
.attr( "aria-disabled", !flag );
if ( flag ) {
this.element.find( "optgroup" ).eq( index ).attr( "disabled", "disabled" );
} else {
this.element.find( "optgroup" ).eq( index ).removeAttr( "disabled" );
}
}
},

Expand Down

0 comments on commit d347aa5

Please sign in to comment.