Category Archives: Technical

ClassAnim & HoverHijax: Keeping Presentation out of Your JavaScript

Heads up! This was written in 2007 and many things have changed since then. Nowadays, CSS transitions are widely supported by browsers and a better approach.

Ever since the dawn of CSS and compliant browsers web developers have been squeezing the presentation layer out of HTML and into external CSS files. It has become a web development battle cry and having a tableless website was worn as your badge of honor. To the web dev elite, having <br> tags in your HTML is a sin punishable by death (or at least severe laughing and poking).

Now we are moving in to the so-called ‘Web 2.0’ era. The time of shiny websites with page refreshes cut down to a select few actions. Animations and special effects compliment the content as it fades in and out of view. Libraries like YUI, Dojo and Prototype are making these things increasingly easy and well supported. But with all this, I feel we’re forgetting something. Where’d the presentation layer go?

When you’re animating a rollover or fading some colors do you stop and thing what you’re doing? You’re putting the colors, dimensions and effects into your JavaScript! The presentation layer that you’ve worked so hard to externalize is leaking into your JavaScript code. This is a slippery slope that we have to prevent now. The presentation layer should remain in the CSS, markup in the HTML and logic in the JavaScript. If you want to change the colors or sizes the elements are morphed into, you should be making those changes in CSS.

This brings me to my solution. I present to you an extension to the YUI animation library that will perform your cool animations from the styles defined in your CSS. I call it ClassAnim.

How it works

  1. ClassAnim starts by reading the styles from the base element.
  2. Then it quickly applies the new CSS class to it, reads the new styles and removes the class. This happens quicker than the user can notice.
  3. Now it compares the styles from both versions, extracts the differences that can be animated, and invokes the animation.

With ClassAnim, when you want to make a color or dimensional change you don’t have to go searching through your JavaScript, you make the change straight in the CSS — the way it was meant to be.

See the demo
(Please note: This API is still beta)

Link Rollovers (HoverHijax)

Here’s a simple implementation for rollovers. You’ll notice that all the links on my site have a fading hover effect on them (try mousing over one). This uses a simplified version of ClassAnim that I call HoverHijax. It only animates colors and does it on mouseover and mouseout. My original prototype would actually honor the :hover pseudo class, but good ‘ol Internet Explorer wasn’t allowing me to get to those styles through JavaScript. The current implementation adds a ‘hover’ class to all links when they are being moused over.

See the demo
(Please note: This API is still beta)

The best thing with HoverHijax is that it follows the Progressive Enhancement (or Hijax) strategy and can easily work with or without JavaScript as long as you use the ‘hover’ class along with a ‘:hover’ pseudo class. The only difference is that without JavaScript it wont have the cool fade effect.

a:hover, a.hover {

   color: #000;

}

Where to Download

You can download these new ‘experimental’ APIs from my subversion repository.

The YUI’s First Year Party

If you haven’t heard yet, the YUI team has put out an open invitation to their first year party.

Quoting Nate Koechley from the YUI blog:

This month the YUI Library turns one year old. When we started last year I wrote that I was “thrilled to have you with us.” That’s never been truer than it is today. We owe an outstanding first year to you. Libraries aren’t achievements themselves — it’s what people do with them that’s exceptional. We love everything you’re doing, so we’re throwing a party to thank you, our amazing community.

Join us Thursday, February 22nd, from 5:30 to 8:30 PM, at Yahoo! HQ in Sunnyvale, California. Visit Upcoming.org for details and to RSVP. 300 people max, so RSVP early!

You can bet that I’ll be there along with many other WebDevs from PayPal. The guest list is up to 197, so RSVP now!

Czech Beer

New Version of OpenDownload

I finally got around to updating the OpenDownload extension and it’s now better than ever. Firefox 2.0 now hides the “Open With…” and “Save” options when downloading certain file types. When this happens now OpenDownload adds a “Run” button to the dialog. See screenshot below:

OpenDownload screenshot

I also fixed the bug that would, sometimes, execute the file multiple times.

I’ll be trying to find time to update my other extensions. Recently I’ve changed jobs and am working on a couple other open source projects. I can’t go into much detail right now about the open source projects I’m working on, but expect to hear more soon.

I’ve been at PayPal for about a month now and am really enjoying it. They hired me into their web development platform team as the JavaScript specialist. We’ve adopted the YUI libraries and they are working great to conserve time and provide really customized functionality. Will be sharing more soon.

Speaking of PayPal…

Updates for Firefox 2.0

Good news everybody (cue up Professor Farnsworth), I’ve finally got my server back up to 99% and have upgraded all the extensions for Firefox 2.0. You can go to my extensions list (http://mozmonkey.com) and download the latest versions there (NOTE: I haven’t updated the version numbers listed on the site yet). I’m also updating my update.rdf and submitting the extensions to addons right now.

Even better is that all the extensions have now been committed to my shiny new Subversion source control that’ll I’ll open to the public sometime next week. When I do I’ll also release and article on how to download and painlessly upgrade extension version numbers with my handy build scripts.

I hope you enjoy the extensions.

Delay in Firefox 2.0 Extensions Release

I know many of you are still patiently waiting for my extensions to be compatible with Firefox 2.0, but I continue to have severe web server issues. Somehow the server that hosts my extension site has come down and I cannot access it. I’m trying to get the hosting company to reboot it in safe mode right now so I can get to my code and give all of you upgrades to the extensions.

In the meantime, if any of you have hacked the source code and upgraded my extensions, please post a link to them here.

Again, sorry for the delay and thanks for the continued support. You’ll get updates soon.

April Fools Hack – The Singing Keyboard

This year I decided to go all out for April Fools and do something that could be duplicated across multiple computers without permanent damage — and so the singing keyboard hack was born.

Update

If you like this project, please vote for it on instructables.com.

Concept

Take the musical element from a musical greeting card and connect it to the caps lock LED on the user’s keyboard. Each time the victim presses caps lock the music plays (and quite loud too). This is a great sleeping prank…It might be found on the first day, or weeks from implementation. It’s the perfect prank.
Continue reading April Fools Hack – The Singing Keyboard

Creating a Semantic Tab Box — Without AJAX

Recently I wanted to create a content box that would use tabs to organize a few sections of text. Here were my requirements:

  1. Tabs oriented vertically (you can easily customize my example to be horizontal)
  2. HTML be semantic, logical and gracefully degrade
  3. Be easily accessible to screen readers
  4. Easy to implement and portable
  5. Works in IE, Firefox & Safari

I started by looking on the web for pre-existing examples of this and found a lot of things that worked well, but when you looked under the hood they were a mess.
Continue reading Creating a Semantic Tab Box — Without AJAX