« MediaWiki:Gadget-inline-js-loader.js » : différence entre les versions
(variable globale) |
Aucun résumé des modifications |
||
Ligne 1 : | Ligne 1 : | ||
window.inlineJSLoadRetries = 0; // Declared as part of window for global scope. | |||
var 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 |
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");