File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed
Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 1-
2-
31/**
42 * https://tobiasahlin.com/spinkit
53 * https://connoratherton.com/loaders
@@ -45,12 +43,25 @@ export function useLoading() {
4543
4644 return {
4745 appendLoading ( ) {
48- document . head . appendChild ( oStyle )
49- document . body . appendChild ( oDiv )
46+ safe . append ( document . head , oStyle )
47+ safe . append ( document . body , oDiv )
5048 } ,
5149 removeLoading ( ) {
52- document . head . removeChild ( oStyle )
53- document . body . removeChild ( oDiv )
50+ safe . remove ( document . head , oStyle )
51+ safe . remove ( document . body , oDiv )
5452 } ,
5553 }
5654}
55+
56+ const safe = {
57+ append ( parent : HTMLElement , child : HTMLElement ) {
58+ if ( ! Array . from ( parent . children ) . find ( e => e === child ) ) {
59+ return parent . appendChild ( child )
60+ }
61+ } ,
62+ remove ( parent : HTMLElement , child : HTMLElement ) {
63+ if ( Array . from ( parent . children ) . find ( e => e === child ) ) {
64+ return parent . removeChild ( child )
65+ }
66+ } ,
67+ }
You can’t perform that action at this time.
0 commit comments