This commit is contained in:
cookfront
2017-02-16 16:54:15 +08:00
parent 3a1fca4953
commit c45822b400
4 changed files with 21 additions and 5 deletions
+14 -2
View File
@@ -1,4 +1,17 @@
/* istanbul ignore next */
const trim = function(string) {
return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
};
export function hasClass(el, cls) {
if (!el || !cls) return false;
if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.');
if (el.classList) {
return el.classList.contains(cls);
} else {
return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
};
export function addClass(el, cls) {
if (!el) return;
var curClass = el.className;
@@ -21,7 +34,6 @@ export function addClass(el, cls) {
}
};
/* istanbul ignore next */
export function removeClass(el, cls) {
if (!el || !cls) return;
var classes = cls.split(' ');