Cheers to everyone building PhoneGap. It freaking rocks.
I'm waiting on approval from Apple for my Japanese and JLPT Flash
Cards (
http://www.kanjitastic.com/) app and am ecstatic that I could
use most of my web app JavaScript directly in the iPhone app.
In the meantime it seems a good idea to contribute some of my code
back here. In particular I thought some might find it useful to be
able to synchronize the local database with a remote server, or load
an initial set of tables and data.
Impel.inTouch is one of the modules of an HTML5 Javascript ORM that I
am developing, but it can happily live on it's own. When you fire off
the Impel.inTouch's sync method it will use JsonP to retrieve a file
listing all the tables that you want to duplicate locally. Then one at
a time it will download those files, create any necessary tables and
load any data necessary. The files can be local to the app or hosted
on a remote server.
The API is and basic usage documentation is here:
http://www.kanjitastic.com/impel/api/inTouch/symbols/Impel.inTouch.html
The JavaScript source with comments is here:
http://www.kanjitastic.com/impel/dist/impel.inTouch-source.js
The YUI compressed version is here:
http://www.kanjitastic.com/impel/dist/impel.inTouch.js
Finally, a quick snippet showing how to use it to synchronize from the
local file system the first time the app is used and remotely
thereafter.
http://www.kanjitastic.com/en/blog/incrementally_synchronize_html5_databases_from_remote_or_local_sources.html
One thing to note on the snippet is that it makes reference to
localStorage, which doesn't exist on the iPhone. I've written a class
that emulates localStorage using the HTML5 database. I'll make it
available soon. Until then you can accomplish the same thing using
cookies.
Really, really last thing is that Impel.inTouch currently requires the
MooTools library. If Impel.inTouch proves to be useful to you and you
need the MooTools dependency pulled out tell me. I'll make it a
priority if it is a priority for enough people.