« MediaWiki:Gadget-inline-js-loader.js » : différence entre les versions

De Wikimedica
(Ajout console.log)
Aucun résumé des modifications
 
(5 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
console.log("Loaded inline-js-loader");
window.inlineJSLoadRetries = 0; // Declared as part of window for global scope.


eJS = function()  
var eJS = function()  
{
{
/* It sometimes happens that gadgets are called before the inlineJS is delcared, making the loading
/* 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. */
fail. In this case, give it another 500ms and do a recursive call to try again. */
Ligne 8 : Ligne 9 :
{
{
setTimeout(eJS, 500);
setTimeout(eJS, 500);
console.log("Loading inline-js-loader failed, tying again in 500ms");
console.log("Loading inline-js-loader failed, trying again in 500ms");
return;
}
/* It also sometimes happen that inlineJS has been declared but the page has not completely been parsed for things to load inline.
In this case, give it half a second and try again a couple times. */
else if(Object.keys(inlineJS).length === 0 && window.inlineJSLoadRetries < 3)
{
window.inlineJSLoadRetries++;
setTimeout(eJS, 500);
console.log("inlineJS is empty, trying again in 500ms");
return;
return;
}
}
Ligne 19 : Ligne 29 :
}
}
eJS();
eJS();
console.log("Loaded inline-js-loader");

Dernière version du 24 octobre 2021 à 20:20

window.inlineJSLoadRetries = 0; // Declared as part of window for global scope.

var 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);
		console.log("Loading inline-js-loader failed, trying again in 500ms");
		return;
	}
	/* It also sometimes happen that inlineJS has been declared but the page has not completely been parsed for things to load inline.
	In this case, give it half a second and try again a couple times. */
	else if(Object.keys(inlineJS).length === 0 && window.inlineJSLoadRetries < 3)
	{
		window.inlineJSLoadRetries++;
		setTimeout(eJS, 500);
		console.log("inlineJS is empty, trying again in 500ms");
		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();

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