Admin Forum:ImportScriptPage

Forums: Admin Central Index → Technical Help → ImportScriptPage Wikia's forums are a place for the community to help other members. To contact staff directly or to report bugs, please use Special:Contact.

I just added a little widget module I wrote to the dev wiki. Looking at the code of other entries I found this mysterious JavaScript function named.

What it's supposed to do is fairly obvious but it just doesn't do it for me. Do I lack the permissions? Is there somebody I need to talk to? Or does the function work but there's a scoping issue? Or a timing issue?

Here's what the code looks like:

importScriptPage('InfoWidgets/code.js', 'dev'); $(function {     if ($('#sandbox').length) {         s = Widgets.stubs;         s.selector = '#sandbox';         Widgets.add(s);         Widgets.start;     } });

I should probably add that the widgets work fine on my own machine - without importScriptPage of course. They even work fine here on our landing page - also without importScriptPage.

But when I try to import from the dev wiki I get the error message "Widgets is not defined".

Pecoes 06:57, February 18, 2012 (UTC)


 * importScriptPage works properly, but when you load a JavaScript file dynamically it's loaded asynchronously. That means the following lines are executed before the included script is parsed and executed by the browser. To solve this you should create a "delegate" function, and call that function from the included script (namely, "fire an event"). --Category:Ciencia Al Poder (talk) -WikiDex 11:17, February 18, 2012 (UTC)


 * That makes a lot of sense!
 * So this is what I got in InfoWidgets/code.js now:
 * So this is what I got in InfoWidgets/code.js now:

$(function {    if ($.isFunction(window.widgetsLoaded)) {        window.widgetsLoaded;        Widgets.start;    } });
 * (I could probably do away with ready here)
 * And this is what I got in MediaWiki:Common.js:

$(function {     if ($('#sandbox').length) {         importScriptPage('InfoWidgets/code.js', 'dev');         window.widgetsLoaded = function  {             s = Widgets.stubs;             s.selector = '#sandbox';             Widgets.add(s);         }     }; }
 * Here's the result: User:Pecoes/sandbox
 * It seems to work fine. Does that look correct to you?
 * Pecoes 13:32, February 18, 2012 (UTC)
 * Pecoes 13:32, February 18, 2012 (UTC)