]> source.dussan.org Git - jquery-ui.git/commitdiff
improved: rework enable / enable option setting
authorFelix Nagel <info@felixnagel.com>
Sat, 7 Sep 2013 17:12:09 +0000 (19:12 +0200)
committerFelix Nagel <info@felixnagel.com>
Sat, 7 Sep 2013 17:12:09 +0000 (19:12 +0200)
ui/jquery.ui.selectmenu.js

index d5217c09f93c77b8c267664adfe407a781b79ec4..e3c8c4d94279e9bef685f5c04e1d526b8fdaea94 100644 (file)
@@ -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() ) {