Daring Fireball: PastryKit
daringfireball.net
daringfireball.net
(remember, dont actually use that code for your own website, I'm sure apple wouldn't like that), the only reason I put it up on github is because I found it interesting to learn from and thought others might too.
Some interesting notes:
1. the redirect if you are not coming from an iphone does not happen in this code. it is something done on the server. it has nothing to do with these PastryKit javascript files.
2. I took all of the minified css files and js files and made an uncompressed version next to it with the name <filename>.uncompressed.js for the css files I converted it to SASS because I like that and I can see better visually what they are doing with it. (ps, if nothing else, look at the css they are using, there is some awseome webkit-proprietary stuff you can do with your styles if you are targeting only the iPhone)
Some cool things:
1. check out the stuff they are doing with the html5 databases in classes/datacontroller-database-uncompressed.js that is pretty cool. 2. the loading image they do with pure css ( @-webkit-keyframes loadingImageAnimation ) in stylesheet.css is pretty cool.
Actually, maybe that's it: Perhaps PastryKit was developed originally as a "plan B" in case the App Store didn't take off. Its development probably tracks back to before 2007, when third-party native development was still in question, and was kept in the back pocket as the App Store was launched.
My guess is it will stay a stealth project unless the voice of devs burned by App Store policies becomes too loud and Apple needs to bring out an alternative.
Perhaps PastryKit was developed originally as a "plan B" in case the
App Store didn't take off. Its development probably tracks back
to before 2007, when third-party native development was still in
question, and was kept in the back pocket as the App Store
was launched.
Actually, given the history of 3rd party development on the device, I think this was "Plan A" and the App Store was "Plan B." When you watch the first couple of Stevenotes that came during and after the iPhone's public announcement, you'll note that Apple was originally expecting developers to only make web apps. But there was a big push-back from developers complaining that they couldn't make apps good enough to stand side-by-side with the built-in ones. (And people also pointed out the pointlessness of advertising to devs that the iPhone was using the same technologies as OS X if they couldn't be directly accessed.)It looks to me much more like the SDK was dependent on an OS build that just wasn't ready for primetime in 2007 and Steve was just trying to spin what they had as something you want.
Why re-invent something in Javascript when you control the underlying browser?
It could also have been developed during the initial post-launch pre-app-store period when they were encouraging webapps, but not released publicly until 2.0 or later.
The batteries on my Magic Mouse (which has momentum scrolling) are dead, so I'm using my Mighty Mouse today, and boy, is it a drag.
Beautified Gist: http://gist.github.com/257514
Compacted Orig: http://help.apple.com/ipodtouch/3/mobile/dist/PastryKit-ug-c...
[EDIT] A slightly nicer to read version with better coloring - http://dpaste.de/n2CR/
http://help.apple.com/iphone/2/Contents/Frameworks/Foundatio... http://help.apple.com/iphone/2/Contents/Frameworks/Foundatio... http://help.apple.com/iphone/2/Contents/Frameworks/Foundatio... . . . etc
oh, and http://help.apple.com/iphone/2/Parts/license.txt too.
We used it for the built-in help files in our iPhone app (Grafly, a graphing calculator).
I'm wondering how users on mobile browsers which aren't iPhones would react to that interface...? (And also, how well it would render.)
The underlying HTML is just a bunch of unordered lists and divs, and all the advanced behavior is via CSS and Javascript - if you want to make sure it'll work on less-capable browsers it's doable, but you'll need to keep an eye on how you're loading things.
You may wind up needing to to browser sniffing on the server and serving up different HTML if you see various browsers; we didn't get that far in the project we worked on.
Though, Android is very late getting some features (HTML5 manifests, local storage, and navigator.geolocation) and I'm still not sure if it supports support CSS animations.
iUI is a pretty decent way to get going quickly - it's a fairly simple framework once you start digging into it, and you can make some decent looking stuff. The AJAX loading of sub-pages is a nice touch and is handled well. We had to do a lot of the fancier map scrolling/etc. ourselves, though, and there are still a ton of shortcomings that we can't get around due to lack of native events (fixed toolbars, proper scrolling, a few other fiddly things that you might notice but are too esoteric to mention here.)
jQTouch is getting a lot of buzz right now, and we might look at rewriting ExpoJunkie using it early next year: http://www.jqtouch.com/
I wish people stopped using JavaScript to do things it wasn't supposed to do :(
EDIT: Momentum scrolling is delicious. I'm really enjoying this :D
Still, this is a very cool piece of JavaScript.
There are a few JS demos that show this off floating around for iPhone, though they tend to have a variety of potential problems. (Intercepting every touch event via Javascript and handling it yourself results in a lot of edge cases you need to handle; see what happens in the User Guide if you drag your finger off the edge of the screen...)
The "sticking" problem when you drag your finger off the bottom of the screen doesn't happen when you add the app to your home screen and launch it that way (because there's no safari menu at the bottom of the screen, presumably).
It does'nt kinda make sense if I have to have a Mac and iPhone to develop web apps for the iphone!
But really, "feel" is a huge part of the interface and you should be testing on a real device for any handheld dev. An iPod Touch is your cheapest option here.
It makes sense for Apple.
I am totally guessing based on the comment in the article that if you double tap the top of the screen it brings the address bar into view, sort of implying it was just scrolled away.
PKUtils.disableScrolling = function (a) {
a.stopPropagation();
window.addEventListener("touchmove", PKUtils.preventEventDefault, true);
window.addEventListener("touchend", PKUtils.restoreScrollingBehavior, true);
window.addEventListener("touchcancel", PKUtils.restoreScrollingBehavior, true)
};Is he talking about a different Apple than the one that I know of?