@@ -721,9 +721,9 @@ $.widget("ui.selectmenu", {
721
721
this . _setOption ( 'disabled' , true ) ;
722
722
} else {
723
723
if ( type == "optgroup" ) {
724
- this . _disableOptgroup ( index ) ;
724
+ this . _toggleOptgroup ( index , false ) ;
725
725
} else {
726
- this . _disableOption ( index ) ;
726
+ this . _toggleOption ( index , false ) ;
727
727
}
728
728
}
729
729
} ,
@@ -734,52 +734,43 @@ $.widget("ui.selectmenu", {
734
734
this . _setOption ( 'disabled' , false ) ;
735
735
} else {
736
736
if ( type == "optgroup" ) {
737
- this . _enableOptgroup ( index ) ;
737
+ this . _toggleOptgroup ( index , true ) ;
738
738
} else {
739
- this . _enableOption ( index ) ;
739
+ this . _toggleOption ( index , true ) ;
740
740
}
741
741
}
742
742
} ,
743
743
744
744
_disabled : function ( elem ) {
745
745
return $ ( elem ) . hasClass ( this . namespace + '-state-disabled' ) ;
746
746
} ,
747
-
748
- _disableOption : function ( index ) {
749
- var optionElem = this . _optionLis . eq ( index ) ;
750
- if ( optionElem ) {
751
- optionElem . addClass ( this . namespace + '-state-disabled' )
752
- . find ( "a" ) . attr ( "aria-disabled" , true ) ;
753
- this . element . find ( "option" ) . eq ( index ) . attr ( "disabled" , "disabled" ) ;
754
- }
755
- } ,
756
-
757
- _enableOption : function ( index ) {
758
- var optionElem = this . _optionLis . eq ( index ) ;
759
- if ( optionElem ) {
747
+
748
+ _toggleOption : function ( index , flag ) {
749
+ var optionElem = this . _optionLis . eq ( index ) ;
750
+ if ( optionElem ) {
760
751
optionElem
761
- . removeClass ( this . namespace + '-state-disabled' )
762
- . find ( "a" ) . attr ( "aria-disabled" , false ) ;
752
+ . toggleClass ( this . namespace + '-state-disabled' , flag )
753
+ . find ( "a" ) . attr ( "aria-disabled" , ! flag ) ;
754
+ if ( flag ) {
755
+ this . element . find ( "option" ) . eq ( index ) . attr ( "disabled" , "disabled" ) ;
756
+ } else {
763
757
this . element . find ( "option" ) . eq ( index ) . removeAttr ( "disabled" ) ;
764
758
}
759
+ }
765
760
} ,
766
761
767
- _disableOptgroup : function ( index ) {
762
+ // true = enabled, false = disabled
763
+ _toggleOptgroup : function ( index , flag ) {
768
764
var optGroupElem = this . list . find ( 'li.ui-selectmenu-group-' + index ) ;
769
- if ( optGroupElem ) {
765
+ if ( optGroupElem ) {
770
766
optGroupElem
771
- . addClass ( this . namespace + '-state-disabled' )
772
- . attr ( "aria-disabled" , true ) ;
773
- this . element . find ( "optgroup" ) . eq ( index ) . attr ( "disabled" , "disabled" ) ;
774
- }
775
- } ,
776
-
777
- _enableOptgroup : function ( index ) {
778
- var optGroupElem = this . list . find ( 'li.ui-selectmenu-group-' + index ) ;
779
- if ( optGroupElem ) {
780
- optGroupElem . removeClass ( this . namespace + '-state-disabled' )
781
- . attr ( "aria-disabled" , false ) ;
782
- this . element . find ( "optgroup" ) . eq ( index ) . removeAttr ( "disabled" ) ;
767
+ . toggleClass ( this . namespace + '-state-disabled' , flag )
768
+ . attr ( "aria-disabled" , ! flag ) ;
769
+ if ( flag ) {
770
+ this . element . find ( "optgroup" ) . eq ( index ) . attr ( "disabled" , "disabled" ) ;
771
+ } else {
772
+ this . element . find ( "optgroup" ) . eq ( index ) . removeAttr ( "disabled" ) ;
773
+ }
783
774
}
784
775
} ,
785
776
0 commit comments