<?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>Wayne Pan &#187; safari</title>
	<atom:link href="http://waynepan.com/tag/safari/feed/" rel="self" type="application/rss+xml" />
	<link>http://waynepan.com</link>
	<description>tech &#124; js &#124; ui &#124; ajax &#124; mobile</description>
	<lastBuildDate>Mon, 17 Oct 2011 20:52:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Digging into PastryKit</title>
		<link>http://waynepan.com/2009/12/16/digging-into-pastrykit/</link>
		<comments>http://waynepan.com/2009/12/16/digging-into-pastrykit/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 10:21:18 +0000</pubDate>
		<dc:creator>Wayne</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[pastrykit]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://waynepan.com/?p=444</guid>
		<description><![CDATA[If you haven&#8217;t already, go read the DaringFireball piece on PastryKit. Are you back? Good. If you&#8217;re the least bit like me, you&#8217;re probably a least a little bit intrigued. If you&#8217;re sorta like me you probably cut and pasted &#8230; <a href="http://waynepan.com/2009/12/16/digging-into-pastrykit/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t already, go read the <a href="http://daringfireball.net/2009/12/pastrykit">DaringFireball piece on PastryKit</a>. Are you back? Good. If you&#8217;re the least bit like me, you&#8217;re probably a least a little bit intrigued. If you&#8217;re sorta like me you probably cut and pasted <a href="http://help.apple.com/iphone/3/mobile/dist/PastryKit-ug-compact.js">http://help.apple.com/iphone/3/mobile/dist/PastryKit-ug-compact.js</a> into <a href="http://jsbeautifier.org/">jsbeautifier.org</a>. If you&#8217;re kinda like me you also dug into <a href="http://help.apple.com/iphone/3/mobile/javascript.js">http://help.apple.com/iphone/3/mobile/javascript.js</a> to see how PastryKit is used. And finally, if you&#8217;re exactly like me, you&#8217;ve probably already dissected the framework and won&#8217;t need to read this post <img src='http://waynepan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>PastryKit, at least the one on the iPhone User Guide, contains (it&#8217;s possible their compiler strips out classes/functions their site doesn&#8217;t use)</p>
<ul>
<li><b>PKUtils</b> &#8211; collection of util functions (eg. degreesToRadians, objectHasMethod, etc)</li>
<li><b>PKClass, PKObject</b> &#8211; classes that make inheritance easier. PKObjects to have observer methods for properties and PKClasses are able to synthetize properties ala ObjC.</li>
<li><b>PKPoint, PKSize, PKImage</b> &#8211;  self explanatory OOO objects for points, sizes, and &lt;img&gt; </li>
<li><b>PKAnimator</b> &#8211; simple animator class taskrunner/setTimeout style. Even PastryKit doesn&#8217;t use WebKitAnimations since the API is <a href="http://waynepan.com/2008/08/08/iphone-css-animations-thoughts-and-issues/">fubar&#8217;d</a>! As far as I can tell nothing in the framework or iPhone User Guide uses this</li>
<li><b>PKTransition</b> &#8211; This is where all the real animation is done, including the scroll effect, has the ability to commit animation transactions.</li>
<li><b>PKView, PKContentView, PKRootView</b> &#8211; View hierarchy, akin to one you would set up in Interface Builder. Very Xcode. I echo Gruber&#8217;s sentiments that PastryKit could show up in the next DashCode. Or at the very least the remnants of Apple&#8217;s web apps as an app strategy circa 2008.</li>
<li><b>PKScrollIndicator</b> &#8211; The magical class that creates the DHTML scrollbar when a view is scrolled.</li>
<li><b>PKSearchBar, PKTableView, PKNavigationView, PKToolbar</b> &#8211; the main view classes used to construct an actual app. (Along with PKScrollView, PKTableViewCell, PKNavigationItem, PKControl)</li>
</ul>
<p>If you&#8217;ve built anything in Xcode all this seems very familiar. Applications are built by setting up a hierarchy of views such as:</p>
<pre class="brush: jscript; title: ; notranslate">
// create a new navigation view
navigation = new PKNavigationView();
// set a size for the view
navigation.size = new PKSize(height, width);
// init some basic parameters about the view
 // add the view to the root view
PKRootView.sharedRoot.addSubview(navigation);
// build the rest of your views
</pre>
<p>I gave myself a couple hours to build a basic view app from scratch using PastryKit. It was painful and time consuming. There are plenty of methods that are required by the framework that you must declare unknowingly (eg. tableViewCellForRowAtPath vs tableViewCustomCellForRowAtPath dependent on what your table view is styled). Without proper documentation the framework is difficult to do any real work with. I&#8217;ll tinker with it some more but if you&#8217;re interested in a semi-prepackaged PastryKit and my work so far you can grab it <a href="http://waynepan.com/s/pastrykit_experiment.tgz">here</a>.</p>
<p>PKScrollIndicator is the best part of the framework, <a href="http://www.jqtouch.com/">jQTouch</a> should definitely look into &#8220;borrowing&#8221; this code.  Meanwhile, I&#8217;ll be waiting for a documented official release of PastryKit.</p>
<p><b>Bonus</b>: You can use the following to disable scrolling in Mobile Safari.</p>
<pre class="brush: jscript; title: ; notranslate">
document.addEventListener('touchmove', function(e) {
  e.preventDefault();
}, true);
</pre>
<p>This coupled with window.scrollTo(0,0) is how PastryKit hides the navigation bar.</p>
<p><i>Update:</i> Sorry, should be document.addEventListener() instead of window.addEventListener(). I&#8217;ve added a <a href="http://waynepan.com/s/noscroll">demo no scroll page here</a>. Just view the source.</p>
]]></content:encoded>
			<wfw:commentRss>http://waynepan.com/2009/12/16/digging-into-pastrykit/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Dissecting Safari 4&#8242;s Welcome Screen</title>
		<link>http://waynepan.com/2009/03/11/dissecting-safari-4s-welcome-screen/</link>
		<comments>http://waynepan.com/2009/03/11/dissecting-safari-4s-welcome-screen/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 06:53:49 +0000</pubDate>
		<dc:creator>Wayne</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css animations]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://waynepan.com/?p=340</guid>
		<description><![CDATA[If you&#8217;ve downloaded Safari 4 Beta then you&#8217;ve seen a very cool welcome screen. If you haven&#8217;t seen it click the video above (or if you&#8217;re running Safari 4 you can view it again here). I was curious as to &#8230; <a href="http://waynepan.com/2009/03/11/dissecting-safari-4s-welcome-screen/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><object width="476" height="235"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3591822&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3591822&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="476" height="235"></embed></object></p>
<p>If you&#8217;ve downloaded <a href="http://www.apple.com/safari/">Safari 4 Beta</a> then you&#8217;ve seen a very cool welcome screen. If you haven&#8217;t seen it click the video above (or if you&#8217;re running Safari 4 you can view it again <a href="http://www.apple.com/safari/welcome/">here</a>). I was curious as to how this page was put together so I did some dissecting&#8230; </p>
<p><b>HTML 5</b> &#8211; Cleverly, Apple decided to use HTML5 and the &lt;audio&gt; and &lt;video&gt; tags for the sound effects and part of the animation. The only part that is a full blown .mov is the ending compass sequence. <a href="http://images.apple.com/safari/welcome/media/compass.mov">Here is the .mov.</a></p>
<p><b>CSS Animation</b> &#8211; The first 2 animations, the Apple logo (plus lens flare) and the <i>Welcome to Safari 4</i> are achieved by a combination of CSS animations (<a href="http://images.apple.com/safari/welcome/styles/safari.css">stylesheet</a>) and a series of images. </p>
<p>The <i>Welcome to Safari 4</i>, is the simplest of the 2. It uses this image:<br />
<a href="http://images.apple.com/safari/welcome/images/header.jpg"> <img src="http://waynepan.com/wp-content/uploads/2009/03/header.jpg" alt="header" title="header" width="300" height="30" class="alignnone size-full wp-image-351" /></a><br />
&#8230; and this scaling animation rule:</p>
<pre class='brush:css'>@-webkit-keyframes header {
	from {
		opacity: 0;
		-webkit-transform: scale(2.6);
		-webkit-animation-timing-function: linear;
	}
	20% {
		opacity: 1;
		-webkit-transform: scale(1);
		-webkit-animation-timing-function: linear;
	}
	77% {
		opacity: 1;
		-webkit-transform: scale(0.9);
		-webkit-animation-timing-function: linear;
	}
	to {
		opacity: 0;
		-webkit-transform: scale(0.1);
		-webkit-animation-timing-function: linear;
	}
}
</pre>
<p>The Apple logo animation is bit more tricky and is achieved with these four images:<br />
<a href="http://images.apple.com/safari/welcome/images/apple_icon.png"><img src="http://waynepan.com/wp-content/uploads/2009/03/apple_icon.png" alt="apple_icon" title="apple_icon" width="50" height="78" class="alignnone size-full wp-image-348" /></a> <a href="http://images.apple.com/safari/welcome/images/apple_flare.jpg"><img src="http://waynepan.com/wp-content/uploads/2009/03/apple_flare.jpg" alt="apple_flare" title="apple_flare" width="50" height="50" class="alignnone size-full wp-image-350" /></a> <a href="http://images.apple.com/safari/welcome/images/apple_spots.png"><img src="http://waynepan.com/wp-content/uploads/2009/03/apple_spots.png" alt="apple_spots" title="apple_spots" width="50" height="55" class="alignnone size-full wp-image-349" /></a> <a href="http://images.apple.com/safari/welcome/images/apple_flare_icon.png"><img src="http://waynepan.com/wp-content/uploads/2009/03/apple_flare_icon.png" alt="apple_flare_icon" title="apple_flare_icon" width="50" height="62" class="alignnone size-full wp-image-347" /></a><br />
&#8230; plus 4 different css animation rules that are similar to the rule above but each image&#8217;s opacity is changed from 0 to 1 at the appropriate time. </p>
<p><b>Works on an iPhone</b> &#8211; What&#8217;s more impressive is that this page more or less works on an iPhone! The .mov and audio do not play, but everything animations properly. I removed the javascript that disables the page for non-Safari 4 browsers and put it here <a href="http://waynepan.com/s/safari4">http://waynepan.com/s/safari4</a>.</p>
<p><b>Bonus!</b> &#8211; At the end of all the animation, the page redirects you to <a href="topsites://">topsites://</a>, which of course takes you to Top Sites.</p>
<p>The Safari Welcome screen is a peak into the future. It shows us what&#8217;s possible when you get to throw all backwards compatibility concerns out the window&#8230; (no pun intended.)</p>
]]></content:encoded>
			<wfw:commentRss>http://waynepan.com/2009/03/11/dissecting-safari-4s-welcome-screen/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
<enclosure url="http://images.apple.com/safari/welcome/media/compass.mov" length="129258" type="video/quicktime" />
		</item>
		<item>
		<title>iPhone CSS Animations Thoughts and Issues</title>
		<link>http://waynepan.com/2008/08/08/iphone-css-animations-thoughts-and-issues/</link>
		<comments>http://waynepan.com/2008/08/08/iphone-css-animations-thoughts-and-issues/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 00:29:22 +0000</pubDate>
		<dc:creator>Wayne</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css animations]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://waynepan.com/?p=151</guid>
		<description><![CDATA[I&#8217;ve been doing a lot of work with the iPhone lately and I&#8217;ve been holding back on blogging about my experiences because I&#8217;m unclear as to the damn NDA stipulations. NDA be damn, here&#8217;s a first in a series of &#8230; <a href="http://waynepan.com/2008/08/08/iphone-css-animations-thoughts-and-issues/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a lot of work with the iPhone lately and I&#8217;ve been holding back on blogging about my experiences because I&#8217;m unclear as to the damn NDA stipulations. NDA be damn, here&#8217;s a first in a series of posts!</p>
<p>If you aren&#8217;t familiar with the new animation framework that&#8217;s built into Mobile Safari you can read about the closest thing on WebKit, <a href="http://webkit.org/blog/138/css-animation/">CSS transitions</a>. Here is an example of a CSS transition:</p>
<pre>
&lt;div style="-webkit-transition: opacity 2s ease-in"
  onclick="this.style.opacity='0'"&gt;
This div will do a fade when clicked only Safari 3.1 or on the iPhone!
&lt;/div&gt;
</pre>
<div style="-webkit-transition: opacity 2s ease-in; border: 1px blue dashed" onclick="this.style.opacity='0'">This div will do a fade when clicked Safari 3.1 or on the iPhone</div>
<p>Essentially you tie a timing function and duration when a css property is changed. CSS animations allow for more complex rule transitions. For example, if you want to have a card flipping effect show in this video, you will need to use CSS animations.<br />
<object width="325" height="244"><param name="movie" value="http://www.youtube.com/v/hM07-L0C48A&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/hM07-L0C48A&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="325" height="244"></embed></object><br />
<span id="more-151"></span><br />
CSS animations consist of a combination of 2 rules, one to define the animation timing, duration, and animation name. The second to define the actual animation.  </p>
<pre>
/* the following rules make something shrink from 50px */
/* to 10px then grow to 100px in 2 seconds */
.shrink-n-grow {
  -webkit-animation-name: 'shrink-n-grow-animation';
  -webkit-animation-timing-function: ease-in-out;
  -webkit-animation-duration: 2s;
}

@-webkit-keyframes shrink-n-grow-animation {
  from {
    height: 50px;
  }
  50% {
    height: 10px;
  }
  to {
    height: 100px;
  }
}
</pre>
<p>There are a few issues with the Mobile Safari CSS animation implementation and I urge Mozilla, the IE team, Opera, and W3C to consider these before writing their own spec.</p>
<h4>CSS means no syntax checking</h4>
<p><a href="http://snook.ca/archives/javascript/css_animations_in_safari/">Jonathan Snook</a> wrote about this last year and until I actually started using them I didn&#8217;t feel the pain. Since all the rules are written in CSS there is no error checking. Figuring out that you&#8217;re animation is broken because you misspelled -webkit-transition: is painful enough. When you start working with perspectives for translateZ, it will drive you utterly insane.</p>
<h4>Access through javascript problematic</h4>
<p>Also, because the rules live in CSS world, modifying existing rules on the fly in javascript requires you to use this ridiculous function to scan through CSS rules and find the one you want and then modifying a value.</p>
<pre>
  var findAnimation = function(name) {
      var ret_rule = null, sheets = document.styleSheets;
      for(var i = sheets.length - 1; i >= 0 ; i--) {
        var sheet = sheets[i];
          for(var j = sheet.cssRules.length - 1; j >= 0; j--) {
            var rule = sheet.cssRules[j];
              // 7 means the keyframe rule
              if(rule.type === 7 &#038;&#038; rule.name == name) {
                ret_rule = rule;
                break;
              }
            }
      }
      return ret_rule;
    }
  findAnimation('shrink-n-grow-animation').findRule(
     '50%').style.height = '25px'
</pre>
<h4>Needlessly complicated</h4>
<p>To use an animation, not only do you have to apply the final value of the animation if you want it to stick, but you have to perform some software olympics. </p>
<pre>
  // Add shrink-n-grow animation to a div
  var remove = function() { // we'll need this later
    // first, set final values
    theDiv.style.height = '100px';
    // then remove shrink-n-grow classname so that
    // it can be applied again animations are only
    // triggered when classnames are first applied
    theDiv.className = '';
    // remove this listener because webkitAnimationEnd
    // is triggered on every time ANY animation ends on theDiv
    theDiv.removeEventListener('webkitAnimationEnd', remove);
  };
  // listen for animation end
  theDiv.addEventListener('webkitAnimationEnd', remove);
  /// FINALLY, start the animation animation
  theDiv.className = 'shrink-n-grow';
</pre>
<p>That is just way too much code.</p>
<p>My personal preference is to have everything accessible in javascript so that the entire workflow of animation can live in javascript (instead of just modifying styles).</p>
]]></content:encoded>
			<wfw:commentRss>http://waynepan.com/2008/08/08/iphone-css-animations-thoughts-and-issues/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

