PromoCursed/node_modules/rc-util/es/Dom/class.js
2024-08-20 23:25:37 +04:00

26 lines
776 B
JavaScript

export function hasClass(node, className) {
if (node.classList) {
return node.classList.contains(className);
}
var originClass = node.className;
return " ".concat(originClass, " ").indexOf(" ".concat(className, " ")) > -1;
}
export function addClass(node, className) {
if (node.classList) {
node.classList.add(className);
} else {
if (!hasClass(node, className)) {
node.className = "".concat(node.className, " ").concat(className);
}
}
}
export function removeClass(node, className) {
if (node.classList) {
node.classList.remove(className);
} else {
if (hasClass(node, className)) {
var originClass = node.className;
node.className = " ".concat(originClass, " ").replace(" ".concat(className, " "), ' ');
}
}
}