All: Use .toggleClass() instead of conditionally using .addClass() and .removeClass(). Fixes #6764 - Use toggleClass instead of [ bool ? 'addClass' : 'removeClass' ].

This commit is contained in:
Xavi 2010-12-19 16:52:22 -05:00 committed by Scott González
parent d6edba5a89
commit 956697bfca
4 changed files with 6 additions and 13 deletions

View File

@ -187,8 +187,7 @@ $.widget( "ui.accordion", {
// so we need to add the disabled class to the headers and panels // so we need to add the disabled class to the headers and panels
if ( key == "disabled" ) { if ( key == "disabled" ) {
this.headers.add(this.headers.next()) this.headers.add(this.headers.next())
[ value ? "addClass" : "removeClass" ]( .toggleClass( "ui-accordion-disabled ui-state-disabled", !!value );
"ui-accordion-disabled ui-state-disabled" );
} }
}, },

View File

@ -77,8 +77,7 @@ $.widget("ui.sortable", $.ui.mouse, {
if ( key === "disabled" ) { if ( key === "disabled" ) {
this.options[ key ] = value; this.options[ key ] = value;
this.widget() this.widget().toggleClass( "ui-sortable-disabled", !!value );
[ value ? "addClass" : "removeClass"]( "ui-sortable-disabled" );
} else { } else {
// Don't call widget base _setOption for disable as it adds ui-state-disabled class // Don't call widget base _setOption for disable as it adds ui-state-disabled class
$.Widget.prototype._setOption.apply(this, arguments); $.Widget.prototype._setOption.apply(this, arguments);

View File

@ -233,9 +233,7 @@ $.widget( "ui.tabs", {
o.selected = this.lis.index( this.lis.filter( ".ui-tabs-selected" ) ); o.selected = this.lis.index( this.lis.filter( ".ui-tabs-selected" ) );
} }
// update collapsible this.element.toggleClass( "ui-tabs-collapsible", o.collapsible );
// TODO: use .toggleClass()
this.element[ o.collapsible ? "addClass" : "removeClass" ]( "ui-tabs-collapsible" );
// set or update cookie after init and add/remove respectively // set or update cookie after init and add/remove respectively
if ( o.cookie ) { if ( o.cookie ) {
@ -244,9 +242,8 @@ $.widget( "ui.tabs", {
// disable tabs // disable tabs
for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) { for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) {
$( li )[ $.inArray( i, o.disabled ) != -1 && $( li ).toggleClass( "ui-state-disabled",
// TODO: use .toggleClass() $.inArray( i, o.disabled ) != -1 && !$( li ).hasClass( "ui-tabs-selected" ) );
!$( li ).hasClass( "ui-tabs-selected" ) ? "addClass" : "removeClass" ]( "ui-state-disabled" );
} }
// reset cache if switching from cached to not cached // reset cache if switching from cached to not cached

View File

@ -212,9 +212,7 @@ $.Widget.prototype = {
if ( key === "disabled" ) { if ( key === "disabled" ) {
this.widget() this.widget()
[ value ? "addClass" : "removeClass"]( .toggleClass( this.widgetBaseClass + "-disabled ui-state-disabled", !!value )
this.widgetBaseClass + "-disabled" + " " +
"ui-state-disabled" )
.attr( "aria-disabled", value ); .attr( "aria-disabled", value );
} }