MediaWiki:Gadget-inline-js-loader.js : Différence entre versions

De Wikimedica
Sauter à la navigation Sauter à la recherche
(Ajouté un mécanisme de vérification de la définition de inlineJS)
Ligne 1 : Ligne 1 :
 
console.log("Loaded inline-js-loader");
 
console.log("Loaded inline-js-loader");
  
for(var n in inlineJS) // Each function to be executed is added to the inlineJS object.
+
eJS = function()  
 
{
 
{
f = inlineJS[n];
+
/* It sometimes happens that gadgets are called before the inlineJS is delcared, making the loading
if(typeof f === 'function' ) { f(); }
+
fail. In this case, give it another 500ms and do a recursive call to try again. */
 +
if(typeof inlineJS == 'undefined')
 +
{
 +
setTimeout(eJS, 500);
 +
return;
 +
}
 +
 +
for(var n in inlineJS) // Each function to be executed is added to the inlineJS object.
 +
{
 +
f = inlineJS[n];
 +
if(typeof f === 'function' ) { f(); }
 +
}
 
}
 
}
 +
eJS();

Version du 8 avril 2020 à 21:52

console.log("Loaded inline-js-loader");

eJS = function() 
{
	/* It sometimes happens that gadgets are called before the inlineJS is delcared, making the loading
	fail. In this case, give it another 500ms and do a recursive call to try again. */
	if(typeof inlineJS == 'undefined')
	{
		setTimeout(eJS, 500);
		return;
	}
	
	for(var n in inlineJS) // Each function to be executed is added to the inlineJS object.
	{
		f = inlineJS[n];
		if(typeof f === 'function' ) { f(); }
	}
}
eJS();