@@ -737,57 +737,52 @@ function setupTableEvents(tableId, config) {
737737 try {
738738 const tableElement = document .getElementById (tableId);
739739 if (tableElement) {
740- document .getElementById (tableId).querySelectorAll (' script' ).forEach (function (script ) {
741- const scriptsToLoad = [];
742- if (script .src ) {
743- // For external scripts with src attribute
744- const srcUrl = script .src ;
745-
746- // Only load the script if it's not already loaded
747- if (! document .querySelector (` script[src="${ srcUrl} "]` )) {
748- scriptsToLoad .push (new Promise ((resolve , reject ) => {
749- const newScript = document .createElement (' script' );
750-
751- // Copy all attributes from the original script
752- Array .from (script .attributes ).forEach (attr => {
753- newScript .setAttribute (attr .name , attr .value );
754- });
755-
756- // Set up load and error handlers
757- newScript .onload = resolve;
758- newScript .onerror = reject;
759-
760- // Append to document to start loading
761- try {
762- document .head .appendChild (newScript);
763- } catch (e) {
764- console .warn (' Error appending external script:' , e);
765- reject (e);
766- }
767- }));
768- }
740+ tableElement .querySelectorAll (' script' ).forEach (function (script ) {
741+ if (script .parentNode ) {
742+ script .parentNode .removeChild (script);
743+ }
769744
770- // Remove the original script tag
771- script .parentNode .removeChild (script);
772- } else {
773- // For inline scripts
774- const newScript = document .createElement (' script' );
745+ if (script .src ) {
746+ // For external scripts with src attribute
747+ const srcUrl = script .src ;
775748
776- // Copy all attributes from the original script
777- Array .from (script .attributes ).forEach (attr => {
778- newScript .setAttribute (attr .name , attr .value );
779- });
749+ // Only load the script if it's not already loaded in <head>
750+ if (! document .querySelector (` script[src="${ srcUrl} "]` )) {
751+ const newScript = document .createElement (' script' );
780752
781- // Copy the content
782- newScript .textContent = script .textContent ;
753+ // Copy all attributes from the original script
754+ Array .from (script .attributes ).forEach (attr => {
755+ newScript .setAttribute (attr .name , attr .value );
756+ });
783757
784- try {
785- document .head .appendChild (newScript);
786- }catch (e) {
787- console .warn (' Error appending inline script:' , e);
788- }
758+ newScript .onerror = function (e ) {
759+ console .warn (' Error loading script:' , srcUrl, e);
760+ };
761+
762+ try {
763+ document .head .appendChild (newScript);
764+ } catch (e) {
765+ console .warn (' Error appending external script:' , e);
789766 }
790-
767+ }
768+ } else {
769+ // For inline scripts
770+ const newScript = document .createElement (' script' );
771+
772+ // Copy all attributes from the original script
773+ Array .from (script .attributes ).forEach (attr => {
774+ newScript .setAttribute (attr .name , attr .value );
775+ });
776+
777+ // Copy the content
778+ newScript .textContent = script .textContent ;
779+
780+ try {
781+ document .head .appendChild (newScript);
782+ } catch (e) {
783+ console .warn (' Error appending inline script:' , e);
784+ }
785+ }
791786 });
792787 } else {
793788 console .warn (' Table element not found:' , tableId);
0 commit comments