File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 22 * SimpleToast - A small library for toasts
33 */
44( ( ) => {
5- const version = buildVersion ( 1 , 2 ) ;
5+ const version = buildVersion ( 1 , 3 ) ;
66 if ( window . SimpleToast ) {
77 if ( SimpleToast . version ) {
88 if ( SimpleToast . version >= version . number ) return ;
6868 }
6969
7070 const toasts = new Map ( ) ;
71- const root = ( ( ) => {
71+ let root = ( ( ) => {
7272 function create ( ) {
7373 const el = document . createElement ( 'div' ) ;
7474 el . setAttribute ( 'id' , 'AlertToast' ) ;
7979 body . appendChild ( el ) ;
8080 } else {
8181 window . addEventListener ( 'load' , ( ) => {
82- if ( document . getElementById ( el . id ) ) return ; // Another script may have created it already
82+ const exists = document . getElementById ( el . id ) ;
83+ if ( exists ) { // Another script may have created it already
84+ if ( el . hasChildNodes ( ) ) { // Transfer existing nodes to new root
85+ const nodes = el . childNodes ;
86+ for ( let i = 0 , l = nodes . length ; i < l ; i ++ ) {
87+ exists . appendChild ( nodes [ i ] ) ;
88+ }
89+ }
90+ root = exists ; // Set this incase anyone still has a reference to this toast
91+ return ;
92+ }
8393 document . getElementsByTagName ( 'body' ) [ 0 ] . appendChild ( el ) ;
8494 } ) ;
8595 }
You can’t perform that action at this time.
0 commit comments