✨ feat: 新增 WYSIWYG 编辑器功能和相关工具栏事件处理
This commit is contained in:
27
web/include/vditor/src/ts/util/hasClosestByHeadings.ts
Normal file
27
web/include/vditor/src/ts/util/hasClosestByHeadings.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// NOTE: 减少 method.ts 打包,故从 hasClosest.ts 中拆分
|
||||
export const hasClosestByTag = (element: Node, nodeName: string) => {
|
||||
if (!element) {
|
||||
return false;
|
||||
}
|
||||
if (element.nodeType === 3) {
|
||||
element = element.parentElement;
|
||||
}
|
||||
let e = element as HTMLElement;
|
||||
let isClosest = false;
|
||||
while (e && !isClosest && !e.classList.contains("vditor-reset")) {
|
||||
if (e.nodeName.indexOf(nodeName) === 0) {
|
||||
isClosest = true;
|
||||
} else {
|
||||
e = e.parentElement;
|
||||
}
|
||||
}
|
||||
return isClosest && e;
|
||||
};
|
||||
|
||||
export const hasClosestByHeadings = (element: Node) => {
|
||||
const headingElement = hasClosestByTag(element, "H");
|
||||
if (headingElement && headingElement.tagName.length === 2 && headingElement.tagName !== "HR") {
|
||||
return headingElement;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Reference in New Issue
Block a user