<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David B. Calhoun - Developer Blog &#187; iui</title>
	<atom:link href="http://davidbcalhoun.com/tag/iui/feed" rel="self" type="application/rss+xml" />
	<link>http://davidbcalhoun.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 08 Sep 2010 18:28:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using mobile-specific HTML, CSS, and JavaScript (Mobile web part 5)</title>
		<link>http://davidbcalhoun.com/2010/using-mobile-specific-html-css-javascript</link>
		<comments>http://davidbcalhoun.com/2010/using-mobile-specific-html-css-javascript#comments</comments>
		<pubDate>Wed, 30 Jun 2010 03:27:11 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[basejs]]></category>
		<category><![CDATA[blackberry.network]]></category>
		<category><![CDATA[blackberry.system]]></category>
		<category><![CDATA[capture api]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[gesture events]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[iui]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jqtouch]]></category>
		<category><![CDATA[media queries]]></category>
		<category><![CDATA[mozorientation]]></category>
		<category><![CDATA[orientationchange]]></category>
		<category><![CDATA[pastrykit]]></category>
		<category><![CDATA[touch events]]></category>
		<category><![CDATA[webkit]]></category>
		<category><![CDATA[xui]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=317</guid>
		<description><![CDATA[Mobile-specific HTML Use the viewport tag to properly fit the content to the screen: &#60;meta name=&#34;viewport&#34; content=&#34;width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no&#34;/&#62; Use the tel scheme for telephone numbers, allowing users to initiate calls by clicking: &#60;a href=&#34;tel:18005555555&#34;&#62;Call us at 1-800-555-5555&#60;/a&#62; Or use the sms scheme to initiate an SMS message: &#60;a href=&#34;sms:18005555555&#34;&#62; &#60;a href=&#34;sms:18005555555,18005555556&#34;&#62; &#60;!-- multiple [...]]]></description>
			<content:encoded><![CDATA[<h3>Mobile-specific HTML</h3>
<p>Use the <a href="http://davidbcalhoun.com/2010/viewport-metatag">viewport tag</a> to properly fit the content to the screen:</p>
<pre name="code" class="html">
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no&quot;/&gt;
</pre>
<p>Use the <a href="http://www.rfc-editor.org/rfc/rfc3966.txt">tel scheme</a> for telephone numbers, allowing users to initiate calls by clicking:</p>
<pre name="code" class="html">
&lt;a href=&quot;tel:18005555555&quot;&gt;Call us at 1-800-555-5555&lt;/a&gt;
</pre>
<p>Or use the <a href="http://www.rfc-editor.org/rfc/rfc5724.txt">sms scheme</a> to initiate an SMS message:</p>
<pre name="code" class="html">
&lt;a href=&quot;sms:18005555555&quot;&gt;
&lt;a href=&quot;sms:18005555555,18005555556&quot;&gt;          &lt;!-- multiple recipients --&gt;
&lt;a href=&quot;sms:18005555555?body=Text+goes+here&quot;&gt;  &lt;!-- predefined message body --&gt;
</pre>
<p>You also have access to several <a href="http://developer.apple.com/safari/library/documentation/appleapplications/reference/safariwebcontent/configuringwebapplications/configuringwebapplications.html">Apple-specific tags to use in your web application (iPhone and iPod Touch)</a>:</p>
<pre name="code" class="html">
// iOS 1.1.3+: this is the icon that's used when the user adds your app to the home screen
&lt;link rel=&quot;apple-touch-icon&quot; href=&quot;/custom_icon.png&quot;/&gt;

// iOS 3+: full-screen startup splash screen image
&lt;link rel=&quot;apple-touch-startup-image&quot; href=&quot;/startup.png&quot;&gt;

// enable full-screen mode
&lt;meta name=&quot;apple-mobile-web-app-capable&quot; content=&quot;yes&quot; /&gt;

// controls the appearance of the status bar in full-screen mode
&lt;meta name=&quot;apple-mobile-web-app-status-bar-style&quot; content=&quot;black&quot; /&gt;
</pre>
<p>And also some handy attributes to turn off annoying autocorrect features (works on iPhone, but anything else?):</p>
<pre name="code" class="html">
&lt;input autocorrect=&quot;off&quot; autocomplete=&quot;off&quot; autocapitalize=&quot;off&quot;&gt;
</pre>
<h3>Mobile-specific CSS</h3>
<p><a href="http://www.w3.org/TR/css3-mediaqueries/">Media queries</a> enable you to target specific features (screen width, orientation, resolution) within CSS itself.  You can use them two ways: 1) inline in a CSS stylesheet or 2) as the &#8220;media&#8221; attribute in the link tag, which targets an external stylesheet.  The following is an example of inline CSS that&#8217;s applied only when the device is in portrait mode:</p>
<pre name="code" class="css">
@media all and (orientation: portrait) {
	body { }
	div { }
}
</pre>
<p>Here&#8217;s the same media query using the other method, which points to an external stylesheet (not recommended, as it creates another network request):</p>
<pre name="code" class="html">
&lt;link rel=&quot;stylesheet&quot; media=&quot;all and (orientation: portrait)&quot; href=&quot;portrait.css&quot; /&gt;
</pre>
<p>Here&#8217;s a few examples:</p>
<pre name="code" class="css">
// target mobile devices
@media only screen and (max-device-width: 480px) {
	body { max-width: 100%; }
}

// recent Webkit-specific media query to target the iPhone 4's high-resolution Retina display
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
	// CSS goes here
}

// should technically achieve a similar result to the above query,
// targeting based on screen resolution (the iPhone 4 has 326 ppi/dpi)
@media only screen and (min-resolution: 300dpi) {
	// CSS goes here
}
</pre>
<p>Read more: <a href="https://developer.mozilla.org/en/css/media_queries">Media queries (Mozilla Developer Center)</a></p>
<p>(edit: removed section on <code>body[orient='portrait']</code>, which requires JavaScript and is in error.  See <a href="http://davidbcalhoun.com/2010/dealing-with-device-orientation">Part 6: Dealing with device orientation</a> for more details.)</p>
<h3>Mobile-specific JavaScript</h3>
<p>window.devicePixelRatio: determine screen resolution (analogue to the media query).  (iPhone 4 has the value 2, while Nexus One has the value 1.5).</p>
<p><a href="https://developer.mozilla.org/en/DOM/window.navigator.onLine">window.navigator.onLine</a> (boolean): not strictly mobile, but helpful for apps to determine if they&#8217;re being run offline</p>
<p><a href="http://developer.apple.com/safari/library/documentation/appleapplications/reference/safarihtmlref/articles/metatags.html">window.navigator.standalone</a> (boolean, iOS 2.1+): determine if it&#8217;s running in full-screen mode (Apple only?)</p>
<p><a href="http://developer.apple.com/safari/library/documentation/appleapplications/reference/safariwebcontent/handlingevents/handlingevents.html">touch events (iOS, Android 2.2+)</a>: touchstart, touchmove, touchend, touchcancel</p>
<p><a href="http://developer.apple.com/safari/library/documentation/internetweb/conceptual/safarivisualeffectsprogguide/InteractiveVisualEffects/InteractiveVisualEffects.html">gesture events (Apple only, iOS 2+)</a>: gesturestart, gesturechange, gesturend give access to predefined gestures (rotation, scale, position)</p>
<p><a href="http://ajaxian.com/archives/iphone-windowonorientationchange-code">window.orientation and orientationchange event</a>: triggered every 90 degrees of rotation (portrait and landscape modes)</p>
<p><a href="https://developer.mozilla.org/en/Detecting_device_orientation">MozOrientation</a> (Fennec/Firefox Mobile, Firefox 3.5+): also not strictly mobile.  Gives access to the device&#8217;s accelerometer (x-y-z orientation data), updated periodically.  Works on Android phones (I tested on the Nexus One), Windows Mobile, etc.  On the desktop this works with laptops such as Thinkpads and MacBooks.</p>
<p>-near future: camera/microphone access in Android 2.3 (announced at Google I/O 2010) through the <a href="http://www.w3.org/TR/capture-api/">Capture API</a></p>
<p>If you&#8217;re developing for a BlackBerry Widget, you have access to proprietary information through the <a href="http://www.blackberry.com/developers/docs/widgetapi/Summary_system.html">blackberry object</a> (which gives access to useful information such as blackberry.network [returns values such as CDMA and Wi-Fi] and blackberry.system).</p>
<p>You also have the option to use <a href="http://phonegap.com/">PhoneGap</a>, which augments JavaScript and gives you access to more phone features that native apps would have access to.</p>
<h3>Use a mobile-optimized JavaScript library</h3>
<p>Because smartphone browsers are standards-based, the aim of a JavaScript library on mobile is less towards API normalization and more towards providing an actual UI framework, usually to emulate the feel of native apps (and to provide easier workarounds to <a href="http://doctyper.com/archives/200808/fixed-positioning-on-mobile-safari/">lack of access to position:fixed</a>).  We&#8217;ve seen a few libraries released that emulate the iPhone UI, and in the future we might see libraries emulating the Android UI, as well as entirely new UIs.</p>
<p>There&#8217;s also a bit to be said about simply loading full desktop JavaScript libraries into mobile clients.  In my opinion this doesn&#8217;t particularly make sense, especially in a world where latency and bandwidth are so much more of a concern.  It doesn&#8217;t make sense to force the user wait longer and download code that&#8217;s ultimately useless to them (hacks for desktop browsers such as IE 6, etc).</p>
<p>Here&#8217;s a few of the mobile libraries now available:<br />
-<a href="http://www.sencha.com/">Sencha Touch</a><br />
-<a href="http://paularmstrongdesigns.com/projects/basejs/">baseJS</a><br />
-<a href="http://xuijs.com/">XUI</a><br />
-<a href="http://www.jqtouch.com/">jQTouch</a>: jQuery-style mobile library that emulates the look of the iPhone UI<br />
-<a href="http://code.google.com/p/iui/">iUI</a>: the first JavaScript library to be released, emulates the look of the iPhone UI.  Originally coded by <a href="http://www.joehewitt.com/">Joe Hewitt</a>.<br />
-<a href="http://davidbcalhoun.com/2009/pastrykit-digging-into-an-apple-pie">PastryKit</a>: Apple proprietary non-public JavaScript library with no available documentation</p>
<h3>Take advantage of new stuff!</h3>
<p>While not specific to mobile, there&#8217;s a lot of new stuff in general that you can use.  If you limit yourself to the top smartphones (iPhone, Android, and maybe webOS), compared to the desktop you immediately have access to an even wider array of new stuff, especially many Webkit proprietary features, since most of these top smartphones have browsers based on Webkit.</p>
<p>-HTML: new tags (<a href="http://diveintohtml5.org/">HTML5</a> (I&#8217;m sure you&#8217;ve heard of it by now…))<br />
-CSS: <a href="http://webkit.org/blog/130/css-transforms/">2d transforms</a>, <a href="http://webkit.org/blog/386/3d-transforms/">3d transforms</a>, animation, <a href="http://border-radius.com/">border radius</a>, <a href="https://developer.mozilla.org/en/css/@font-face">custom fonts with @font-face</a>, etc.<br />
-JavaScript: <a href="http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/">strict mode</a>, <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Core_Language_Features#Constants">constants</a>, <a href="http://davidbcalhoun.com/2009/javascript-tidbit-block-scope-with-let">block scope</a>, <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Date">Date.now()</a>, etc.</p>
<h3>Related posts</h3>
<p>This post is part of a series on the mobile web.  You can read the other parts of the series here:<br />
<a href="http://davidbcalhoun.com/2010/viewport-metatag">Part 1: The viewport metatag</a><br />
<a href="http://davidbcalhoun.com/2010/the-mobile-developers-toolkit-mobile-web-part-2">Part 2: The mobile developer’s toolkit</a><br />
<a href="http://davidbcalhoun.com/2010/designing-buttons-that-dont-suck">Part 3: Designing buttons that don’t suck</a><br />
<a href="http://davidbcalhoun.com/2010/on-designing-a-mobile-webpage">Part 4: On designing a mobile webpage</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2010/using-mobile-specific-html-css-javascript/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PastryKit: digging into an Apple Pie</title>
		<link>http://davidbcalhoun.com/2009/pastrykit-digging-into-an-apple-pie</link>
		<comments>http://davidbcalhoun.com/2009/pastrykit-digging-into-an-apple-pie#comments</comments>
		<pubDate>Wed, 16 Dec 2009 13:10:01 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iui]]></category>
		<category><![CDATA[jqtouch]]></category>
		<category><![CDATA[pastrykit]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=66</guid>
		<description><![CDATA[Yesterday John Gruber wrote about Apple&#8217;s PastryKit, iPhone&#8217;s JavaScript framework that&#8217;s been discovered &#8220;in the wild&#8221; on the iPhone user guide at http://help.apple.com/iphone/3/mobile/. There&#8217;s a few ways to access the page: with an actual iPhone or iTouch by browsing with an iPhone/iTouch user agent. If you&#8217;re using Safari, enable the Developer menu in Safari&#62;Preferences&#62;Advanced and [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday <a href="http://daringfireball.net/2009/12/pastrykit">John Gruber wrote about Apple&#8217;s PastryKit</a>, iPhone&#8217;s JavaScript framework that&#8217;s been discovered &#8220;in the wild&#8221; on the iPhone user guide at <a href="http://help.apple.com/iphone/3/mobile/">http://help.apple.com/iphone/3/mobile/</a>.  There&#8217;s a few ways to access the page:</p>
<ul>
<li>with an actual iPhone or iTouch</li>
<li>by browsing with an iPhone/iTouch user agent.  If you&#8217;re using Safari, enable the Developer menu in Safari&gt;Preferences&gt;Advanced and switching user agents by clicking on Develope&gt;User Agent</li>
</ul>
<h3>What&#8217;s all the big fuss?</h3>
<p>John was particularly interested in the responsiveness and native-like interaction of flinging through long lists, the fact the address bar is completely hidden, and the possibility of having a toolbar fixed to the top of the page.  PastryKit makes all of these things possible and implements them better than anything else.  And the result is nearly indistinguishable from a native app.  Here&#8217;s a video I made of the iPhone user guide in action, powered by PastryKit.  This is running on Safari &#8211; it&#8217;s not a native app!</p>
<div style="align: center; margin: 1em auto; width: 640px;"><object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/gV305XeIZyc&#038;hl=en_US&#038;fs=1&#038;color1=0x3a3a3a&#038;color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/gV305XeIZyc&#038;hl=en_US&#038;fs=1&#038;color1=0x3a3a3a&#038;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></div>
<h3>PastryKit has been here for a while</h3>
<p>As John Gruber points out, the code for PastryKit has been there for quite a while now.  <a href="http://stackoverflow.com/questions/1143589/what-is-the-pastrykit-framework">Stack Overflow has a question about it</a> that was asked way back in July, and there are several more <a href="http://twitter.com/jQTouch/status/6146839190">recent references</a> to it by jQTouch developer David Kaneda on Twitter.  Of course, since John&#8217;s post there&#8217;s been an explosion of interest in the form of even more tweets!</p>
<p>Hopefully with all of this increased attention, we&#8217;ll see Apple take notice and address it.  Here&#8217;s hoping, anyway.</p>
<h3>Some interesting features</h3>
<p>There&#8217;s even more interesting takeaways from the PastryKit code, and I&#8217;m sure I&#8217;ve just barely scratched the surface:</p>
<ul>
<li>implements its own form of Object-Oriented programming (obj.inherits and obj.synthetizes properties).  When modules are declared, they&#8217;re registered as a PK Class (i.e. PKClass(PKBarButtonItem) registers PKBarButtonItem as a PK Class)</li>
<li>CSS3 wrapper functions (PKUtils.t() is a wrapper for translate3d, etc.)</li>
<li>no single library namespace (surprisingly) &#8211; which means there are many many global variables.  This however is somewhat acceptable, as all variables are prefixed with &#8220;PK&#8221; and are declared to be constant (const PKStartEvent, const PKEndEvent) and cannot be overwritten.</li>
</ul>
<p>There&#8217;s also some interesting takeaways not from PastryKit itself, but from the way the iPhone user guide is implemented.  Most of the data on the page &#8211; including each menu icon (base64 encoded) &#8211;  is located in a single 650kb JSON-encoded file called content.json.  This means the initial loading of the page is quite slower than the user would normally expect, but once the initial payload has been delivered, it&#8217;s a relatively smooth browsing experience thereafter.</p>
<p>And as John Gruber already pointed out, this data is stored locally with the help of HTML5, allowing the user to continue reading even while offline!</p>
<div id="attachment_75" class="wp-caption aligncenter" style="width: 329px"><img src="http://davidbcalhoun.com/wp-content/uploads/2009/12/apple-pastrykit.png" alt="iPhone user guide in Safari" title="iPhone user guide in Safari" width="319" height="480" class="size-full wp-image-75" /><p class="wp-caption-text">iPhone user guide in Safari</p></div>
<h3>PastryKit unminified and explained (sorta)</h3>
<p>What I&#8217;m excited to show you now is a result of a bit of effort to make PastryKit more intelligible.  Though there&#8217;s a <a href="http://help.apple.com/iphone/3/mobile/dist/PastryKit-ug-compact.js">minified version of the code</a> on Apple&#8217;s website, it&#8217;s not obfuscated (and rendered unintelligible), so not all hope is lost!  With the help of <a href="http://jsbeautifier.org/">jsbeautifier.org</a> we can now see the slightly unminified version of the code: <a href="http://davidbcalhoun.com/pastrykit/PastryKit.js">PastryKit.js unminified</a>.</p>
<p>The next thing I did was separate each module into its own file.  I was able to separate the code into 27 numbered files, with the original ordering preserved (to prevent issues with dependencies).  Viewing the code in this way definitely helps make sense of it all.  You can download these separate files as part of a little unofficial SDK I made, which also includes a copy of the iPhone user guide with the JS iPhone-only redirect removed: <a href="http://davidbcalhoun.com/pastrykit/pastrykit-sdk.zip">PastryKit unofficial SDK</a>.</p>
<h3>PastryKit modules</h3>
<p>The following is an explanation of each module I found.  The descriptions are definitely incomplete and possibly inaccurate, so any comments or help is appreciated.  But this should hopefully shed some light on the matter!</p>
<ul>
<li>PKUtils &#8211; general helper functions (PKUtils.t() is a wrapper for CSS translate3d, PKUtils.degreesToRadians(), etc, etc.)</li>
<li>PKEventTriage &#8211; general event handler</li>
<li>PKPropertyTriage &#8211; handlePropertyChange() method &#8211; ?</li>
<li>Element &#8211; helper functions added to HTML Element prototype</li>
<li>Node &#8211; adds getNearestView() method to HTML Node prototype</li>
<li>PKClass &#8211; custom-rolled class with with &#8220;inherits&#8221; and &#8220;synthetizes&#8221; properties</li>
<li>PKObject &#8211; custom-rolled object with observer pattern.  Most modules extend from this.</li>
<li>PKPoint &#8211; wrapper for WebKitPoint &#8211; used for touch events?</li>
<li>PKSize &#8211; wrapper for width/height properties</li>
<li>PKImage (inherits PKObject) &#8211; helper for creating Image elements and knowing when it&#8217;s finished loading (but doesn&#8217;t add the image to the DOM)</li>
<li>PKAnimator &#8211; basic animation tweens</li>
<li>PKTransition &#8211; helper for proprietary Webkit CSS transitions</li>
<li>PKTransaction &#8211; interacts with PKTransition &#8211; ?</li>
<li>PKView (extends PKObject) &#8211; manages a view, such as handling events that occur within that view &#8211; ?</li>
<li>PKContentView (extends PKView) &#8211; ?</li>
<li>PKRootView (extends PKContentView) &#8211; ?</li>
<li>PKScrollIndicator (extends PKView) &#8211; custom scrollbar</li>
<li>PKScrollView (extends PKView) &#8211; handles dynamically positioning the page when it&#8217;s scrolled</li>
<li>PKTableView (extends PKScrollView) &#8211; handles more touch/scroll events?</li>
<li>PKCellPath &#8211; ?</li>
<li>PKTableViewCell (extends PKView) &#8211; ?</li>
<li>PKToolbar (extends PKView) &#8211; manages the top toolbar</li>
<li>PKNavigationView (extends PKView) &#8211; manages bottom navigation bar</li>
<li>PKNavigationItem (extends PKObject) &#8211; manages bottom navigation buttons</li>
<li>PKControl (extends PKView) &#8211; manages generic controls</li>
<li>PKBarButtonItem (extends PKControl) &#8211; manages button controls</li>
<li>PKSearchBar.js (extends PKView) &#8211; manages the search bar</li>
</ul>
<h3>Conclusion after a first glance</h3>
<p>As far as I can tell, this is no full-fledged JavaScript library.  At least not for now.</p>
<p>On first glance PastryKit seems to be at most a nice development framework for making web apps with the same look-and-feel of native iPhone apps.  And this framework in many ways does this better than anything out there (at the moment).</p>
<p>I echo the sentiments of Gruber &#8211; I do hope we hear more about this from Apple!</p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2009/pastrykit-digging-into-an-apple-pie/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
