aboutsummaryrefslogtreecommitdiffstats
path: root/src/attributes
diff options
context:
space:
mode:
authorThomas Tortorini <thomastortorini@gmail.com>2015-10-11 10:22:06 +0200
committerTimmy Willison <timmywillisn@gmail.com>2015-10-18 12:46:34 -0400
commit5db1e053098af747330044d5740e5379f2834402 (patch)
tree883f9f1b161007bddcdda05082aa94de5b0f1177 /src/attributes
parent4bf1a09522955eb52de1fafb4ee1ecc5982b7a3e (diff)
downloadjquery-5db1e053098af747330044d5740e5379f2834402.tar.gz
jquery-5db1e053098af747330044d5740e5379f2834402.zip
Attributes: removeClass() -> attr("class", "")
- Classes simpliciation Close gh-2465
Diffstat (limited to 'src/attributes')
-rw-r--r--src/attributes/classes.js44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/attributes/classes.js b/src/attributes/classes.js
index 4a6ea3b2e..6ab6f6efa 100644
--- a/src/attributes/classes.js
+++ b/src/attributes/classes.js
@@ -13,9 +13,7 @@ function getClass( elem ) {
jQuery.fn.extend( {
addClass: function( value ) {
var classes, elem, cur, curValue, clazz, j, finalValue,
- proceed = typeof value === "string" && value,
- i = 0,
- len = this.length;
+ i = 0;
if ( jQuery.isFunction( value ) ) {
return this.each( function( j ) {
@@ -23,13 +21,10 @@ jQuery.fn.extend( {
} );
}
- if ( proceed ) {
+ if ( typeof value === "string" && value ) {
+ classes = value.match( rnotwhite ) || [];
- // The disjunction here is for better compressibility (see removeClass)
- classes = ( value || "" ).match( rnotwhite ) || [];
-
- for ( ; i < len; i++ ) {
- elem = this[ i ];
+ while ( ( elem = this[ i++ ] ) ) {
curValue = getClass( elem );
cur = elem.nodeType === 1 &&
( " " + curValue + " " ).replace( rclass, " " );
@@ -56,20 +51,22 @@ jQuery.fn.extend( {
removeClass: function( value ) {
var classes, elem, cur, curValue, clazz, j, finalValue,
- proceed = arguments.length === 0 || typeof value === "string" && value,
- i = 0,
- len = this.length;
+ i = 0;
if ( jQuery.isFunction( value ) ) {
return this.each( function( j ) {
jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
} );
}
- if ( proceed ) {
- classes = ( value || "" ).match( rnotwhite ) || [];
- for ( ; i < len; i++ ) {
- elem = this[ i ];
+ if ( !arguments.length ) {
+ return this.attr( "class", "" );
+ }
+
+ if ( typeof value === "string" && value ) {
+ classes = value.match( rnotwhite ) || [];
+
+ while ( ( elem = this[ i++ ] ) ) {
curValue = getClass( elem );
// This expression is here for better compressibility (see addClass)
@@ -87,7 +84,7 @@ jQuery.fn.extend( {
}
// Only assign if different to avoid unneeded rendering.
- finalValue = value ? jQuery.trim( cur ) : "";
+ finalValue = jQuery.trim( cur );
if ( curValue !== finalValue ) {
elem.setAttribute( "class", finalValue );
}
@@ -125,12 +122,13 @@ jQuery.fn.extend( {
},
hasClass: function( selector ) {
- var className = " " + selector + " ",
- i = 0,
- l = this.length;
- for ( ; i < l; i++ ) {
- if ( this[ i ].nodeType === 1 &&
- ( " " + getClass( this[ i ] ) + " " ).replace( rclass, " " )
+ var className, elem,
+ i = 0;
+
+ className = " " + selector + " ";
+ while ( ( elem = this[ i++ ] ) ) {
+ if ( elem.nodeType === 1 &&
+ ( " " + getClass( elem ) + " " ).replace( rclass, " " )
.indexOf( className ) > -1
) {
return true;