Ojay 0.4.0: a new Tabs package, custom DOM events and other goodness

We (which is to say, theOTHERmedia) just pushed out version 0.4.0 of Ojay, our JavaScript library that builds on top of the Yahoo! User Interface library. Also I just realised that I never properly announced the 0.3 release (which came out in December) here, so I should probably catch you up in case it looked like the project had died.

First, a quick summary of the 0.3 release. This version saw Ojay migrate to JS.Class 2.0, which allowed us to add type-level observers using some Module trickery. Type-level observers are event handlers that you can apply to a whole class of objects to get notification when a single instance changes. For example:

Ojay.Paginator.on('pagechange', function(pager, index) {
    // here pager is an *instance* of Paginator

This allows you to easily add behaviour to existing classes and objects without the ceremony of subclassing or overriding anything. You could even listen to all observable objects using Ojay.Observable.on(...).

0.3 introduced support for multiple CSS selector engines, with the ability to easily plug in your own. It currently has adapters for YUI, Ext, Sizzle, Peppy and the W3C API out of the box, with YUI being the default choice unless the browser supports document.querySelectorAll().

The HTTP package was improved by allowing implicit onSuccess handlers and transparent JSON-P support, for example:

// Old method:
Ojay.HTTP.GET('/endpoint', {id: 1}, {
    onSuccess: function(response) {
        // ...

// New method:
Ojay.HTTP.GET('/endpoint', {id: 1}, function(response) {
    // ...

// Cross-domain JSON-P call:
Ojay.HTTP.GET('http://json-time.appspot.com/time.json', {
    tz:    'America/Chicago',
    jsonp: 'callback'
}, function(data) {
    // handle data

And finally, 0.3 added ‘infinite’ looping paginators, and a bunch of other small additions and bug fixes.

Now onto 0.4. This release includes a Tabs package contributed by Benedict. We’d previously been doing tabs using a quick script – pretty simple with the Ojay core – but for one project we needed some custom events and so we decided it was big enough to go into Ojay itself and added said events, plus simple Ajax and History support for tab groups.

The other major additions in this release were support for custom DOM events, string-based (as opposed to key-value-pair-based) POST bodies, and some new methods for adding and removing content from paginators item-by-item.

We’ve also moved the source code to GitHub, where you can check out the full change log. Downloads are still available via the Ojay website.

If you’ve enjoyed this article, you might enjoy my recently published book JavaScript Testing Recipes. It’s full of simple techniques for writing modular, maintainable JavaScript apps in the browser and on the server.