Dijit API Drive-By

The functions listed in Table 11-4 are too commonly used not to especially call out. They're available as part of Dijit Base and get pulled in whenever you require Dijit resources into the page. You can also fetch them by issuing a dojo.require("dijit.dijit") statement, as they are included in the standard build profile, which you'll read more about in Chapter 16.

Tip

For comprehensive API documentation, visit Dojo's online documentation at http://api.dojotoolkit.org.

Table 11-4. Commonly used Dijit functions

Function/Member

Comment

dijit.registry( )

The registry contains a complete record of all dijits that are on the page and may be used to explicitly iterate through them, to check for the existence of a particular dijit, etc. For example, you could uniformly manipulate every dijit on a page via the dijit.registry.forEach function or you could query the page for a particular type of widget via dijit.registry.byClass (where "class" is in the OOP sense).

dijit.byNode(/* DOM Node */ node)

Given a node, returns the dijit that represents this node.

dijit.getEnclosingWidget(/* DOM Node */ node)

Given a node, returns the dijit whose DOM tree contains this node. This method is especially handy for situations in which you need a quick reference to a dijit via a DOM event. For example, you might use this method to easily find a dijit via the target property of the event object that is associated with a mouse click when a user clicks the mouse on some part of a dijit.

dijit.getViewport( )

Returns the dimensions and scroll position of the viewable area of a browser window—extremely useful for programmatically placing objects on the screen when the exact screen resolution or window size cannot be assumed. Often used in animations.

dijit.byId(/* String */ id)

Looks up a dijit on the page by the id value included in its original dojoType tag or passed in through programmatic creation. This function differs from dojo.byId in that dojo.byId returns a DOM node, whereas this function returns an actual dijit (a Function object).

While these aren't the only API methods you'll want to be aware of, they're some of the most common ones, and they will save you a lot of time if you can remember that they exist.

Get Dojo: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.