Re: [Wikitech-l] function drawmap not defined when loading external js with resourceLoader

2018-06-04 Thread Bartosz Dziewoński
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;

--
Bartosz Dziewoński

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

[Wikitech-l] function drawmap not defined when loading external js with resourceLoader

2018-06-04 Thread Tom Schulze

Hello everyone,

I have created a public gist 
 
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

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