Yahoo! User Interface Library Revealed!

A couple of weeks ago, Yahoo released their JavaScript user interface library to the world. This is the very library that Yahoo uses internally for its miriad of products, and so was very likely that it would be highly stable, usable and cross browser compatible. The good news is, it seems that it is. In fact, the user interface team have gone to great pains to tell us exactly how they grade web browsers at Yahoo, and how much support each browser is likely to receive from their libraries. Impressive stuff.

Even so, I didn’t jump on board the moment this User Interface library train pulled into the station. The JavaScript I’m writing just now works quite nicely without using Yahoo’s libraries, and I didn’t really want to feel that I’d become locked in to using them. After all, the fuss and buzz surrounding the release of the libraries might have been just that, so I decided to wait until the fuss about the them had died down and some other people had written some proper feedback about how these libraries actually felt to use.

Then, a couple of days ago, Dustin Diaz wrote about Yahoo’s version of addEvent() . Now, I know Dustin works for Yahoo (actually I didn’t, but it says he does in his colophon - I wonder why he didn’t disclose it in this entry? Anyway, I absolutely believe that Dustin wrote his entry because he wanted to, not because he’d been called upon to do it by any Higher Power), but he is a very talented chap and I trust what he says. Basically, it seems like Yahoo’s addEvent() is the best thing since sliced bread and far better than any of the other versions on the market. The reasons Dustin gives for why it’s simply the best (better than all the rest) include:

  1. It’s got Handler Attachment Deferral.

    You can attach an event before the page has finished loading. If the element that you’re trying to attach the element to does not exist yet, then Yahoo’s Event compenent will keep checking for it’s existence every now and then until the window.onload event is fired. Woah - very cool

  2. It’s got Automatic Scope Correction.

    With the original addEvent() method Internet Explorer gave you the window obect when you asked for this (instead of giving you the object that caused the event). Not good. Yahoo’s version gives you the object that caused the event, just like a lot of the newer versions of addEvent().

  3. It’s got Automatic Event Object Browser Abstraction.

    Another improvement that deals with IE. For callback : function(e) { ... }, e is e is e whatever browser you’re using. So, no more having to do a round trip to window.event with IE.

  4. You can send an arbitrary Object to the Event Handler.

    This is very sexy. Makes it easier to pass arbitrary values into an event, which is rather nice.

So, I think that I’m going to have a play with it. I might even use it as the addEvent() method for Standardista Table Sorting, but I’m not sure - is the extra weight of the library going to be worth it? At the moment I’m teetering on the edge, not really sure whether I should use it or not. What do you think?

If you enjoyed reading this and would like other people to read it as well, please add it to, digg or furl.

If you really enjoyed what you just read, why not buy yourself something from Amazon? You get something nice for yourself, and I get a little bit of commission to pay for servers and the like. Everyone's a winner!

comments (2) | write a comment | permalink | View blog reactions


  1. by Nate Koechley on March 5, 2006 04:29 AM

    Hi Neil,

    If I may, I would point out one inviting characteristic of our library. Instead of requiring the download of a massive everything-but-the-kitchen-sink file, our library is made up of discrete parts. You can use Event.js (which is as small as 2kb) by itself. With our library — and this was an internal requirment when we decided to start building — you just use the pieces you need.

    (It’s true that some pieces of the library do require other parts, as you would expect. For example, Dragdrop.js requires Event.js, etc.)

    Thanks, Nate

  2. by Neil Crosby [TypeKey Profile Page] on March 5, 2006 08:52 AM

    Hi there Nate,

    Yup, that is a fantastic characteristic of your library, and I should really have mentioned it in the entry.

    I think I’m going to have a play with the Yahoo UI library when I start my next little JavaScript project (I’ve got one on the go at the moment, so it’ll be a little while before I do). I’m looking forward to it.

other relevant pages

about wwm is a resource for web developers created by Neil Crosby, a web developer who lives and works in London, England. More about the site.

Neil Crosby now blogs at The Code Train and also runs, The Ten Word Review and Everything is Rubbish.