Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Yahoo! UI JavaScript treats

The Yahoo! Developer Network was updated yesterday with a veritable gold-mine of Exciting New Stuff, coinciding with the launch of the brand new Yahoo! User Interface Blog.

Here are some of the highlights:

The code is all under a BSD Open Source license, which means you can use it freely in your own projects, including for commercial development.

This release represents the culmination of more than 9 months of work by an incredibly talented team. Eric Miraglia provides some behind-the-scenes insight in to the work that has gone in to the code.

I’ve been playing with this internally quite a bit over the past few months and I keep finding new useful bits and pieces. Here are some of my favourite details:

  • The Event library normalises the event model across multiple browsers, including workarounds for many of the weird frustrations faced when dealing with Safari. It cleans up events when the page is unloaded, which guards against a whole swathe of memory leak problems in IE. Best of all, if you assign an event to the DOM ID of an element that has not yet been loaded, the library keeps trying to attach the event (polling) until it succeeds or the page finishes loading.

  • The CustomEvent library implements the publish-subscribe/listener pattern for you to use within your own scripts.

  • The Dom library’s getStyle and setStyle methods include cross-browser support for the CSS 3 opacity property.

  • The Animation library uses a global Animation Manager object to oversee all animations on the page. This means it can adjust the frame-rate depending on how much stuff is happening—so if you tell a block to move across the screen in 1 second it will happen in one second no matter how much other stuff is going on at the same time.

  • Here’s a surprisingly tricky question: when does a drag start? When the user presses down on the mouse they might be starting a click rather than a drag. The Drag and Drop library defaults to starting a drag after a user either clicks and moves 3 pixels or more, or holds the mouse down for over a second.

  • The Drag library also makes it easy to have elements “grouped” so that they can only interact with other elements in the same group—see this demo for an example.

And finally, I couldn’t resist quoting this bit of code from one of the Animation examples:

var attributes = {
   width: { to: 100 },
   height: { to: 100 },
   fontSize: { from: 100, to: 50, unit: '%' },
   opacity: { to: 0.5 }
}
var anim = new YAHOO.util.Anim('size', attributes, 1,
  YAHOO.util.Easing.easeOut);

A big thanks to the team that put this all together.

This is Yahoo! UI JavaScript treats by Simon Willison, posted on 14th February 2006.

Tagged , ,

View blog reactions

Next: My ETech JavaScript tutorial

Previous: Notes from the summit

17 comments

  1. This is amazing. Great work to everyone responsible. You've just massivly increased my productivity.

    Ed - 14th February 2006 14:34 - #

  2. I've been checking these goodies out all morning (GMT -7 here). Sweet!

    Yvonne Adams - 14th February 2006 15:41 - #

  3. This is absolutely fantastic. Thanks to the entire Yahoo! Dev team. :)

    JD - 14th February 2006 15:44 - #

  4. I know it's not the exciting part, but I can't help but be most fascinated by the UI patterns library. Designers can have APIs too!

    Wilson - 14th February 2006 17:17 - #

  5. It's surprisingly well-written, and it looked great at first. But it seems really imbalanced - there's great code for particular functionality, but when it comes to manipulating the DOM and picking out elements, it is awful. Why do you need to give everything IDs to work with them? Why isn't there an easy way to select a bunch of elements? Why can't you pass something like "ol.draggable li" to set up your event handlers?

    Maybe I'm spoiled from working with jQuery recently, but writing code to manipulate a page just seems way too much needless work unless you have something like $(). It's a glaring omission considering most of the other major Javascript libraries have something along those lines.

    Jim Dabell - 14th February 2006 19:57 - #

  6. Wilson, design patterns are a heavily-borrowed concept (as Simon pointed out). He made an abortive attempt at CSS design patterns on the css-discuss wiki some time ago.

    There's a crying need for design patterns in UI discussions. Even if something is a well-understood problem, just giving the situation a name aids communication and learning.

    Instead of describing some complex problem for 15 minutes before getting to the point, I can say "maybe a visitor to each of the composite nodes would work."

    Huzzah for a high-profile effort at that need, says I.

    Jeremy Dunck - 14th February 2006 23:49 - #

  7. Jim, yeah, one of the first things I looked for was whether getElementsBySelector was included. Too bad.

    There is a benefit to giving everything an ID: using id + $() is a very cheap implementation of weakref so you can avoid closure-leak problems.

    (But I agree that the other common usage, in which all funcs take either an dom elm obj or an id, is useful, too.)

    Jeremy Dunck - 14th February 2006 23:58 - #

  8. Had I not been in the middle of switching hosting services, I would have been the first to blog about this. In the meantime, looks like Jeremy Z and Simon both beat me to it. Either way, the YUI library is cool indeed. Bill Scott (The Y! Ajax Evangelist) helped out quite a bit on this as well taking note of UI patterns within Ajax and really fine-tuned this thing. Just to give a little background and history, he helped on the Open Rico team and also was 'thanked' in the "Ajax in Action" book.

    Dustin Diaz - 15th February 2006 07:56 - #

  9. It's good stuff isn't it!

    Tom Coates - 15th February 2006 14:46 - #

  10. please read it all ....google wreckedband ,,,,paul mcartney 1 billion...bono worth one hundred million ...bill cosbey 250 million jessie jackson ??? ...mihael jackton .....millione .....y do they not help ...........interview me please ...................did u read about the sex pistles ,,said fuck u wi rockand roll hall of fame ,,,,safe thats waht u are little pigs in a blanket .......... www.wreckedband.com ( 7) posted on 26/02/2006 05:20 comments: music for america are just small litte people that will not let people express themselfs ...like the sex pistels ....we are rock and freken roll we want to help the dying n****rs in rowanda ...are u offended bi ...n****rs ..that n word well we are offended bi censorshop on music...for america .....they are killing my fello humans in africa .... ....snoop dog calls the niggis .....i call call u people who love your sick self ....god help us all ......f**k u music for yourselves ......richard hydell ...www.wreckedband.com screen name: www.wreckedband.com ( 7) posted on 26/02/2006 05:32 comments: music foe america ..or should i say censorship ...niggis is rowanda are sliced to bits children are dying ...crying ...sex pistoles have it right ...f**k u ....please paul mcmacartny bono ..jessie jackson bob geldoff ...bush ..hillery clinton help the niggis in rowanda ....sticke and stones weiil break my bones but names will never hurt me ....machetties will kill the ....rich f**ken rock stars ...politician ....were are u cried the little babies in rowanda .....richard hydell and wrecked ..www.wreckedband.com Mail from: richard hydell

    www.wreckedband.com - 28th February 2006 05:48 - #

  11. nice site

    penis enlargement - 6th March 2006 20:50 - #

  12. Just in case anyone cares I have manged to make a demo of the Yahoo UI on my website (www.steamed-design.com), feel free to have a look and steal it.

    Matthew Corich - 18th March 2006 05:22 - #

  13. Good text

    Naweb - 25th March 2006 12:14 - #

  14. I like your site. Blogs with comments windows that you have to click to open keep the dialogue under wraps. Blogs like this one which string comments out in the open are much more proactive about sparking dialogue.

    Tim - 11th April 2006 17:05 - #

  15. Hello, i am new with internet and i am tring to make a blog but its very hard. If anyone knows where to get information about this i would really apritiate it.

    tom - 29th April 2006 21:19 - #

  16. I agree with Tim. You should never use those nasty tiny windows again.

    Tam - 25th May 2006 21:35 - #

  17. seems to be interesting, I will test this on my site.

    Thommes - 9th August 2006 00:20 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2006/02/14/ui

A django site