Hmm… actually, looking at the ResourceLoader code, the makeInlineScript() 
function does not actually queue the script to execute. It only returns a 
properly wrapped, anonymized function as a string.  I still needed to call 
OutputPage->addScript() to make it execute.

DanB

From: Wikitech-l [mailto:wikitech-l-boun...@lists.wikimedia.org] On Behalf Of 
Daniel Barrett
Sent: Wednesday, December 30, 2015 11:03 AM
To: Wikimedia developers
Subject: Re: [Wikitech-l] The right way to inject user-supplied JavaScript?

Kevin Israel writes:
>Since MediaWiki 1.26, all ResourceLoader modules are loaded
>asynchronously, so inline scripts now need to account for the
>possibility they may be executed before the jquery and mediawiki modules
>have loaded.
>
>If you use ResourceLoader::makeInlineScript() to build the HTML script
>element, your JavaScript code will be automatically wrapped in an
>anonymous function and queued for execution once ResourceLoader has
>started up.

Thank you! I have documented your advice at 
https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_%28users%29#Inline_scripts.

DanB
_______________________________________________
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
_______________________________________________
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to