Hello everyone,
I have created a public gist https://gist.github.com/tomschulze/afdda960b8c63a3fde0db6cb2ceea0ae with a minimal working example. I am trying to put JavaScript Code from a Widget to an external JS file and load it dynamically with the ResourceLoader. However, the developer console returns the following error: jQuery.Deferred exception: drawmap is not defined when I am accessing the function defined in the external script. Checking the state in the developer console with 'mw.loader.getState("ext.iswiki.display_project_map")' returns: "ready".
When the Resource Loader debug mode is enabled in LocalSettings.php the function is found and called.
What am I doing wrong?
Kind regards,
Tom
Scripts loaded via ResourceLoader are not executed in global scope, so your variables/functions will not be global.
To make them global, you have to explicitly attach them to the `window` object – add this at the end of your external_script.js:
window.drawmap = drawmap;
wikitech-l@lists.wikimedia.org