Using MochiKit with Dojo Toolkit

MochiKit supports both the Dojo Toolkit and the JSAN package loading systems for JavaScript. This page documents how to use MochiKit with Dojo Toolkit, from versions 0.4 to 1.1 (and possibly also future versions). Please report any issues found on the MochiKit mailing list or by creating a support ticket.

Packaged Versions

When using the packaged version of MochiKit, the dojo package loading does not provide any additional functionality. Since all the MochiKit JavaScript code is placed in a single file, it is pointless to load individual modules with dojo.require(). The MochiKit.js file should be loaded after dojo.js though:

<!-- Using Dojo 1.1.0 release path here, replace with your own version -->
<script type="text/javascript" src="dojo-release-1.1.0/dojo/dojo.js"></script>
<script type="text/javascript" src="MochiKit/MochiKit.js"></script>

Of course, it is also possible to load MochiKit dynamically with dojo.require(). In this case, the MochiKit.js script shouldn't be included as above. Instead the following two lines of JavaScript code will trigger the script loading:

// Using the "../../MochiKit" file path, which corresponds to the previous example
dojo.registerModulePath("MochiKit", "../../MochiKit");
dojo.require("MochiKit.MochiKit");

Note: The Dojo integration is broken for custom packaged files, unless they include all the default MochiKit modules.

Development Versions

With development or unpacked versions of MochiKit, the preferred way of integrating with Dojo is using dojo.require(). Note that the file path must be specified as MochiKit is not part of a default Dojo installation.

// Using the "../../MochiKit" file path, which corresponds to the previous example
dojo.registerModulePath("MochiKit", "../../MochiDev");
// Either load all modules...
dojo.require("MochiKit.MochiKit");
// ... or only load specific modules
dojo.require("MochiKit.DOM");
dojo.require("MochiKit.Style");