From 1b97e728dcccc23a413ca8059624e0516eda3871 Mon Sep 17 00:00:00 2001 From: Felix Nagel Date: Sat, 7 Sep 2013 19:12:09 +0200 Subject: [PATCH] improved: rework enable / enable option setting --- ui/jquery.ui.selectmenu.js | 49 ++++++++++++-------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) 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() ) { -- 2.39.5