Now what I did not do was use any widgets. Dojo widgets are a whole other ball game. I have written about them before — see my post about implementing a progress bar widget. This bit of example code is more about all the other cool stuff that Dojo lets you do.
The full source code for the tag generator is available in the tags.js file. The code is fairly direct, there's a bit too much repetition and stuff like that. But I thought I would try to not to “architect” it too much, as it is meant to be easy to understand.
The event handling uses the
dojo.event.connect function. I also use the convenient
$ function convention, instead of the far too verbose
document.getElementById, to pick out the HTML elements I want to attach events too. All the event connection code is at the end of the
The links on the side bar bring up semi-transparent
divs. This is done with the
dojo.style.setOpacity function, which hides all the browser specific stuff. I fade in the transparency over a few seconds using the
Dojo also provides a full suite of escaping functions. I use
dojo.string.encodeAscii for formatting the tag text correctly. These are great little functions that “just work”.
Various HTML elements are shown and hidden using the
dojo.html.hide functions. These work fine so long as the element is
display:block. It the element is inline, they won't work.
And, of course, AJAX. You knew it was coming. The comment form submits the comment data to the server using AJAX and pops up an alert to let you know it was saved. Look for the
dojo.io.bind function to handle all this for you. A really big win. Totally cross-browser and another “just works” feature for Dojo.
I should mention that I use JSON for the data encoding, just in case you were wondering how I did that. It's by far the best method for AJAX data exchange. Yeah, I know, the X is for XML. Well, honestly, JSON is better and much easier to work with, it’s just that AJAJ is crappy acronym.
So there you go. If you're an old hand at Dojo, then this post is probably a bit pointless, but if you're just starting out, hopefully you'll find some of it useful. It's meant to highlight things that Dojo can help you with, even if you aren't building the next GMail, Flickr or Web 2.0 Wonder Site.
Feel free to ask questions in the comments…