Dojo Overview¶
Contents
The dojo package is the foundation package of the Dojo Toolkit. It consists of three main areas:
- dojo.js - the bootstrap
- dojo/_base - basic functionality historically pulled in as part of dojo.js, and historically existing directly
under the
dojo
namespace - Dojo Core - more advanced functionality, with some of the functionality available in sub-packages (e.g.
dojo/dnd
anddojo/store
)
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)¶
dojoConfig (dojo/_base/config)
Possibility to override certain global settings that control how the framework operates
Array Utilities (dojo/_base/array)¶
Details on dojo.every, dojo.filter, dojo.forEach, dojo.indexOf, dojo.lastIndexOf, dojo.map, and dojo.some. See the Array QuickStart for an overview.
-
STUB Overview of the array module
-
Invokes a callback function for every item in array
-
Applies a callback to each element of arr and returns an Array with the results
-
Iterate over an array, escaping when the callback returns true for some logic check.
-
Iterate over an array, escaping when the callback returns false for some logic check.
-
Iterate over an array, reducing the array based on the callback return.
-
Find the index of some element in an Array.
-
- NodeList.indexOf, NodeList.lastIndexOf, NodeList.forEach, NodeList.every, NodeList.some, NodeList.concat, NodeList.map, NodeList.filter, NodeList.at
Language Utilities (dojo/_base/lang)¶
-
Function that generates a wrapper function that ensures a function that will only ever execute in a defined scope.
-
Function that generates a wrapper function that ensures a function will only ever execute globally.
-
Clones objects (including DOM nodes) and all children.
-
Returns a new object which “looks” to obj for properties which it does not have a value for.
-
Checks if the parameter is a String
-
Checks if the parameter is an Array
-
Checks if the parameter is a Function
-
Checks if the parameter is an Object
-
Checks if the parameter is like an Array
-
Checks if the parameter is a built-in function
-
Trim whitespace from a String
-
Simple templates with parameterized substitutions.
-
Mixes one object into another. Can be used as a shallow copy
-
Get a property from a dot-separated string, such as “A.B.C”
-
Set a property from a dot-separated string, such as “A.B.C”
-
Determine if an object supports a given method
HTML Utilities (dojo/_base/html)¶
The dojo/_base/html module contains basic DOM & HTML handling functions for backward compatibility purposes.
New code should use the dojo/dom* modules (see “Dojo core” section below for details).
Deferred Utilities (dojo/_base/Deferred)¶
-
Communication between asynchronous calls
-
Allows a single code path for synchronous and asynchronous code execution.
-
Kernel (dojo/_base/kernel)¶
-
STUB from 1.7+ dojo/_base/kernel module contains the following parts of Dojo API:
-
Log a debug message to indicate that a behavior has been deprecated
-
Evaluate some string of JavaScript
-
A string containing the current locale as defined by Dojo
-
Returns a URL relative to a module
-
The current version number of Dojo
-
Window (dojo/_base/window)¶
from 1.7 + dojo/_base/window module collects following part of dojo APIs
-
Alias for the current document.
-
Return the body element of the document
-
Changes the behavior of many core Dojo functions that deal with namespace and DOM lookup
-
Call callback with globalObject as dojo.global and globalObject.document as dojo.doc
-
Call callback with documentObject as dojo.doc
Effects (dojo/_base/fx)¶
-
The workhorse of most dojo.fx animations. Used for animating CSS properties
-
1.4+ previously dojo._Animation, the class behind all dojo.fx
-
Shorthand version of animateProperty using positional arguments
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:
-
Connects events to methods
-
Disconnects methods from linked topics
-
Linked a listener to a named topic
-
Remove a topic listener
-
Publish an event to all subscribers of a topic
-
Ensure that every time an event is called, a message is published on the topic.
NodeList (dojo/_base/NodeList)¶
-
Connects events to every node in the list, like dojo.connect
-
Common event names mapped as functions on a NodeList - eg: .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)¶
dojo/_base/unload
STUB functions related to document unloading
-
Call functions when the page unloads
-
Call functions when window.onunload fires
-
Signal fired by impending window destruction
AJAX/XHR (dojo/_base/xhr)¶
-
1.4+ Pre-defined XHR content handlers, and an extension point to add your own custom handling.
-
Core for all xhr* verbs, eg: xhrPost, getGet
Package System (dojo/_base/loader)¶
This module is defining deprecated symbols for loading. See the loader documentation for details on new replacement API’s.
-
STUB module overview
-
Maps module name to a path
-
Loads a Javascript module from the appropriate URI
JSON Tools (dojo/_base/json)¶
-
Parses a JSON string to return a JavaScript object
-
Returns a JSON serialization of an object
Objects / OO Utilities (dojo/_base/declare)¶
dojo.declare (dojo/_base/declare)
Creates a constructor using a compact notation for inheritance and prototype extension
Colors (dojo/_base/Color)¶
-
Color object and utility functions to handle colors. Defines the following API functions:
- dojo.colorFromArray
- dojo.colorFromHex
- dojo.colorFromString
- dojo.colorFromRgb
Miscellaneous Base¶
dojo/browser
This module causes the browser-only base modules to be loaded.
-
Alias for the global scope
-
A collection of key constants.
dojo._Url
dojo._Url is used to manage the url object.
dojo/sniff STUB
dojo/_base/sniff is introduced in dojo 1.7 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
.-
Select a DOM node by ‘id’.
dojo.isDescendant
dojo.setSelectable
-
Manipulation (dojo/dom-construct)
This module defines the core dojo DOM construction API. The convention for the return variable for this module is
domConstruct
.-
Instantiates an HTML fragment returning the corresponding DOM.
-
Creates a DOM node with optional values and placement
-
Place DOM nodes relative to others
-
Destroy a DOM node
-
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
.-
Modifying DOM node attributes
-
Gets an attribute on an HTML element.
-
Sets an attribute on an HTML element.
-
Returns true if the requested attribute is specified on the given element, and false otherwise.
-
Removes an attribute from an HTML element.
-
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
.-
Serialize a form field to a JavaScript object.
-
Create an object from an form node
-
Serialize a form node to a JavaScript object.
-
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
.-
A getter/setter for styles on a DOM node
-
Return a cacheable object of all computed styles for a node
-
Accesses styles on a node.
-
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
.-
Returns a boolean depending on whether or not a node has a passed class string.
-
Adds a CSS class to a node.
-
Removes a class from a Node.
-
Toggles a className (or now in 1.4 an array of classNames).
-
Replaces one or more classes on a node if not present. Operates more quickly than calling
dojo.removeClass
anddojo.addClass
.
-
Geometry (dojo/dom-geometry)
This module defines the core dojo DOM geometry API. The convention for the return variable for this module is
domGeom
.-
Getter for the coordinates (relative to parent and absolute) of a DOM node. Deprecated in Dojo 1.4.
-
Getter for the border-box x/y coordinates and size of a DOM node.
-
Getter/setter for the margin-box of node
-
Getter/setter for the content-box of node
-
Get an object that encodes the width, height, left and top positions of the node’s margin box.
-
Sets the size of the node’s margin box and placement (left/top), irrespective of box model.
-
Get an object that encodes the width, height, left and top positions of the node’s content box, irrespective of the current box model.
-
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
.-
Gets or sets a property on an HTML element.
-
Gets a property on an HTML element.
-
Sets a property on an HTML element.
-
IO-Query (dojo/io-query)¶
-
Takes a name/value mapping object and returns a string representing a URL-encoded version of that object.
-
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)¶
-
Users who use doh+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)¶
-
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.
AJAX I/O transports (dojo/io/*)¶
-
Sends an AJAX I/O call using an IFrame
-
Sends a JSONP request using a script tag
AJAX RPC transports (dojo/rpc/*)¶
-
Communicate via Remote Procedure Calls (RPC) with Backend Servers
-
Generic JSONP service
-
JSON RPC service
-
RPC service class
Query (dojo/query)¶
-
The swiss army knife of DOM node manipulation in Dojo.
Selectors (dojo/selector/*)¶
The different selector engines that are available in Dojo.
-
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.
-
A class to handle a list of DOM nodes. Most commonly returned from a dojo.query call.
-
Create classes out of each node in the list
-
Adds a
.data()
and.removeData()
API to dojo.query operations -
Adds
dojo.fx
animation support todojo.query()
. -
Adds a chainable html method to dojo.query()
-
1.4+ Method extensions to dojo.NodeList/dojo.query() that manipulate HTML.
-
1.4+ Method extensions to dojo.NodeList/dojo.query() for traversing the DOM.
Browser History (dojo/back - dojo/hash)¶
Store (dojo/store)¶
-
Dojo Store is an uniform interface for the access and manipulation of stored data that will eventually replace dojo/data
-
A data access interface for in memory storage
-
A data access interface for a RESTful service providing JSON data
-
A wrapper for data stores that are observable
-
A wrapper for data stores that are cacheable
-
Data (dojo/data)¶
-
The deprecated uniform data access layer
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)¶
-
Date manipulation utilities
dojo.date.locale
Offers a library of localization methods to format and parse dates and times
dojo.date.locale.addCustomFormats
Adds a reference to a bundle containing localized custom formats to be used by date/time formatting and parsing routines.
-
Formats a Date object as a String, using locale-specific settings or custom patterns.
-
Used to get localized strings from dojo.cldr for day or month names.
-
Determines if the date falls on a weekend, according to local custom.
-
Converts a properly formatted string to a primitive Date object, using locale-specific settings.
-
Builds the regular needed to parse a localized date
Drag and Drop (dojo/dnd)¶
-
Drag and Drop
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.
-
Defers execution of the module’s factory function until the DOM is ready.
-
Loads text resources; it is a superset of RequireJS’s text plugin, and subsumes
dojo.cache
. -
Loads i18n bundles either in legacy or AMD format. It includes the legacy i18n API and is a superset of RequireJS’s i18n plugin.
-
Allows has.js expressions to be used to conditionally load modules.
-
A convenience plugin for loading dependencies computed at runtime.
-
Downloads a legacy module without loading it. This allows the legacy code path to be guaranteed.
-
Causes
dojo.loadInit
callbacks then other legacy API functions to be executed–in particular those that are associated with a module.
Miscellaneous Core¶
-
A registry to make contextual calling/searching easier
-
Utility for unobtrusive/progressive event binding, DOM traversal, and manipulation
-
Get and set named properties in conjunction with the ability to monitor these properties for changes
-
Provides aspect oriented programming facilities to attach additional functionality to existing methods
-
A Common Locale Data Repository (CLDR) implementation
-
CSS color manipulation functions
-
Simple HTTP cookie manipulation
-
Localized formatting and parsing routines for currency data
-
Event handling for a group of Deferred objects
-
Effects library on top of Base animations
-
Google Gears
-
Inserting contents in HTML nodes
-
Utility classes to enable loading of resources for internationalization
-
Localized formatting and parsing methods for number data
-
The DOM/Widget parsing package
-
Regular expressions and Builder resources
-
String utilities for Dojo
-
Provides extension events for hovering and mouse button utility functions
-
Provides normalized event listening and event dispatching functionality
-
Provides standardized touch events
-
Loads a Dojo module, by name
Table of Contents
- Dojo Overview
- dojo.js
- dojo/_base
- Configuring Dojo (dojo/_base/config)
- Array Utilities (dojo/_base/array)
- Language Utilities (dojo/_base/lang)
- HTML Utilities (dojo/_base/html)
- Deferred Utilities (dojo/_base/Deferred)
- Kernel (dojo/_base/kernel)
- Window (dojo/_base/window)
- Effects (dojo/_base/fx)
- Connect (dojo/_base/connect)
- NodeList (dojo/_base/NodeList)
- Event (dojo/_base/event)
- Document Lifecycle - Unload (dojo/_base/unload)
- AJAX/XHR (dojo/_base/xhr)
- Package System (dojo/_base/loader)
- JSON Tools (dojo/_base/json)
- Objects / OO Utilities (dojo/_base/declare)
- Colors (dojo/_base/Color)
- Miscellaneous Base
- Dojo Core
- DOM (dojo/dom*)
- IO-Query (dojo/io-query)
- Robot (dojo/robot - dojo/robotx)
- Document Lifecycle - Onload (dojo/ready)
- AJAX I/O transports (dojo/io/*)
- AJAX RPC transports (dojo/rpc/*)
- Query (dojo/query)
- Selectors (dojo/selector/*)
- NodeList (dojo/NodeList-*)
- Browser History (dojo/back - dojo/hash)
- Store (dojo/store)
- Data (dojo/data)
- Cache (dojo/cache)
- Date (dojo/date)
- Drag and Drop (dojo/dnd)
- AMD Loader Plugins
- Miscellaneous Core
- See also