iMusings - the iPhone, Standards, and jQuery


It still feels odd to use a WebKit browser on a phone and see it churn through the jQuery demos, but I’m having great fun with the Series 60 browser. I’ve already tweaked a number of my things to work better with it, and that includes reading RSS feeds via an Ajax-enabled (if kludgy) front-end to my newspipe and IMAP setup.

And, of course, with the enthusiasm regarding iPhone development, I’m positive we’ll see a bunch of neat web apps popping up all over the place, so I started keeping tabs on a few emerging projects like iui – a library for building web apps for the iPhone that tries to handle all the basics (and that I hope will also support other mobile WebKit browsers).

Too bad they went for Prototype instead of jQuery, though.

Honest – I’m guessing at this point that whoever starts developing for the iPhone is going to take a look at Apple’s revamped web site and go ’wow! surely, if my app is to be at least as cool as this, I should use the same JavaScript library!’ and, as a result, completely ignore jQuery, even though it does pretty much the same (if not more) and with amazingly efficient syntax.

Not only that, the new, improved jQuery 1.1.3.1 is fast, and I’m going to update all my production stuff with it as soon as the .1 fix is proven stable.

But JavaScript libraries apart, I have a stronger concern:

I most sincerely hope that the iPhone doesn’t give rise to a bunch of Safari-centric, egotistical, incompatible, and “standards para-compliant” applications – i.e., stuff that is formally standards compliant (because it is, after all, HTML and JavaScript) but that uses so many WebKit or Safari-specific idioms that ends up not working properly (if at all) in other browsers.

Otherwise, we’ll be back where we started when IE was all the rage, and repeating all the same mistakes.

So remember: Just because you’re doing it on the coolest phone on the planet doesn’t automatically make it right.

Update: For instance, I’ve been playing around with Joe Hewitt’s navigation sample, which is pretty neat, but only works on the iPhone browser and on the WebKit nightlies (yes, I refuse to run Safari 3.0 anywhere but Windows until it’s stable).

After doing a few simple changes, it now works in “regular” Safari (2.0) and my Nokia. Although I haven’t replaced the animation code with “normal” jQuery effects yet, all it takes is to change the handlers in a standard way:


$(document).ready(function() { // Show the page corresponding to the home button link // (we get the button’s link and then the element that has that hash as its ID) showPage($(’#’ + $(’#homeButton’).get(0).hash.substr(1)).get(0)); // Teach all links to invoke the showPage function $(“a”).click(function(){ // Show the first match for “#hash” showPage($(’#’ + this.hash.substr(1)).get(0)); }); // Periodic checks for iPhone orientation setInterval(checkOrientAndLocation, 300); // Hide iPhone toolbar? setTimeout(scrollTo, 0, 0, 1); });

Nothing else was changed (except removing addEventListener from iphonenav.js). But the rest – all the rest – looks like it can be replaced by six to ten lines of jQuery code…

Of course the CSS is all shot due to “proprietary” WebKit stuff, but that’s fixable. If I have time, I’ll post the results somewhere.


See Also: