@@ -559,9 +559,51 @@ function setupTableEvents(tableId, config) {
559559        //  button created by the developer. For that reason, we move them to the end of the body 
560560        //  ensuring they are re-evaluated on each draw event. 
561561        document .getElementById (tableId).querySelectorAll (' script'  ).forEach (function (script ) { 
562-             const  newScript  =  document .createElement (' script'  ); 
563-             newScript .text  =  script .text ; 
564-             document .body .appendChild (newScript); 
562+             const  scriptsToLoad  =  []; 
563+                     if  (script .src ) { 
564+                         //  For external scripts with src attribute 
565+                         const  srcUrl  =  script .src ; 
566+ 
567+                         //  Only load the script if it's not already loaded 
568+                         if  (! document .querySelector (` script[src="${ srcUrl}  "]`  )) { 
569+                             scriptsToLoad .push (new  Promise ((resolve , reject ) =>  { 
570+                                 const  newScript  =  document .createElement (' script'  ); 
571+ 
572+                                 //  Copy all attributes from the original script 
573+                                 Array .from (script .attributes ).forEach (attr  =>  { 
574+                                     newScript .setAttribute (attr .name , attr .value ); 
575+                                 }); 
576+ 
577+                                 //  Set up load and error handlers 
578+                                 newScript .onload  =  resolve; 
579+                                 newScript .onerror  =  reject; 
580+ 
581+                                 //  Append to document to start loading 
582+                                 document .head .appendChild (newScript); 
583+                             })); 
584+                         } 
585+ 
586+                         //  Remove the original script tag 
587+                         script .parentNode .removeChild (script); 
588+                     } else  { 
589+                         //  For inline scripts 
590+                         const  newScript  =  document .createElement (' script'  ); 
591+ 
592+                         //  Copy all attributes from the original script 
593+                         Array .from (script .attributes ).forEach (attr  =>  { 
594+                             newScript .setAttribute (attr .name , attr .value ); 
595+                         }); 
596+ 
597+                         //  Copy the content 
598+                         newScript .textContent  =  script .textContent ; 
599+ 
600+                         try  { 
601+                             document .head .appendChild (newScript); 
602+                         }catch  (e) { 
603+                             console .warn (' Error appending inline script:'  , e); 
604+                         } 
605+                     } 
606+                  
565607        }); 
566608
567609        //  Run table-specific functions and pass the tableId 
0 commit comments