On Thu, 20 Aug 2015 04:07:57 +0200, Huji Lee huji.huji@gmail.com wrote:
However, if you don't bypass ResourceLoader, the "+" links won't work and an error is thrown reading "SimpleWindow is not defined" (try on my talk page without bypassing RL https://fa.wikipedia.org/wiki/User_talk:Huji). Note that SimpleWindow is defined in morebits.js
When you load a script through ResourceLoader, it's not executed in global context. This means that global variables you define are actually *not global* (they are local to the function your code is wrapped in), unless you explicitly assign them as `window` properties.
The code of the gadget in question actually does it right:
// https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%... var UserMessages = {}; window.UserMessages = UserMessages; // global access
(It would be sufficient to just do `window.UserMessages = {}`, but this is also just as correct.)
morebits doesn't:
// https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%... var SimpleWindow = function( width, height ) { ...
This should be changed to:
window.SimpleWindow = function( width, height ) {
- How come it works when you bypass ResourceLoader? Note that nothing
else has changed recently (including the morebits.js code on that Wiki)
When you use ?debug=true, the global variables are actually global. This is an implementation detail of how debug mode works, and hopefully will be changed to behave like normal mode at some point.
- Is it safe to assume that just by listing ext.gadgets.morebits as a
dependency, morebits will be properly loaded by ResourceLoader?
Yes, just be careful about explicitly allowing access to globals by attaching them to `window`.