mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
34 lines
684 B
JavaScript
34 lines
684 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
var cache = {};
|
||
|
var start = '(?:^|\\s)';
|
||
|
var end = '(?:\\s|$)';
|
||
|
|
||
|
function lookupClass (className) {
|
||
|
var cached = cache[className];
|
||
|
if (cached) {
|
||
|
cached.lastIndex = 0;
|
||
|
} else {
|
||
|
cache[className] = cached = new RegExp(start + className + end, 'g');
|
||
|
}
|
||
|
return cached;
|
||
|
}
|
||
|
|
||
|
function addClass (el, className) {
|
||
|
var current = el.className;
|
||
|
if (!current.length) {
|
||
|
el.className = className;
|
||
|
} else if (!lookupClass(className).test(current)) {
|
||
|
el.className += ' ' + className;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function rmClass (el, className) {
|
||
|
el.className = el.className.replace(lookupClass(className), ' ').trim();
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
add: addClass,
|
||
|
rm: rmClass
|
||
|
};
|