On 2014-09-16 3:00 PM, Jack Phoenix wrote:
> Hi all,
>
> Now, the actual issue is that no matter what I do, I get a "TypeError:
> 'LightBox' is not defined" on Poll: pages (such as [4]). In the git master
> version, this is due to the aforementioned race condition: line 466 of
> Poll.js tries to use mw.loader.load() to load the LightBox RL module if
> it's not already loaded, but in RL's production mode this fails, because,
> as I've been told by those with more intimate knowledge of ResourceLoader
> and its inner workings, mw.loader.load is asynchronous. I've tried
> mw.loader.using, but it doesn't seem to do anything as far as fixing the
> issue goes.
Loading a script that's not in the page is inherently going to be an
async thing. You're going to have to write your code to work async.

When you use mw.loader.using to load something in a script always use
the callback to wait till the script is actually loaded. It can safely
be called when something is already in the page, so just drop the
`typeof LightBox == undefined` (this is the wrong way to write a typeof
anyways) and do anything with the lightbox in the callback.

mw.loader.using( 'ext.pollNY.lightBox', function() {
        LightBox.init();
} );

((Any other code using LightBox.* should probably do the same thing,
athough mw.loader.using is using jQuery's "promises" (I really want to
call this something else, since jQuery doesn't implement proper
promises) incorrectly so I'm not sure how well that will work))

~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://danielfriesen.name/]

_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to