Dojo Overview

The dojo package is the foundation package of the Dojo Toolkit. It consists of three main areas:

Each of these areas are detailed in the following sections.

dojo.js

This file provides the bootstrap for loading other modules, in particular the require() function, previously known as dojo.require(). See the loader documentation for further details of how modules are loaded.

For backwards-compatibility, when dojo.js is included without the async: true configuration flag, all the modules in dojo/_base are implicitly loaded.

dojo/_base

The dojo/_base directory contains modules with basic functionality, such as array operations. Typically, if a function or class exists within the dojo namespace directly (e.g. dojo.forEach()) then it is defined in dojo/_base.

However, note that the modules in dojo/_base are being phased out in favor of top level modules in the dojo/ directory. The dojo/_base files will be maintained until the 2.0 release. See details below for replacement modules.

  • dojo/_base - Overview of all the dojo/_base modules.

Configuring Dojo (dojo/_base/config)

Array Utilities (dojo/_base/array)

See Arrays and Dojo for details on dojo's array methods:

  • forEach() - Invokes a callback function for every item in array
  • map() - Applies a callback to each element of arr and returns an Array with the results
  • some() - Iterate over an array, escaping when the callback returns true for some logic check.
  • every() - Iterate over an array, escaping when the callback returns false for some logic check.
  • filter() - Iterate over an array, reducing the array based on the callback return.
  • indexOf() - Find the index of some element in an Array.

See also the NodeList array methods:

  • NodeList.indexOf, NodeList.lastIndexOf, NodeList.forEach, NodeList.every, NodeList.some, NodeList.concat, NodeList.map, NodeList.filter, NodeList.at

Language Utilities (dojo/_base/lang)

  • hitch()

    Function that generates a wrapper function that ensures a function that will only ever execute in a defined scope.

  • partial()

    Function that generates a wrapper function that ensures a function will only ever execute globally.

  • clone()

    Clones objects (including DOM nodes) and all children.

  • delegate()

    Returns a new object which "looks" to obj for properties which it does not have a value for.

  • trim()

    Trim whitespace from a String

  • replace()

    Simple templates with parameterized substitutions.

  • mixin()

    Mixes one object into another. Can be used as a shallow copy

  • extend()

    Extends an object.

  • getObject()

    Get a property from a dot-separated string, such as A.B.C

  • setObject()

    Set a property from a dot-separated string, such as A.B.C

  • exists()

    Determine if an object supports a given method

The following features are deprecated and will be removed in Dojo 2.0. See Testing Object Types for alternatives:

HTML Utilities (dojo/_base/html) - Deprecated

The dojo/_base/html module contains basic DOM & HTML handling functions for backward compatibility purposes.

New code should use the dojo/dom* modules instead.

Deferred Utilities (dojo/_base/Deferred) - Deprecated

This has been deprecated in lieu of dojo/Deferred, dojo/when and dojo/promise. New code should use these modules instead.

  • dojo/_base/Deferred

    Communication between asynchronous calls

    • when()

      Allows a single code path for synchronous and asynchronous code execution.

    • promise

      Deferred objects also have a promise property that provides a read-only view of the result of the operation. This provides a safe robust object that can be passed to other functions without worry of the Deferred being mutated or improperly resolved against expectations.

Kernel (dojo/_base/kernel)

  • dojo/_base/kernel

    From 1.7+ dojo/_base/kernel module contains the following parts of Dojo API:

    • deprecated()

      Log a debug message to indicate that a behavior has been deprecated

    • eval()

      Evaluate some string of JavaScript

    • global

      An alias to the global scope.

    • locale

      A string containing the current locale as defined by Dojo.

    • dojo.moduleUrl

      Deprecated Returns a URL relative to a module. Use require.toUrl() instead.

    • version

      The current version number of Dojo

Window (dojo/_base/window)

from 1.7 + dojo/_base/window module collects following part of dojo APIs

  • doc

    Alias for the current document.

  • body()

    Return the body element of the document

  • setContext()

    Changes the behavior of many core Dojo functions that deal with namespace and DOM lookup

  • withGlobal()

    Call callback with globalObject as global and globalObject.document as dojo.doc

  • withDoc()

    Call callback with documentObject as dojo.doc

Effects (dojo/_base/fx)

Connect (dojo/_base/connect)

This module provides event handling for DOM nodes, and AOP for functions. However, it is superseded by the dojo/on, dojo/aspect, and dojo/topic modules, which should be used for new code.

The methods defined in this module are:

NodeList (dojo/_base/NodeList)

  • NodeList.connect()

    Connects events to every node in the list, like dojo/_base/connect::connect().

  • NodeList.events

    Common event names mapped as functions on a NodeList - (e.g. .onclick(function(){}))

Event (dojo/_base/event)

The dojo/_base/event module defines dojo DOM event API. See the dojo/_base/connect section above.

Document Lifecycle - Unload (dojo/_base/unload)

AJAX/XHR (dojo/_base/xhr) - Deprecated

Package System (dojo/_base/loader)

This module is defining deprecated symbols for loading. See the loader documentation for details on new replacement API's.

JSON (dojo/_base/json) - Deprecated

This has been moved deprecated in lieu of dojo/json.

Objects / OO Utilities (dojo/_base/declare)

Colors (dojo/_base/Color)

  • dojo._base.Color

    Color object and utility functions to handle colors. Defines the following API functions:

    • dojo/_base/Color::fromArray()
    • dojo/_base/Color::fromHex()
    • dojo/_base/Color::fromString()
    • dojo/_base/Color::fromRgb()

Miscellaneous Base

  • dojo/browser

    This module causes the browser-only base modules to be loaded.

  • dojo.keys

    A collection of key constants.

  • dojo._Url

    dojo._Url is used to manage the url object.

  • dojo/sniff

    dojo/sniff is introduced in dojo 1.8 as the browser detection utility.

Dojo Core

While using the legacy API, many of the modules listed here are auto-loaded and made available in the global scope for Legacy compatibility purposes, it is not advisable. The best practice is to require in only the modules you need to use within your application. For example, previously, if you need to retrieve a DOM node by its ID, you might have accomplished this by just accessing the dojo global scope object like:

var myNode = dojo.byId("myNode");

But to ensure the current best practices from Dojo 1.7 onwards, you should do the following:

require("dojo/dom", function(dom){
  var myNode = dom.byId("myNode");
});

DOM (dojo/dom*)

The following modules define the core DOM API for the Dojo Toolkit. For compatibility purposes, aliases to the Legacy API are defined in dojo/_base/html and dojo/_base/xhr modules. For new development it is recommended to require only the individual modules of the parts of the API that are needed and to reference them via their return variable. See each module for examples of what the common conventions are for doing this.

DOM Core (dojo/dom)

This module defines the core dojo DOM API. The convention for the return variable for this module is dom.

Manipulation (dojo/dom-construct)

This module defines the core dojo DOM construction API. The convention for the return variable for this module is domConstruct.

  • toDom()

    Instantiates an HTML fragment returning the corresponding DOM.

  • create()

    Creates a DOM node with optional values and placement

  • place()

    Place DOM nodes relative to others

  • destroy()

    Destroy a DOM node

  • empty()

    Empty the contents of a DOM node

Attributes (dojo/dom-attr)

This module defines the core Dojo DOM attributes API. This module will be retired in the future and superseded by dojo/dom-prop. The convention for the return variable for this module is domAttr.

  • get()

    Gets an attribute on an HTML element.

  • set()

    Sets an attribute on an HTML element.

  • has()

    Returns true if the requested attribute is specified on the given element, and false otherwise.

  • remove()

    Removes an attribute from an HTML element.

  • getNodeProp()

    Returns an effective value of a property or an attribute.

Form (dojo/dom-form)

This module defines form-processing functions. The convention for the return variable for this module is domForm.

  • fieldToObject()

    Serialize a form field to a JavaScript object.

  • toJson()

    Create an object from an form node

  • formToObject()

    Serialize a form node to a JavaScript object.

  • toQuery()

    Returns a URL-encoded string representing the form passed as either a node or string ID identifying the form to serialize.

Styles (dojo/dom-style)

This module defines the core dojo DOM style API. The convention for the return variable for this module is domStyle or style.

  • getComputedStyle()

    Return a cacheable object of all computed styles for a node

  • get()

    Accesses styles on a node.

  • set()

    Sets styles on a node.

Class (dojo/dom-class)

This module defines the core Dojo DOM class API. The convention for the return variable for this module is domClass.

  • contains()

    Returns a boolean depending on whether or not a node has a passed class string.

  • add()

    Adds a CSS class to a node.

  • remove()

    Removes a class from a Node.

  • toggle()

    Toggles a className or an array of classNames.

  • replace()

    Replaces one or more classes on a node if not present. Operates more quickly than calling dojo/dom-class::remove() and dojo/dom-class::add().

Geometry (dojo/dom-geometry)

This module defines the core dojo DOM geometry API. The convention for the return variable for this module is domGeom.

  • dojo.coords

    Getter for the coordinates (relative to parent and absolute) of a DOM node. Deprecated in Dojo 1.4.

  • dojo.position

    Getter for the border-box x/y coordinates and size of a DOM node.

  • dojo.marginBox

    Getter/setter for the margin-box of node

  • dojo.contentBox

    Getter/setter for the content-box of node

  • dojo.getMarginBox

    Get an object that encodes the width, height, left and top positions of the node's margin box.

  • dojo.setMarginBox

    Sets the size of the node's margin box and placement (left/top), irrespective of box model.

  • dojo.getContentBox

    Get an object that encodes the width, height, left and top positions of the node's content box, irrespective of the current box model.

  • dojo.setContentSize

    Sets the size of the node's contents, irrespective of margins, padding, or borders.

Property (dojo/dom-prop)

This module defines the core Dojo DOM properties API. The convention for the return variable for this module is domProp.

  • get()

    Gets a property on an HTML element.

  • set()

    Sets a property on an HTML element.

IO-Query (dojo/io-query)

  • objectToQuery()

    Takes a name/value mapping object and returns a string representing a URL-encoded version of that object.

  • queryToObject()

    Create an object representing a de-serialized query section of a URL. Query keys with multiple values are returned in an array.

Robot (dojo/robot - dojo/robotx)

  • dojo/robot

    Users who use D.O.H. plus Dojo get the added convenience of dojo.mouseMoveAt instead of computing the absolute coordinates of their elements themselves.

    Loads an external app into an iframe and points dojo.doc to the iframe document, allowing the robot to control it.

Document Lifecycle - Onload (dojo/ready)

  • ready()

    Call functions after the DOM has finished loading and widgets declared in markup have been instantiated. When using AMD, in most situations the loader plugin dojo/domReady is preferable.

Deferred and Promises (dojo/Deferred, dojo/promise/*, dojo/when)

  • dojo/Deferred

    The main class for managing asynchronous threads.

  • dojo/promise

    The package that is the foundation for asynchronous thread management in Dojo.

  • dojo/when

    Provides transparent application of callbacks to promises or other arbitrary values.

AJAX Requests (dojo/request)

  • dojo/request

    The base module of the package that will return the default request provider based upon the current platform.

    The plugin loader that returns the default provider.

    The default provider for browser based platforms that provides a cross browser compatible XmlHttpRequest.

    The default provider for node based platforms that provides an asynchronous node request.

    The iframe provider, that uses a browser iframe to manage the communication.

    The script provider that expects a <script> tag to embed the request payload.

    Contains the payload handlers for requests and also provides the ability to register additional content handlers.

    Publishes the dojo/request topics.

    Provides the ability to watch inflight requests.

    Allows for the mapping of providers by URI.

AJAX I/O transports (dojo/io/*) - Deprecated

AJAX RPC transports (dojo/rpc/*)

Query (dojo/query)

  • query()

    The swiss army knife of DOM node manipulation in Dojo.

Selectors (dojo/selector/*)

The different selector engines that are available in Dojo.

  • dojo/selector/_loader STUB

    This module handles loading the appropriate selector engine for the given browser

  • dojo/selector/acme STUB

    This is the default selector engine for Dojo.

  • dojo/selector/lite STUB

    A small lightweight query selector engine that implements CSS2.1 selectors minus pseudo-classes and the sibling combinator, plus CSS3 attribute selectors.

NodeList (dojo/NodeList-*)

Various modules that wrap DOM nodes and provide enhanced functionality and management.

Browser History (dojo/back - dojo/hash)

  • dojo.back (dojo/back)

    Browser history management resources (Back button functionality)

  • dojo.hash (dojo/hash)

    Normalized onhashchange module

JSON (dojo/json)

  • parse()

    Converts a JSON string into a JavaScript object

  • stringify()

    Converts a JavaScript object into a JSON string

Store (dojo/store)

Cache (dojo/cache)

  • dojo.cache

    A mechanism to cache inline text. This has been deprecated in 1.7 in lieu of the dojo/text AMD loader plugin.

Date (dojo/date)

AMD Loader Plugins

There are several modules that are plugins for the AMD Loader system. Consult the Loader documentation for more information on AMD Loader Plugins.

  • dojo/domReady

    Defers execution of the module's factory function until the DOM is ready.

  • dojo/text

    Loads text resources; it is a superset of RequireJS's text plugin, and subsumes dojo.cache.

  • dojo/i18n

    Loads i18n bundles either in legacy or AMD format. It includes the legacy i18n API and is a superset of RequireJS's i18n plugin.

  • dojo/has

    Allows has.js expressions to be used to conditionally load modules.

  • dojo/load

    A convenience plugin for loading dependencies computed at runtime.

  • dojo/require

    Downloads a legacy module without loading it. This allows the legacy code path to be guaranteed.

  • dojo/loadInit

    Causes dojo.loadInit callbacks then other legacy API functions to be executed--in particular those that are associated with a module.

Miscellaneous Core

  • dojo.AdapterRegistry

    A registry to make contextual calling/searching easier

  • dojo.behavior

    Utility for unobtrusive/progressive event binding, DOM traversal, and manipulation

  • dojo.Stateful

    Get and set named properties in conjunction with the ability to monitor these properties for changes

  • dojo.aspect

    Provides aspect oriented programming facilities to attach additional functionality to existing methods

  • dojo.cldr

    A Common Locale Data Repository (CLDR) implementation

  • dojo.colors

    CSS color manipulation functions

  • dojo.cookie

    Simple HTTP cookie manipulation

  • dojo.currency

    Localized formatting and parsing routines for currency data

  • dojo.DeferredList

    Deprecated Event handling for a group of Deferred objects. Use dojo/promise/all instead.

  • dojo.fx

    Effects library on top of Base animations

  • dojo.gears

    Google Gears

  • dojo.html

    Inserting contents in HTML nodes

  • dojo.i18n

    Utility classes to enable loading of resources for internationalization

  • dojo.number

    Localized formatting and parsing methods for number data

  • dojo.parser

    The DOM/Widget parsing package

  • dojo.regexp

    Regular expressions and Builder resources

  • dojo.string

    String utilities for Dojo

  • dojo.mouse

    Provides extension events for hovering and mouse button utility functions

  • dojo/on

    Provides normalized event listening and event dispatching functionality

  • dojo/touch

    Provides standardized touch events

  • dojo.require

    Loads a Dojo module, by name

See also

  • Dijit

    The widget system layered on top of Dojo

  • DojoX

    An area for development of extensions to the Dojo toolkit