Posted in Dojo Cookies
List a widget’s events one can connect on
I saw it coming up a couple of times, now that I also needed it, let me share it.
The problem
You have a widget and want to connect, to some event of it. But you don’t know which events are there, what can I connect on and what’s the exact name.
Lets take a dijit.Dialog widget. What do I have to write in my dojo.connect(dialogWidget, “on???”, …) to connect to a certain event?
The solution
Let’s just find out what events the widget has to offer, by finding all methods that the widget has that start with “on”. Hehe pretty simple and basic, but it takes us there!
The following just grabs the first widget on the site that comes along (a dijit.Dialog doh
) and lists all methods that start with “on”. Let’s see. Open your Firebug console and type ahead (or just paste, hehe):
>>> widget = dijit.byNode(dojo.query("[widgetid]")[0]) [Widget dijit.Dialog, inviteDialog] _connects=[3] _attaches=[0] id=overviewInviteDialog >>> for (var i in widget) if (i.indexOf("on")==0) console.log(i) onExecute onCancel onLoad onUnload onDownloadStart onContentError onDownloadError onDownloadEnd onFocus onBlur
Now you can do your dojo.connect() on whatever you think is right.
Tasty, ha?

May 21st, 2008 at 3:37 pm
good idea, what about the next step, which is finding a simple way to know what parameters are sent in each event?
May 22nd, 2008 at 3:22 pm
yaovrubin:
So a couple of ideas spring to mind immediately. First, in Firefox there’s a working “uneval” function which can get you the source code for the function in question. Next, if it’s Dojo-specific class, you could use the dojox.help module to query api.dojotoolkit.org based on the instances’s declaredClass property. Lastly, on every browser you should be able to at least get the “.length” property of the function in question to see how many positional arguments it was declared with.
Regards
May 25th, 2008 at 10:04 pm
Using Firefox 3rc1 the above generates an error for me … anyone else see this? know how to get around it?
>>> >>> widget = dijit.byNode(dojo.query(”[widgetid]“)[0])
commandLine.evaluate FAILS: [Exception... "Security Manager vetoed action" nsresult: "0x80570027 (NS_ERROR_XPC_SECURITY_MANAGER_VETO)" location: "JS frame :: chrome://firebug/content/commandLine.js :: :: line 100" data: no]