mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-21 02:50:11 +08:00
55348b30b6
* style: use prettier * style: just prettier format, no code changes * style: eslint fix object-shorthand, prefer-const * style: fix no-void * style: no-console
35 lines
657 B
TypeScript
35 lines
657 B
TypeScript
import isServer from './isServer'
|
|
|
|
const globalNodes = []
|
|
let target = isServer ? undefined : document.body
|
|
|
|
export function createGlobalNode(id?: string) {
|
|
const el = document.createElement('div')
|
|
|
|
if (id !== undefined) {
|
|
el.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) {
|
|
target = el
|
|
|
|
globalNodes.forEach((el) => {
|
|
if (el.contains(target) === false) {
|
|
target.appendChild(el)
|
|
}
|
|
})
|
|
}
|
|
}
|