Permalink
Browse files

Attributes: removeClass() -> attr("class", "")

- Classes simpliciation

Close gh-2465

(cherry picked from commit 5db1e05)

Conflicts:
	src/attributes/classes.js
  • Loading branch information...
mr21 authored and gibson042 committed Oct 11, 2015
1 parent c003cd6 commit f5328b6a447f23fd8fb9465db36b6eb46e9d8ba6
Showing with 22 additions and 24 deletions.
  1. +22 −24 src/attributes/classes.js
View
@@ -13,23 +13,18 @@ function getClass( elem ) {
jQuery.fn.extend( {
addClass: function( value ) {
var classes, elem, cur, curValue, clazz, j, finalValue,
i = 0,
len = this.length,
proceed = typeof value === "string" && value;
i = 0;
if ( jQuery.isFunction( value ) ) {
return this.each( function( j ) {
jQuery( this ).addClass( value.call( this, j, getClass( this ) ) );
} );
}
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,
i = 0,
len = this.length,
proceed = arguments.length === 0 || typeof value === "string" && value;
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)
@@ -86,8 +83,8 @@ jQuery.fn.extend( {
}
}
// only assign if different to avoid unneeded rendering.
finalValue = value ? jQuery.trim( cur ) : "";
// Only assign if different to avoid unneeded rendering.
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;

0 comments on commit f5328b6

Please sign in to comment.