Skip to content

Commit 1b97e72

Browse files
committed
improved: rework enable / enable option setting
1 parent d9ad9d0 commit 1b97e72

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

ui/jquery.ui.selectmenu.js

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,7 @@ $.widget("ui.selectmenu", {
718718
if ( typeof( index ) == 'undefined' ) {
719719
this._setOption( 'disabled', true );
720720
} else {
721-
if ( type == "optgroup" ) {
722-
this._toggleOptgroup( index, false );
723-
} else {
724-
this._toggleOption( index, false );
725-
}
721+
this._toggleEnabled( ( type || "option" ), index, false );
726722
}
727723
},
728724

@@ -731,47 +727,32 @@ $.widget("ui.selectmenu", {
731727
if ( typeof( index ) == 'undefined' ) {
732728
this._setOption( 'disabled', false );
733729
} else {
734-
if ( type == "optgroup" ) {
735-
this._toggleOptgroup( index, true );
736-
} else {
737-
this._toggleOption( index, true );
738-
}
730+
this._toggleEnabled( ( type || "option" ), index, true );
739731
}
740732
},
741733

742734
_disabled: function( elem ) {
743735
return $( elem ).hasClass( 'ui-state-disabled' );
744736
},
745-
746-
_toggleOption: function( index, flag ) {
747-
var optionElem = this._optionLis.eq( index );
748-
if ( optionElem ) {
749-
optionElem
750-
.toggleClass( 'ui-state-disabled', !flag )
751-
.find( "a" ).attr( "aria-disabled", flag );
737+
738+
// true = enabled, false = disabled
739+
_toggleEnabled: function( type, index, flag ) {
740+
var element = this.element.find( type ).eq( index ),
741+
elements = ( type === "optgroup" ) ? this.list.find( 'li.ui-selectmenu-group-' + index ) : this._optionLis.eq( index );
742+
743+
if ( elements ) {
744+
elements
745+
.toggleClass( 'ui-state-disabled', !flag )
746+
.attr( "aria-disabled", flag );
747+
752748
if ( flag ) {
753-
this.element.find( "option" ).eq( index ).removeAttr( "disabled" );
749+
element.removeAttr( "disabled" );
754750
} else {
755-
this.element.find( "option" ).eq( index ).attr( "disabled", "disabled" );
751+
element.attr( "disabled", "disabled" );
756752
}
757753
}
758754
},
759755

760-
// true = enabled, false = disabled
761-
_toggleOptgroup: function( index, flag ) {
762-
var optGroupElem = this.list.find( 'li.ui-selectmenu-group-' + index );
763-
if ( optGroupElem ) {
764-
optGroupElem
765-
.toggleClass( 'ui-state-disabled', !flag )
766-
.attr( "aria-disabled", flag );
767-
if ( flag ) {
768-
this.element.find( "optgroup" ).eq( index ).removeAttr( "disabled" );
769-
} else {
770-
this.element.find( "optgroup" ).eq( index ).attr( "disabled", "disabled" );
771-
}
772-
}
773-
},
774-
775756
index: function( newIndex ) {
776757
if ( arguments.length ) {
777758
if ( !this._disabled( $( this._optionLis[ newIndex ] ) ) && newIndex != this._selectedIndex() ) {

0 commit comments

Comments
 (0)