mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-27 03:01:14 +08:00
6503e55277
* refactor(utils-v2): migrate utils * refactor(utils-v2): migrate utils * refactor(utils-v2): migrate utils * refactor(utils): remove * refactor(utils): rename * refactor(utils): move EVENT_CODE to constants * refactor: remove generic
33 lines
704 B
TypeScript
33 lines
704 B
TypeScript
import { isClient } from '@vueuse/core'
|
|
|
|
const globalNodes: HTMLElement[] = []
|
|
let target: HTMLElement = !isClient ? (undefined as any) : document.body
|
|
|
|
export function createGlobalNode(id?: string) {
|
|
const el = document.createElement('div')
|
|
if (id !== undefined) {
|
|
el.setAttribute('id', id)
|
|
}
|
|
|
|
target.appendChild(el)
|
|
globalNodes.push(el)
|
|
|
|
return el
|
|
}
|
|
|
|
export function removeGlobalNode(el: HTMLElement) {
|
|
globalNodes.splice(globalNodes.indexOf(el), 1)
|
|
el.remove()
|
|
}
|
|
|
|
export function changeGlobalNodesTarget(el: HTMLElement) {
|
|
if (el === target) return
|
|
|
|
target = el
|
|
globalNodes.forEach((el) => {
|
|
if (el.contains(target) === false) {
|
|
target.appendChild(el)
|
|
}
|
|
})
|
|
}
|