summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Nagel <info@felixnagel.com>2013-09-07 19:12:09 +0200
committerFelix Nagel <info@felixnagel.com>2013-09-07 19:12:09 +0200
commit1b97e728dcccc23a413ca8059624e0516eda3871 (patch)
treef0c1d9157dfa92841f0f6a918b342bab4ed61e6d
parentd9ad9d064d1410eaf16058e217b161e871732955 (diff)
downloadjquery-ui-1b97e728dcccc23a413ca8059624e0516eda3871.tar.gz
jquery-ui-1b97e728dcccc23a413ca8059624e0516eda3871.zip
improved: rework enable / enable option setting
-rw-r--r--ui/jquery.ui.selectmenu.js49
1 files 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() ) {