No Mod Required

Archive for the 'apple' Category

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;
}

Surprising (to me at least) iPhone Numbers

Is demand for the iPhone in America already starting to wane?

AT&T, the exclusive American carrier of the iPhone, activated just 900,000 iPhones during the fourth quarter, the company revealed during its earnings conference call Thursday. It wrapped up the year with “just at or slightly under 2 million iPhone customers,” according to company executives.

Apple announced at Macworld that it has sold 4 million iPhones through the middle of January, and Toni Sacconaghi, a financial analyst with Sanford C. Bernstein, thinks the gap between the figures means that Apple might have a demand problem. He released a research note Thursday after AT&T’s earnings saying that the carrier’s figures imply that an awful lot of inventory is building up at Apple’s channel partners.

Read the rest:

Report: iPhones piling up at AT&T stores

For my money, while it’s a lovely device the lack of a keyboard and the lack of third party apps makes it an unattractive option. I couldn’t live without my Treo and a healthy part of that is the wealth of third party applications I’m able to jam onto the thing.

And yeah, I’m sure mobile Safari would make me all tingly with it’s slickosity, especially when compared to the sickly Blazer, but to be honest it probably wouldn’t matter all that much. most of the time, if I’m surfing a site on my phone I’m not usually interested in bells and whistles anyway. I’m usually just looking for info, and Blazer’s optimized mode is usually better for that than a full blown website anyway (Just another reason those black screen iPhone commercials drove me nuts. I wanted yell at the screen sometimes since they would imply that the only way you could quickly browse to a site to get someone’s name is with the magical powers of the iPhone. )

The thing that’s surprising is that I really felt like I was in the minority and that there was the usual insatiable Apple technolust for the iPhone. Of course, the numbers could be wrong and the demand could be as insane as I expected it to be, but if the numbers are accurate that’s sure a lot of unsold iPhones.

Of course, thinking about it, I only know three people with iPhones. I see more Blackberries and Treos than that at pretty much any meeting with more than maybe seven or eight participants… Not a huge sampling of course, but it still seems like a small number.

A new site I made is live.

Not my magnum opus certainly, but it’s been several months since I’ve had a site launch so I figured I might as well prove that I’m still gainfully employed.

Macworld - Homepage | Macworld Conference & Expo

I did some HTML consulting* and some CSS work.

*Drupal, the technology it’s built on, doesn’t really allow the sort of control over markup I’m used to, so I’m limited to sketching out what I’d like to see, crossing my fingers and then asking questions like “is there any way we can get rid of X” or “can we change Z to Y?”

Drupal is really powerful and most of the people from the Drupal community we’ve worked with have been awesome, but I simply can’t stand working with the system. I’m used to being in complete control of the UI layer. With Drupal, complete control just isn’t possible so I’ve been driven a bit mental with bumping up against the constraints of the system.

“The iPhone is a piece of shit, and so is your face.”

“This keyboard will not only stomp your colon, but the colons of distant relatives of the human species such as lagomorphs, and hypothetical colons of children you haven’t even had yet. Want to type a backslash? No problem. Ampersand? You bet your ass. On an iPhone, you have to press an additional button that opens up an alternate keypad that will allow you to type numbers and punctuation. So typing something as simple as elipses (…) requires you to tap your finger 9 times. Enjoy your phone, losers! People like me who have shit to do will stick to a keyboard that doesn’t have its lips wrapped firmly to the user-interface equivalent of a throbbing dong:”

Way too funny for its own good. Especially since there’s valid criticism in between the jokes.

The iPhone is a piece of shit, and so is your face.

As a note, because of this I installed tussh installed on my Treo. The power of SSH from my phone is mine, all mine… next time I’m out and have a eureka debugging moment I could potentially whip out the phone and work my magic.

The odds of me doing that are slim, but it’s nice to have the option. I feel all nerdy.

iLamp

The first thing anyone I’ve talked to about it has said the same thing (and so does ZDNET): The new iMac looks like a desk lamp.

Has Apple gotten OS X stable enough for everyday use yet?

Survey: Anger at Microsoft’s new licensing - Tech News - CNET.com