From: Felix Nagel Date: Sat, 7 Sep 2013 17:12:09 +0000 (+0200) Subject: improved: rework enable / enable option setting X-Git-Tag: selectmenu_v1.4.0~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1b97e728dcccc23a413ca8059624e0516eda3871;p=jquery-ui.git improved: rework enable / enable option setting --- diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js index d5217c09f..e3c8c4d94 100644 --- a/ui/jquery.ui.selectmenu.js +++ b/ui/jquery.ui.selectmenu.js @@ -718,11 +718,7 @@ $.widget("ui.selectmenu", { if ( typeof( index ) == 'undefined' ) { this._setOption( 'disabled', true ); } else { - if ( type == "optgroup" ) { - this._toggleOptgroup( index, false ); - } else { - this._toggleOption( index, false ); - } + this._toggleEnabled( ( type || "option" ), index, false ); } }, @@ -731,47 +727,32 @@ $.widget("ui.selectmenu", { if ( typeof( index ) == 'undefined' ) { this._setOption( 'disabled', false ); } else { - if ( type == "optgroup" ) { - this._toggleOptgroup( index, true ); - } else { - this._toggleOption( index, true ); - } + this._toggleEnabled( ( type || "option" ), index, true ); } }, _disabled: function( elem ) { return $( elem ).hasClass( 'ui-state-disabled' ); }, - - _toggleOption: function( index, flag ) { - var optionElem = this._optionLis.eq( index ); - if ( optionElem ) { - optionElem - .toggleClass( 'ui-state-disabled', !flag ) - .find( "a" ).attr( "aria-disabled", flag ); + + // true = enabled, false = disabled + _toggleEnabled: function( type, index, flag ) { + var element = this.element.find( type ).eq( index ), + elements = ( type === "optgroup" ) ? this.list.find( 'li.ui-selectmenu-group-' + index ) : this._optionLis.eq( index ); + + if ( elements ) { + elements + .toggleClass( 'ui-state-disabled', !flag ) + .attr( "aria-disabled", flag ); + if ( flag ) { - this.element.find( "option" ).eq( index ).removeAttr( "disabled" ); + element.removeAttr( "disabled" ); } else { - this.element.find( "option" ).eq( index ).attr( "disabled", "disabled" ); + element.attr( "disabled", "disabled" ); } } }, - // true = enabled, false = disabled - _toggleOptgroup: function( index, flag ) { - var optGroupElem = this.list.find( 'li.ui-selectmenu-group-' + index ); - if ( optGroupElem ) { - optGroupElem - .toggleClass( 'ui-state-disabled', !flag ) - .attr( "aria-disabled", flag ); - if ( flag ) { - this.element.find( "optgroup" ).eq( index ).removeAttr( "disabled" ); - } else { - this.element.find( "optgroup" ).eq( index ).attr( "disabled", "disabled" ); - } - } - }, - index: function( newIndex ) { if ( arguments.length ) { if ( !this._disabled( $( this._optionLis[ newIndex ] ) ) && newIndex != this._selectedIndex() ) {