]> source.dussan.org Git - jquery-ui.git/commitdiff
All: Use .toggleClass() instead of conditionally using .addClass() and .removeClass...
authorXavi <xavi.rmz@gmail.com>
Sun, 19 Dec 2010 21:52:22 +0000 (16:52 -0500)
committerScott González <scott.gonzalez@gmail.com>
Sun, 19 Dec 2010 21:52:22 +0000 (16:52 -0500)
ui/jquery.ui.accordion.js
ui/jquery.ui.sortable.js
ui/jquery.ui.tabs.js
ui/jquery.ui.widget.js

index 76be0095f5e7d65e4af75503f1f69b24512ca3a3..955030ccca052fcdfd498ad81a7ce6957b363b34 100644 (file)
@@ -187,8 +187,7 @@ $.widget( "ui.accordion", {
                // so we need to add the disabled class to the headers and panels
                if ( key == "disabled" ) {
                        this.headers.add(this.headers.next())
-                               [ value ? "addClass" : "removeClass" ](
-                                       "ui-accordion-disabled ui-state-disabled" );
+                               .toggleClass( "ui-accordion-disabled ui-state-disabled", !!value );
                }
        },
 
index d2d3228ee1447f839b8a9eebac2ddbf6c6c44947..32757d41c4b4c2f0a9eb859f0d68ce62a5405c38 100644 (file)
@@ -77,8 +77,7 @@ $.widget("ui.sortable", $.ui.mouse, {
                if ( key === "disabled" ) {
                        this.options[ key ] = value;
        
-                       this.widget()
-                               [ value ? "addClass" : "removeClass"]( "ui-sortable-disabled" );
+                       this.widget().toggleClass( "ui-sortable-disabled", !!value );
                } else {
                        // Don't call widget base _setOption for disable as it adds ui-state-disabled class
                        $.Widget.prototype._setOption.apply(this, arguments);
index 7d73bf10b30981cf02ce3f9e53c0fa0283e32c9e..13e1c25c88e3bbf90da4ede4fb4aeb6e4ac2640f 100644 (file)
@@ -233,9 +233,7 @@ $.widget( "ui.tabs", {
                        o.selected = this.lis.index( this.lis.filter( ".ui-tabs-selected" ) );
                }
 
-               // update collapsible
-               // TODO: use .toggleClass()
-               this.element[ o.collapsible ? "addClass" : "removeClass" ]( "ui-tabs-collapsible" );
+               this.element.toggleClass( "ui-tabs-collapsible", o.collapsible );
 
                // set or update cookie after init and add/remove respectively
                if ( o.cookie ) {
@@ -244,9 +242,8 @@ $.widget( "ui.tabs", {
 
                // disable tabs
                for ( var i = 0, li; ( li = this.lis[ i ] ); i++ ) {
-                       $( li )[ $.inArray( i, o.disabled ) != -1 &&
-                               // TODO: use .toggleClass()
-                               !$( li ).hasClass( "ui-tabs-selected" ) ? "addClass" : "removeClass" ]( "ui-state-disabled" );
+                       $( li ).toggleClass( "ui-state-disabled",
+                               $.inArray( i, o.disabled ) != -1 && !$( li ).hasClass( "ui-tabs-selected" ) );
                }
 
                // reset cache if switching from cached to not cached
index 0420bc31ae920360dab8afd3bae09562cc669c66..b5fb600d9498adce40b81d5e985c3a4761df69ab 100644 (file)
@@ -212,9 +212,7 @@ $.Widget.prototype = {
 
                if ( key === "disabled" ) {
                        this.widget()
-                               [ value ? "addClass" : "removeClass"](
-                                       this.widgetBaseClass + "-disabled" + " " +
-                                       "ui-state-disabled" )
+                               .toggleClass( this.widgetBaseClass + "-disabled ui-state-disabled", !!value )
                                .attr( "aria-disabled", value );
                }