mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Fix #14164: assign className in addClass/removeClass only if changed. Close gh-1331. (cherry-picked from c418b94eb4
)
This commit is contained in:
parent
49670c5f48
commit
7dfe0ad191
@ -8,7 +8,7 @@ var rclass = /[\t\r\n\f]/g;
|
|||||||
|
|
||||||
jQuery.fn.extend({
|
jQuery.fn.extend({
|
||||||
addClass: function( value ) {
|
addClass: function( value ) {
|
||||||
var classes, elem, cur, clazz, j,
|
var classes, elem, cur, clazz, j, finalValue,
|
||||||
i = 0,
|
i = 0,
|
||||||
len = this.length,
|
len = this.length,
|
||||||
proceed = typeof value === "string" && value;
|
proceed = typeof value === "string" && value;
|
||||||
@ -37,8 +37,12 @@ jQuery.fn.extend({
|
|||||||
cur += clazz + " ";
|
cur += clazz + " ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elem.className = jQuery.trim( cur );
|
|
||||||
|
|
||||||
|
// only assign if different to avoid unneeded rendering.
|
||||||
|
finalValue = jQuery.trim( cur );
|
||||||
|
if ( elem.className !== finalValue ) {
|
||||||
|
elem.className = finalValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +51,7 @@ jQuery.fn.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeClass: function( value ) {
|
removeClass: function( value ) {
|
||||||
var classes, elem, cur, clazz, j,
|
var classes, elem, cur, clazz, j, finalValue,
|
||||||
i = 0,
|
i = 0,
|
||||||
len = this.length,
|
len = this.length,
|
||||||
proceed = arguments.length === 0 || typeof value === "string" && value;
|
proceed = arguments.length === 0 || typeof value === "string" && value;
|
||||||
@ -76,7 +80,12 @@ jQuery.fn.extend({
|
|||||||
cur = cur.replace( " " + clazz + " ", " " );
|
cur = cur.replace( " " + clazz + " ", " " );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elem.className = value ? jQuery.trim( cur ) : "";
|
|
||||||
|
// only assign if different to avoid unneeded rendering.
|
||||||
|
finalValue = value ? jQuery.trim( cur ) : "";
|
||||||
|
if ( elem.className !== finalValue ) {
|
||||||
|
elem.className = finalValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user