Monday, June 18, 2007

An introduction to Dojo

Related link:
http://dojotoolkit.org

What is dojo?
Dojo is an Open Source DHTML toolkit that is written in JavaScript. For more information, take a look at this:
http://dojotoolkit.org/book/dojo-book-0-9/introduction/dojo-what-it

Quick intro to general function in Dojo:
  1. dojo.require(String module)
    This is how to include other module file to work with.
    dojo.require("dojo.generalModule");
  2. dojo.byId(String id)
    This sounds like document.getElementById(String id) in standard Javascript.
    dojo.byId("idNumber");
  3. dojo.addOnLoad(Function func)
    This function will be executed after all the HTML is already loaded.
    dojo.addOnLoad(someFunction);
  4. dojo.connect
    This is the way to map an event handler (function) to any property or element or object.
    function sayHello() {
    alert("Hello, everyone.");
    }

    function init() {
    dojo.connect(dojo.byId('helloButton'), 'onclick', 'sayHello');
    }
  5. dojo.declare
    This is all you need when you want to create new widget.
    - Name of widget
    - Extended widget
    - Constructor
    - Variables and functions
    dojo.declare(
    "temp.widget.HelloButton",
    [dijit.base.FormElement, dijit.base.TemplatedWidget],
    {
    required: false,

    templateString: "",

    onclick: function() {
    alert("Hello!!");
    }
    });
Reminder:
postMixInProperties
We can hook any parameters or functions before rendering HTML page here before manager render this page.
postCreate
If you want to hook any parameters or functions after the manager rendered HTML page, do it here.