No Mod Required

Archive for July, 2008

My New GetElementsByClass() + a Safari 3.1 Oddity

To make use of the native getElementsByClassName I rewrote my getElementsByClass function to use the method where possible.

Here's the code*:

function getElementsByClass(theClass,node) {
    var classElements = [];
    var i;
    if ( node == null ) {
    	node = document
    }
    if (node.getElementsByClassName) {
    	var tempCollection = node.getElementsByClassName(theClass);
        for (i = 0; i < tempCollection.length ; i++) {
    		classElements.push(tempCollection[i])
    	}
    }
    else {
    	var els = node.getElementsByTagName("*");
    	var elsLen = els.length;
    	var pattern = new RegExp("(^|\\s)"+theClass+"(\\s|$)");
    	for (i = 0; i < elsLen; i++) {
    		if ( pattern.test(els[i].className) ) {
    			classElements.push(els[i]);
    		}
    	}
    }
    return classElements;
};

The above code works as expected in Firefox 2, 3; IE 6,7,8, Opera 9.5 and Safari 2.

Interestingly it doesn't work in Safari 3.1. Safari supports the native getElementsByClassName, so one would expect it to work alongside Firefox 3 and Opera 9.5.

It does not.

Here's a sample. Click "start" and everything should go from blue to black (which means the class is removed from the LIs) and the numbers should read "10 0″. The 10 is the length of the collection returned by my function when the test starts. The 0 refers to the length after the test has run it's course and the class has been removed.

Safari 3.1 looks like this:

So the count is 10, even though there are 0 instances of the class in the DOM:

This is the code I'm running:

function testSafari() {
    $("messages").innerHTML = getElementsByClass("sample").length;
    var samples = getElementsByClass("sample");
    for (i=0;i<samples.length;i++) {
	    removeClass(samples[i],"sample");
    }
    $("messages").innerHTML += "    "+getElementsByClass("sample").length;
}

I've approached the problem from a few different angles (not exhaustive) and taking a quick look at the WebKit source it seems to me that Safari might be incorrectly caching the results of the getElementsByClassName call. I haven't had the time I would like to test this to see what might be happening in specific, but that's what it feels like.

Anyone know more about the guts of WebKit? Am I onto something? Or is my nonexistent Apple dev knowledge showing? :)

For the webdev crowd, anyone else seen anything like this? Is it something stupid that I'm doing that I'm just not seeing (and therefore not actually a bug)?

That's always my first assumption, but the native method works in both Opera and Firefox so I'm more confident than normal that the issue isn't my fault.

*I used to have support for a specific tag. When rewriting it I thought "I never use the tag argument, I'm dropping it." Of course, as soon as I did that one of my co-workers used the tag argument in a script he was writing for a site we were working on. I'll be adding the tag option back in.

Also, this version relies on support for Array.push(). Our little library adds it in with this:


if(!Array.prototype.push) {
    function array_push() {
        for(var i=0;i<arguments.length;i++){
	        this[this.length]=arguments[i]
        };
        return this.length;
    }
    Array.prototype.push = array_push;
}

Keith Kene on the Net

He's got a small, but fresh sample of flicks up:

KeneOne

kene one

My Theme Song Today

the river seine

Courtesy of Joni Mitchell

I was a free man in paris
I felt unfettered and alive
There was nobody calling me up for favors
And no ones future to decide
You know I'd go back there tomorrow
But for the work Ive taken on

[...]

If l had my way
I'd just walk through those doors
And wander
Down the champs elysees
Going cafe to cabaret
Thinking how Ill feel when I find
That very good friend of mine

Tour de France Weekend Wrap-up: I Just Want to Say…

I'm never picking Alejandro Valverde in the Tour again. Watching him get dropped on the first of two HC climbs on Monday sealed that deal for me. Sure. He looks good all spring. Yes. He's had some success in the Vuelta. No. I'm not picking him for the podium in the Tour again.

Beyond that, Menchov and Evans, to me, look like the guys to beat. If they don't finish 1-2 I'll be seriously surprised. The third member of the podium triumvirate is the interesting spot. Can Vandevelde stay with the big climbers like Sastre, Ricco and Schleck well enough to be able to knock them off with a good time trial? Or will one of the above climb themselves onto the podium?

Whatever way it shakes out the rest of the race is going to be a lot of fun to watch.

Another race I'm interested in is the point competition. Can Óscar Freire ride the jersey all the way to Paris? Will Cavendish (a)finish the race and (b) add enough points to overtake the motivated Freire? And what about big Thor? Kirchen?

Again, there should be some interesting races over the next couple of weeks.

WordPress 2.6 is Out. When Will I Find the Time?

WordPress 2.6

I'd like to upgrade. It's usually very quick, but in fear that it won't be I like to block out a good section of time to actually do the upgrade. Considering I manage a half dozen or so Wordpress installations (between home and work) that's actually a reasonable chunk of time to carve out of an already busy day.

The upgrade looks like a good one. I especially like the ability to track changes. We sell Wordpress installation and theming as a cheaper alternative to more expensive CMSs (no licensing fees) and one of the things I always wanted to be able to offer was version control. Now we have it (of sorts?) How robust it is remains to be seen.

I'll report back once I've been able to kick the tires.

Tour de France Stage 7 - Now That Was a Bike Race

Really hard riding today. Sanchez' victory was quite the classy way to pad the palmarès and the mess that got him to that point was a sight to see.

I love to see Kirchen sprinting for all the green jersey points, by the way. At this rate he looks like he wants to podium AND win the sprint jersey. That would certainly be an interesting result for the newly sponsored American team.

In the overall picture, I'm liking the approach of both Evans and Menchov. While a lot of the other contenders are messing around trying to take a few seconds here and a few seconds there, to maybe seize the jersey for a day or two, the two of them seem to understand that the energy wasted on these "lesser" stages is energy that could come in handy on a beast of a stage like the one coming up Monday or, even worse, the demonic test we have on tap for July 23. I mean, having a little bit extra when going over three HC climbs (Col du Galibier, Col de la Croix de Fer and L’Alpe-d’Huez) isn't a bad idea. Those two are riding like they know what's coming. Everyone else? Not so much. Now we just have to see what kind of climbing form they actually have.

Tour de France Stages 5 & 6 Team Columbia Rules the Roost

High Road/Team Columbia have certainly had a great year already, but this first week of the Tour has been bonkers. Green Jersey, White Jersey, stage win and now… The maillot jaune for Kim Kirchen. They're a well run, talented team hitting on all cylinders. I'm excited to see how they do over the final couple of weeks.

As for Stage 6 itself, I'm surprised there wasn't more activity on that last kilometer. It was still exciting racing, but I thought it would be just a little bit more insane. Vandevelde and Piepoli had the most exciting move and that really happened before the road turned straight up to the sky.

Ricco was a likely winner, in hindsight. He's an opportunist of the highest order and with the big GC men all worried about each other he was able to seize the day.

Stage 5 was more exciting than it should have been. It's painful watching a man from the break get caught within the last 500 meters. Within the last 100? Ouch.

How many more stage victories will Cavendish gain over the next ten or twelve years? Two Giro stages, one (so far) Tour stage… all at the tender age of 23. That's a bright future right there.

And now? Bring on the Pyrenees!

Back to Smooth

I find it hard to believe that no one ever made a record called "Back to Smooth." I've searched Amazon and the closest I've come is this:

not smooth. no.

Which isn't quite what I'm seeking.

What I really want is this:

Where I Am on the Net. The Big List…

Just in case you were wondering:

Friend me up if you so choose. I don't bite.

Movies 2008 #19 Once

Once Do people set out to make "charming" films? If they do, they could use Once as a template. Telling the story of an Irish street musician and a Czech immigrant who meet on the streets of Dublin, Once is thoroughly enjoyable film that exudes charm from its every pore. The charm is generated by sweetly romantic tale, the naturalistic performances by the ensemble cast and the music. The most important is probably the music. It's mostly a musical, and the music drives it through its too-short 86 minute running time.

Beyond its charms it's also an interesting film technically. Shot with natural light and in a personal manner it manages to inject a touch of realism without seeming contrived. I sometimes get frustrated by this new "reality" style because so little of what it portrays actually resemlbes reality. Here, since the performances are so honest and the story so simple, yet touching; the injection of the viewer, through the natural light and low-fi camera work actually brings us closer to the characters.

The film also avoids the perils of the "music video" moment. There are several full length songs in the film and none of them feel out of place- like they were dropped in fully formed from Mtv. A real accomplishment because I normally roll my eyes at similar sequences in lesser films. Here the musical interludes are as natural as rain and almost always drive the story forward in interesting ways.

Here's an excellent example:

All in all this is a fine film and one that is definitely recommended. Me? I'm buying the soundtrack.