Skip to content

Commit

Permalink
perf(jqLite): avoid repeated add/removeAttribute in jqLiteRemoveClass
Browse files Browse the repository at this point in the history
  • 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.