mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Attributes: removeClass() -> attr("class", "")
- Classes simpliciation Close gh-2465
This commit is contained in:
parent
4bf1a09522
commit
5db1e05309
@ -13,9 +13,7 @@ function getClass( elem ) {
|
|||||||
jQuery.fn.extend( {
|
jQuery.fn.extend( {
|
||||||
addClass: function( value ) {
|
addClass: function( value ) {
|
||||||
var classes, elem, cur, curValue, clazz, j, finalValue,
|
var classes, elem, cur, curValue, clazz, j, finalValue,
|
||||||
proceed = typeof value === "string" && value,
|
i = 0;
|
||||||
i = 0,
|
|
||||||
len = this.length;
|
|
||||||
|
|
||||||
if ( jQuery.isFunction( value ) ) {
|
if ( jQuery.isFunction( value ) ) {
|
||||||
return this.each( function( j ) {
|
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)
|
while ( ( elem = this[ i++ ] ) ) {
|
||||||
classes = ( value || "" ).match( rnotwhite ) || [];
|
|
||||||
|
|
||||||
for ( ; i < len; i++ ) {
|
|
||||||
elem = this[ i ];
|
|
||||||
curValue = getClass( elem );
|
curValue = getClass( elem );
|
||||||
cur = elem.nodeType === 1 &&
|
cur = elem.nodeType === 1 &&
|
||||||
( " " + curValue + " " ).replace( rclass, " " );
|
( " " + curValue + " " ).replace( rclass, " " );
|
||||||
@ -56,20 +51,22 @@ jQuery.fn.extend( {
|
|||||||
|
|
||||||
removeClass: function( value ) {
|
removeClass: function( value ) {
|
||||||
var classes, elem, cur, curValue, clazz, j, finalValue,
|
var classes, elem, cur, curValue, clazz, j, finalValue,
|
||||||
proceed = arguments.length === 0 || typeof value === "string" && value,
|
i = 0;
|
||||||
i = 0,
|
|
||||||
len = this.length;
|
|
||||||
|
|
||||||
if ( jQuery.isFunction( value ) ) {
|
if ( jQuery.isFunction( value ) ) {
|
||||||
return this.each( function( j ) {
|
return this.each( function( j ) {
|
||||||
jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
|
jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
if ( proceed ) {
|
|
||||||
classes = ( value || "" ).match( rnotwhite ) || [];
|
|
||||||
|
|
||||||
for ( ; i < len; i++ ) {
|
if ( !arguments.length ) {
|
||||||
elem = this[ i ];
|
return this.attr( "class", "" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( typeof value === "string" && value ) {
|
||||||
|
classes = value.match( rnotwhite ) || [];
|
||||||
|
|
||||||
|
while ( ( elem = this[ i++ ] ) ) {
|
||||||
curValue = getClass( elem );
|
curValue = getClass( elem );
|
||||||
|
|
||||||
// This expression is here for better compressibility (see addClass)
|
// This expression is here for better compressibility (see addClass)
|
||||||
@ -87,7 +84,7 @@ jQuery.fn.extend( {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only assign if different to avoid unneeded rendering.
|
// Only assign if different to avoid unneeded rendering.
|
||||||
finalValue = value ? jQuery.trim( cur ) : "";
|
finalValue = jQuery.trim( cur );
|
||||||
if ( curValue !== finalValue ) {
|
if ( curValue !== finalValue ) {
|
||||||
elem.setAttribute( "class", finalValue );
|
elem.setAttribute( "class", finalValue );
|
||||||
}
|
}
|
||||||
@ -125,12 +122,13 @@ jQuery.fn.extend( {
|
|||||||
},
|
},
|
||||||
|
|
||||||
hasClass: function( selector ) {
|
hasClass: function( selector ) {
|
||||||
var className = " " + selector + " ",
|
var className, elem,
|
||||||
i = 0,
|
i = 0;
|
||||||
l = this.length;
|
|
||||||
for ( ; i < l; i++ ) {
|
className = " " + selector + " ";
|
||||||
if ( this[ i ].nodeType === 1 &&
|
while ( ( elem = this[ i++ ] ) ) {
|
||||||
( " " + getClass( this[ i ] ) + " " ).replace( rclass, " " )
|
if ( elem.nodeType === 1 &&
|
||||||
|
( " " + getClass( elem ) + " " ).replace( rclass, " " )
|
||||||
.indexOf( className ) > -1
|
.indexOf( className ) > -1
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user