From 402bff88988ee9b4613db121418635ab8055e1c9 Mon Sep 17 00:00:00 2001 From: Alex Winkler Date: Tue, 10 Mar 2026 14:35:44 +0100 Subject: [PATCH 1/3] js(core): add missing js files --- javascript/commons/Core.js | 23 +++++++++++++++++++++++ javascript/commons/CoreEnd.js | 5 +++++ javascript/commons/UseStrict.js | 5 +++++ 3 files changed, 33 insertions(+) create mode 100644 javascript/commons/Core.js create mode 100644 javascript/commons/CoreEnd.js create mode 100644 javascript/commons/UseStrict.js diff --git a/javascript/commons/Core.js b/javascript/commons/Core.js new file mode 100644 index 00000000000..ac8daf6c6b1 --- /dev/null +++ b/javascript/commons/Core.js @@ -0,0 +1,23 @@ +/******************************************************************************* + * Template(s): JavaScript Core + * Author(s): FO-nTTaX + * Information: All modules need to have a parameterless init function. The script + * calls this init function in an asynchronous way so a failing module can not + * stop the execution of the rest of the scripts. A slow script will also not + * block execution of other modules. The script does not check for dependencies + * (impossible to do since modules are in different files), so these need to be + * resolved manually. Modules need to register themselves into the core part of + * the liquipedia.core.modules array, so the script can find them. + ******************************************************************************/ +const liquipedia = { }; +liquipedia.core = { + modules: [ ], + init: function() { + liquipedia.core.modules.forEach( ( module ) => { + // Usage of setTimeout to make scripts asynchronous + window.setTimeout( () => { + window.liquipedia[ module ].init(); + }, 0 ); + } ); + } +}; diff --git a/javascript/commons/CoreEnd.js b/javascript/commons/CoreEnd.js new file mode 100644 index 00000000000..742ab3daf86 --- /dev/null +++ b/javascript/commons/CoreEnd.js @@ -0,0 +1,5 @@ +/******************************************************************************* + * Template(s): JavaScript Core + * Author(s): FO-nTTaX + ******************************************************************************/ +liquipedia.core.init(); diff --git a/javascript/commons/UseStrict.js b/javascript/commons/UseStrict.js new file mode 100644 index 00000000000..c1ff221e946 --- /dev/null +++ b/javascript/commons/UseStrict.js @@ -0,0 +1,5 @@ +/******************************************************************************* + * Template(s): JavaScript Strict Mode + * Author(s): FO-nTTaX + ******************************************************************************/ +'use strict'; From d0c07f27f62a0ab96c2f49cf4b2857b7ecf1174c Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Wed, 11 Mar 2026 12:03:39 +0100 Subject: [PATCH 2/3] cleanup main.js --- javascript/Main.js | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/javascript/Main.js b/javascript/Main.js index 5f5c0853d8d..734b9205fac 100644 --- a/javascript/Main.js +++ b/javascript/Main.js @@ -5,6 +5,8 @@ // List of JavaScript modules to include const jsModules = [ + 'UseStrict', + 'Core', 'Analytics', 'BattleRoyale', 'Bracket', @@ -28,7 +30,8 @@ const jsModules = [ 'Selectall', 'Slider', 'SwitchButtons', - 'Tabs' + 'Tabs', + 'CoreEnd' ]; // Dynamically load JavaScript modules @@ -39,13 +42,6 @@ jsModules.forEach( ( module ) => { document.head.appendChild( script ); } ); -// Initialize liquipedia global object -window.liquipedia = window.liquipedia || { - core: { - modules: [] - } -}; - // Mock MediaWiki APIs for testing window.mw = window.mw || { config: { @@ -82,18 +78,3 @@ window.mw = window.mw || { }; } }; - -// Auto-initialize all loaded modules -onload = () => { - liquipedia.core.modules.forEach( ( module ) => { - if ( !liquipedia[ module ] || typeof liquipedia[ module ].init !== 'function' ) { - return; - } - try { - liquipedia[ module ].init(); - } catch ( e ) { - // eslint-disable-next-line no-console - console.error( `Failed to initialize module: ${ module }. Error: ${ e }` ); - } - } ); -}; From fa15a30120b99fa7210d6edc7a385b1afb289748 Mon Sep 17 00:00:00 2001 From: Alex Winkler Date: Wed, 11 Mar 2026 14:11:12 +0100 Subject: [PATCH 3/3] reorder Main.js for load priority --- javascript/Main.js | 74 +++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/javascript/Main.js b/javascript/Main.js index 734b9205fac..60342bce3c2 100644 --- a/javascript/Main.js +++ b/javascript/Main.js @@ -3,6 +3,43 @@ The equivalent to this file on production is Special:RLA, and should be kept in sync with it. */ +// Mock MediaWiki APIs for testing +window.mw = window.mw || { + config: { + get: function ( key ) { + const mockConfig = { + wgPageName: 'Test_Page', + wgNamespaceNumber: 0, + wgServer: 'https://liquipedia.net', + wgScriptPath: '' + }; + return mockConfig[ key ]; + } + }, + user: { + isAnon: function () { + return false; + } + }, + loader: { + using: function () { + return Promise.resolve(); + } + }, + Api: function () { + return { + get: function () { + return Promise.resolve( { + query: { + logevents: [], + pages: {} + } + } ); + } + }; + } +}; + // List of JavaScript modules to include const jsModules = [ 'UseStrict', @@ -41,40 +78,3 @@ jsModules.forEach( ( module ) => { script.async = false; // Ensure scripts load in order document.head.appendChild( script ); } ); - -// Mock MediaWiki APIs for testing -window.mw = window.mw || { - config: { - get: function ( key ) { - const mockConfig = { - wgPageName: 'Test_Page', - wgNamespaceNumber: 0, - wgServer: 'https://liquipedia.net', - wgScriptPath: '' - }; - return mockConfig[ key ]; - } - }, - user: { - isAnon: function () { - return false; - } - }, - loader: { - using: function () { - return Promise.resolve(); - } - }, - Api: function () { - return { - get: function () { - return Promise.resolve( { - query: { - logevents: [], - pages: {} - } - } ); - } - }; - } -};