What is it?

Ojay is an open-source JavaScript library developed by London web agency the OTHER media for use in all its ongoing client projects. It acts as a wrapper for YUI, providing a more intuitive programming model and some additional features. It is built for compatibility with YUI 2.4.0 onwards, and is released under a BSD-style license.

One of its key features is the ability to chain function calls together, even when asynchronicity is involved. So, you can write lists of instructions where you would normally have nested callbacks:

Run this code!
    $('a#run-this-code').on('click', $.stopDefault)
        .setContent('Running...')
        ._('#example').animate({  height:  {to: 0},
                                  opacity: {from: 1, to: 0}
                               }, 0.5)
        ._($.HTTP).GET('/service/hello.html')
                  .insertInto('#example')
        ._('#example').animate({  height:  {to: 80},
                                  opacity: {from: 0, to: 1}
                               }, 0.7);

Download version 0.5.0

0.5.x is backward-compatible with previous releases. It includes the FilmStrip class which extends the Paginator package with a paginator for handling a single row or column of variable-width or -height elements. Both this and the Paginator class share a common core of functionality, encapsulated in the Paginatable module which you can mix into your own classes to create your own paginator variants.

How do I use it?

To start with, you’ll need to include the following YUI modules on your page: YAHOO.util.Dom, YAHOO.util.Event, and YAHOO.util.Selector. The first two form the base for interacting with the page via script, and the latter is YUI’s CSS selector engine, used by Ojay to grab element references.

Various Ojay features have further dependencies – these are highlighted in the documentation for each feature.

With those files in place, the articles in the sidebar should get you started. YUI libraries and all of Ojay is built into every page of this site, so you can try stuff out in Firebug as you read through the examples.

Development

Ojay is an open-source project, released under the BSD license, and the source code is hosted on Github. We also have a mailing list, or you can get in touch with the library’s author at james.coglan@othermedia.com.