TableSuck: Suckerfish for Tables

Filed under: JavaScript, WebDev | 2 Comments

So you’re laying out some tabular data. (You wouldn’t be using tables for any other reason, now, would you? Didn’t think so.) You stopped by ALA and made some zebra tables to make your rows nice and clear.

Then you thought to yourself, “I think I’ll use the :hover pseudo-class to add a nice hover effect to those rows.” But soon it was “Arrgh, why isn’t it working in IE?”

OK, stop yawning, so this is old news. We already knew that IE only supports the :hover pseudo-class on anchors. You’ve already been using Suckerfish for your drop-down navigation, right? Great. Let’s put it to work on a table.

Note: If you’re not already familiar with Suckerfish, take a moment to read the link above, as I’m only going to cover what I tweaked in it, not the whole thing.

So what needs to change to make Suckerfish work with tables? Well, it starts out the same way: after identifying the browser as IE, you use getElementById to get your element, and store that in a variable:

searchRoot = document.getElementById("your-table-id");

Now, the original Suckerfish looks through the child elements of searchRoot for any <li> elements. But instead of list items, we are looking for table rows.

If you simply change node.nodeName=="LI" to node.nodeName=="TR", your script won’t work. The only direct child elements of a <table> are <thead> and <tbody>.

Here’s the trick: <tbody> will always be a child element, whether it’s in your markup or not. So JavaScript will not find a table row in the child elements of a table.

So first we have to get the table body:

for (i=0; i<searchRoot.childNodes.length; i++) {
node = searchRoot.childNodes[i];
if (node.nodeName=="TBODY") {

Then we can search through that for the table rows:

for (a=0; a<node.childNodes.length; a++) {
newNode = node.childNodes[a];
if (newNode.nodeName=="TR") {

Besides that, the rest of the original script stays the same! So that leaves us with our final script:

window.onload = function tableSuck() {
 if (document.all&&document.getElementById) {
  searchRoot = document.getElementById("your-table-id");
  for (i=0; i<searchRoot.childNodes.length; i++) {
   node = searchRoot.childNodes[i];
   if (node.nodeName=="TBODY") {
    for (a=0; a<node.childNodes.length; a++) {
     newNode = node.childNodes[a];
     if (newNode.nodeName=="TR") {
      newNode.onmouseover=function() {
       this.className+=" over";
      }
      newNode.onmouseout=function() {
       this.className=this.className.replace(" over", "");
      }
     }
    }
   }
  }
 }
}

To finish it all off, write the same CSS rule to cover both tr:hover and tr.over, just like with the original Suckerfish.

And it works! Check out the final results here.

Boot Camp Analysis

Filed under: Culture, Tech | 2 Comments

Well, over the past 36 hours, I have read a lot of analysis on Apple’s newest announcement, Boot Camp. Not owning a McBook (hat tip to Clint for the term), I have yet to play around with it myself, but the reports I’ve read have so far consistantly been good. Considering my own need to test websites in IE, my first reaction was “sweet!,” though, with the recent hacked version, I wasn’t suprised at all.

However, no matter how much I love the idea, I hate the idea of having to re-boot every time I need it.1 I’ve already thought through the idea buying a Mac just to run Windows, which seems kind of silly. Khoi Vinh also voiced these concerns in his excellent post on the topic.

There has been a lot of debate on the question of why, and what does this mean. Some of the common answers are:

  • To eak out a few more points of market share by getting a few fence-sitters to switch
  • A full frontal assault on MicroSoft (i.e., who would want a PC that can only boot one OS)
  • To take over the world

With the exception of Khoi’s, all of the reviews and analysis I have read have missed a couple things on Apple’s Boot Camp page that particularly cought my attention:

Screen-shot from Apple's Boot Camp page

Wow, you catch that attitude?? There’s something bigger going on here. There’s a mental game afoot.

Well, while staying up way too late tonight (again) catching up with my RSS, I ran into the best analysis I have seen yet on the always excellent Daring Fireball:

Apple is confident that most Windows users who give Mac OS X a shot are going to prefer it — again, much in the same way that most long-time Mac users preferred Mac OS X to the old Mac OS.

…everything about Boot Camp is calibrated to position Windows-on-Mac as the next Classic-style ghetto — a compatibility layer that you might need but that you wish you didn’t.

That pretty much sums it up. DF’s analysis covers everything from the wording on Apple’s page to their bastardization of the Windows logo.

I can’t really say anything better than he did, so go read it for yourself. And let me know what you think.

  1. This has of course already been addressed by Parallels

April 2006

Filed under: Playlist | 0 Comments

Again, not much new to report this month. Things have been too crazy (which also explains my tardiness with this update). Regardless, here we go:

Listening to:
- Rumpistol: Mere Rum [Rump Recordings]
- Stephen Stills: Manassas
- Blondie: Autoamerican

Dusting Off:
- The Orb: U.F.Orb
- Moby: Moby
- Lords of Acid: Lust
- 808 State: Ex:El
- Fugazi: The Argument
- Shellac: Terraform