feat: safe.append and safe.remove
This commit is contained in:
		
							parent
							
								
									df3732fabd
								
							
						
					
					
						commit
						fc055bc1e9
					
				| 
						 | 
					@ -43,12 +43,25 @@ export function useLoading() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    appendLoading() {
 | 
					    appendLoading() {
 | 
				
			||||||
      document.head.appendChild(oStyle)
 | 
					      safe.append(document.head, oStyle)
 | 
				
			||||||
      document.body.appendChild(oDiv)
 | 
					      safe.append(document.body, oDiv)
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    removeLoading() {
 | 
					    removeLoading() {
 | 
				
			||||||
      document.head.removeChild(oStyle)
 | 
					      safe.remove(document.head, oStyle)
 | 
				
			||||||
      document.body.removeChild(oDiv)
 | 
					      safe.remove(document.body, oDiv)
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const safe = {
 | 
				
			||||||
 | 
					  append(parent: HTMLElement, child: HTMLElement) {
 | 
				
			||||||
 | 
					    if (!Array.from(parent.children).find(e => e === child)) {
 | 
				
			||||||
 | 
					      return parent.appendChild(child)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  remove(parent: HTMLElement, child: HTMLElement) {
 | 
				
			||||||
 | 
					    if (Array.from(parent.children).find(e => e === child)) {
 | 
				
			||||||
 | 
					      return parent.removeChild(child)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue