Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
perf(jqLite): avoid repeated add/removeAttribute in jqLiteRemoveClass
Browse files Browse the repository at this point in the history
Fixes #16078
Closes #16131
  • Loading branch information
jbedard committed Aug 3, 2017
1 parent 3650723 commit 32ee5a5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,15 @@ function jqLiteHasClass(element, selector) {

function jqLiteRemoveClass(element, cssClasses) {
if (cssClasses && element.setAttribute) {
var existingClasses = (' ' + (element.getAttribute('class') || '') + ' ')
.replace(/[\n\t]/g, ' ');

forEach(cssClasses.split(' '), function(cssClass) {
element.setAttribute('class', trim(
(' ' + (element.getAttribute('class') || '') + ' ')
.replace(/[\n\t]/g, ' ')
.replace(' ' + trim(cssClass) + ' ', ' '))
);
cssClass = trim(cssClass);
existingClasses = existingClasses.replace(' ' + cssClass + ' ', ' ');
});

element.setAttribute('class', trim(existingClasses));
}
}

Expand Down

0 comments on commit 32ee5a5

Please sign in to comment.