Skip to content

Commit cd2c147

Browse files
committedMar 16, 2025
Optimization of the fallback matchclass loop
1 parent 3803d3e commit cd2c147

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed
 

‎tarteaucitron.js

+11-20
Original file line numberDiff line numberDiff line change
@@ -2284,28 +2284,19 @@ var tarteaucitron = {
22842284
},
22852285
"fallback": function (matchClass, content, noInner) {
22862286
"use strict";
2287-
var elems = document.getElementsByTagName('*'),
2288-
i,
2289-
index = 0;
2290-
2291-
for (i in elems) {
2292-
if (elems[i] !== undefined) {
2293-
for (index = 0; index < matchClass.length; index += 1) {
2294-
if ((' ' + elems[i].className + ' ')
2295-
.indexOf(' ' + matchClass[index] + ' ') > -1) {
2296-
if (typeof content === 'function') {
2297-
if (noInner === true) {
2298-
content(elems[i]);
2299-
} else {
2300-
elems[i].innerHTML = content(elems[i]);
2301-
}
2302-
} else {
2303-
elems[i].innerHTML = content;
2304-
}
2305-
}
2287+
const selector = matchClass.map(cls => `.${cls}`).join(', ');
2288+
const elems = document.querySelectorAll(selector);
2289+
elems.forEach((elem) => {
2290+
if (typeof content === 'function') {
2291+
if (noInner === true) {
2292+
content(elem);
2293+
} else {
2294+
elem.innerHTML = content(elem);
23062295
}
2296+
} else {
2297+
elem.innerHTML = content;
23072298
}
2308-
}
2299+
});
23092300
},
23102301
"engage": function (id) {
23112302
"use strict";

0 commit comments

Comments
 (0)
Failed to load comments.