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 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 and IMAP setup.

And, of course, with the enthusiasm regarding 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 that tries to handle all the basics (and that I hope will also support other mobile WebKit browsers).

Too bad they went for instead of jQuery, though.

Honest – I’m guessing at this point that whoever starts developing for the is going to take a look at revamped web site and go ’wow! surely, if my app is to be at least as cool as this, I should use the same 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 is fast, and I’m going to update all my production stuff with it as soon as the .1 fix is proven stable.

But libraries apart, I have a stronger concern:

I most sincerely hope that the doesn’t give rise to a bunch of , 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 idioms that ends up not working properly (if at all) in other browsers.

Otherwise, we’ll be back where we started when 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 browser and on the WebKit nightlies (yes, I refuse to run 3.0 anywhere but until it’s stable).

After doing a few simple changes, it now works in “regular” (2.0) and my . 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.

This page is referenced in: