mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
27 lines
806 B
JavaScript
27 lines
806 B
JavaScript
"use strict";
|
|
|
|
exports.__esModule = true;
|
|
exports.default = removeClass;
|
|
|
|
function replaceClassName(origClass, classToRemove) {
|
|
return origClass.replace(new RegExp("(^|\\s)" + classToRemove + "(?:\\s|$)", 'g'), '$1').replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, '');
|
|
}
|
|
/**
|
|
* Removes a CSS class from a given element.
|
|
*
|
|
* @param element the element
|
|
* @param className the CSS class name
|
|
*/
|
|
|
|
|
|
function removeClass(element, className) {
|
|
if (element.classList) {
|
|
element.classList.remove(className);
|
|
} else if (typeof element.className === 'string') {
|
|
element.className = replaceClassName(element.className, className);
|
|
} else {
|
|
element.setAttribute('class', replaceClassName(element.className && element.className.baseVal || '', className));
|
|
}
|
|
}
|
|
|
|
module.exports = exports["default"]; |