fix #62 accept RegExp type block class config
This commit is contained in:
18
src/utils.ts
18
src/utils.ts
@@ -3,6 +3,7 @@ import {
|
||||
throttleOptions,
|
||||
listenerHandler,
|
||||
hookResetter,
|
||||
blockClass,
|
||||
} from './types';
|
||||
import { INode } from 'rrweb-snapshot';
|
||||
|
||||
@@ -113,15 +114,22 @@ export function getWindowWidth(): number {
|
||||
);
|
||||
}
|
||||
|
||||
export function isBlocked(node: Node | null, blockClass: string): boolean {
|
||||
export function isBlocked(node: Node | null, blockClass: blockClass): boolean {
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
if (node.nodeType === node.ELEMENT_NODE) {
|
||||
return (
|
||||
(node as HTMLElement).classList.contains(blockClass) ||
|
||||
isBlocked(node.parentNode, blockClass)
|
||||
);
|
||||
let needBlock = false;
|
||||
if (typeof blockClass === 'string') {
|
||||
needBlock = (node as HTMLElement).classList.contains(blockClass);
|
||||
} else {
|
||||
(node as HTMLElement).classList.forEach(className => {
|
||||
if (blockClass.test(className)) {
|
||||
needBlock = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return needBlock || isBlocked(node.parentNode, blockClass);
|
||||
}
|
||||
return isBlocked(node.parentNode, blockClass);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user