« MediaWiki:Gadget-inline-js-loader.js » : différence entre les versions
(Ajout code pour donner plus de temps à la page d'ajouter des éléments à charger à inlineJS) |
(inlineJS est un objet) |
||
Ligne 13 : | Ligne 13 : | ||
/* It also sometimes happen that inlineJS has been declared but the page has not completely been parsed for things to load inline. | /* 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. */ | In this case, give it half a second and try again a couple times. */ | ||
else if(inlineJS.length === 0 && retries < 3) | else if(Object.keys(inlineJS).length === 0 && retries < 3) | ||
{ | { | ||
retries++; | retries++; |
Version du 24 octobre 2021 à 20:16
var eJS = function()
{
var retries = 0;
/* 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 && retries < 3)
{
retries++;
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");