From 50bf17c977f5aef979ae877881be69a4f57aad8a Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Sun, 26 Apr 2026 14:32:18 +0200 Subject: [PATCH] Convert require to import: timeslider (dynamic), vendors/jquery - Convert dynamic requires to dynamic imports for circular dependency handling - Make timeslider.init async to support dynamic imports - Update exports references to use module scope or window - Add ESM export default for jquery library - Keep CommonJS compatibility for jquery Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/static/js/timeslider.ts | 22 ++++++++++------------ src/static/js/vendors/jquery.ts | 2 ++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/static/js/timeslider.ts b/src/static/js/timeslider.ts index 93497e038..b16eb45b2 100644 --- a/src/static/js/timeslider.ts +++ b/src/static/js/timeslider.ts @@ -88,7 +88,7 @@ const init = () => { Cookies.set(`${cp}token`, token, {expires: 60}); } - socket = socketio.connect(exports.baseURL, '/', {query: {padId}}); + socket = socketio.connect(baseURL, '/', {query: {padId}}); // send the ready message once we're connected socket.on('connect', () => { @@ -120,8 +120,8 @@ const init = () => { window.location.reload(); }); - exports.socket = socket; // make the socket available - exports.BroadcastSlider = BroadcastSlider; // Make the slider available + window.socket = socket; // make the socket available + window.BroadcastSlider = BroadcastSlider; // Make the slider available hooks.aCallAll('postTimesliderInit'); }); @@ -141,7 +141,7 @@ const sendSocketMsg = (type, data) => { const fireWhenAllScriptsAreLoaded = []; -const handleClientVars = (message) => { +const handleClientVars = async (message) => { // save the client Vars window.clientVars = message.data; cp = (window as any).clientVars?.cookiePrefix || ''; @@ -160,16 +160,14 @@ const handleClientVars = (message) => { }) } - // load all script that doesn't work without the clientVars - BroadcastSlider = require('./broadcast_slider') - .loadBroadcastSliderJS(fireWhenAllScriptsAreLoaded); + // load all script that doesn't work without the clientVars + BroadcastSlider = (await import('./broadcast_slider.js')).loadBroadcastSliderJS(fireWhenAllScriptsAreLoaded); - require('./broadcast_revisions').loadBroadcastRevisionsJS(); - changesetLoader = require('./broadcast') - .loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, BroadcastSlider); + (await import('./broadcast_revisions.js')).loadBroadcastRevisionsJS(); + changesetLoader = (await import('./broadcast.js')).loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, BroadcastSlider); - // initialize export ui - require('./pad_impexp').padimpexp.init(); + // initialize export ui + (await import('./pad_impexp.js')).padimpexp.init(); // Create a base URI used for timeslider exports const baseURI = document.location.pathname; diff --git a/src/static/js/vendors/jquery.ts b/src/static/js/vendors/jquery.ts index 1b9923a62..8dfc6b84d 100644 --- a/src/static/js/vendors/jquery.ts +++ b/src/static/js/vendors/jquery.ts @@ -10711,3 +10711,5 @@ } return jQuery; } ); + +export default (typeof window !== "undefined" && typeof window.$ === "object" ? window.$ : null);