<?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>Ajaxian &#187; Tutorial</title>
	<atom:link href="http://ajaxian.com/by/topic/tutorial/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Tue, 22 May 2012 21:45:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
    	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>CSS 3 Live: Progressive Enhancement</title>
		<link>http://ajaxian.com/archives/css-3-live-progressive-enhancement</link>
		<comments>http://ajaxian.com/archives/css-3-live-progressive-enhancement#comments</comments>
		<pubDate>Tue, 14 Sep 2010 12:00:33 +0000</pubDate>
		<dc:creator>Brad Neuberg</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=10265</guid>
		<description><![CDATA[From SitePoint comes a nice series of videos on CSS3, called CSS Live. Here&#8217;s one on Progressive Enhancement when using CSS3 features:]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://www.sitepoint.com/">SitePoint</a> comes a <a href="http://www.youtube.com/watch?v=_nbWikK2nHY">nice series of videos on CSS3</a>, called CSS Live. Here&#8217;s one on Progressive Enhancement when using CSS3 features:</p>
<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/_nbWikK2nHY?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/_nbWikK2nHY?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/css-3-live-progressive-enhancement/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create a Sticky Note Effect in 5 Easy Steps with CSS3 and HTML5</title>
		<link>http://ajaxian.com/archives/create-a-sticky-note-effect-in-5-easy-steps-with-css3-and-html5</link>
		<comments>http://ajaxian.com/archives/create-a-sticky-note-effect-in-5-easy-steps-with-css3-and-html5#comments</comments>
		<pubDate>Thu, 09 Sep 2010 10:30:35 +0000</pubDate>
		<dc:creator>Brad Neuberg</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=10177</guid>
		<description><![CDATA[Our very own Christian Heilmann has posted a tutorial on creating a fancy sticky note effect using CSS3 and HTML5: He breaks it down in five easy steps to produce the final following demo:]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://ajaxian.com/wp-content/images/sticky_notes.jpg"><img class="aligncenter size-full wp-image-10178" title="sticky_notes" src="http://ajaxian.com/wp-content/images/sticky_notes.jpg" alt="" width="140" height="140" /></a></p>
<p>Our very own <a href="http://www.wait-till-i.com/">Christian Heilmann</a> has <a href="http://net.tutsplus.com/articles/news/create-a-sticky-note-effect-in-5-easy-steps-with-css3-and-html5/">posted a tutorial on creating a fancy sticky note effect using CSS3 and HTML5</a>:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="345" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="flashvars" value="i=94517" /><param name="allowFullScreen" value="true" /><param name="src" value="http://screenr.com/Content/assets/screenr_1116090935.swf" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="345" src="http://screenr.com/Content/assets/screenr_1116090935.swf" allowfullscreen="true" flashvars="i=94517"></embed></object></p>
<p>He breaks it down in five easy steps to produce the <a href="http://nettuts.s3.amazonaws.com/771_sticky/step5.html">final following demo</a>:</p>
<p style="text-align: center;"><a href="http://nettuts.s3.amazonaws.com/771_sticky/step5.html"><img class="aligncenter size-full wp-image-10181" title="stickynotes1" src="http://ajaxian.com/wp-content/images/stickynotes1.png" alt="" width="326" height="165" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/create-a-sticky-note-effect-in-5-easy-steps-with-css3-and-html5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending HTML5</title>
		<link>http://ajaxian.com/archives/extending-html5</link>
		<comments>http://ajaxian.com/archives/extending-html5#comments</comments>
		<pubDate>Wed, 01 Sep 2010 10:30:57 +0000</pubDate>
		<dc:creator>Brad Neuberg</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=10128</guid>
		<description><![CDATA[Google Rich Snippet Oli Studholme has an excellent new article on HTML5 Doctor on the different ways HTML5 can be extended with things like microformats, the link tag, and more. Why would you want to do this? While HTML5 has a bunch of semantic elements, including new ones like &#60;article&#62; and &#60;nav&#62;, sometimes there just isn’t an element <a href="http://ajaxian.com/archives/extending-html5">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://ajaxian.com/wp-content/images/google-rich-snippet2.png"><img class="size-full wp-image-10129 " style="border: 1px solid black;" title="google-rich-snippet2" src="http://ajaxian.com/wp-content/images/google-rich-snippet2.png" alt="" width="380" height="132" /></a><br />
<em>Google Rich Snippet</em><br />
<a title="Posts by Oli Studholme" href="http://html5doctor.com/author/olib/">Oli Studholme</a> has an <a href="http://html5doctor.com/microformats/">excellent new article</a> on <a href="http://html5doctor.com">HTML5 Doctor</a> on the different ways HTML5 can be extended with things like microformats, the link tag, and more. Why would you want to do this?</p>
<blockquote><p>While <abbr>HTML</abbr>5 has a bunch of semantic elements, including new ones like <a title="The article element | HTML5 Doctor" href="http://html5doctor.com/the-article-element/"><code>&lt;article&gt;</code></a> and <a title="Semantic navigation with the nav element | HTML5 Doctor" href="http://html5doctor.com/nav-element/"><code>&lt;nav&gt;</code></a>, sometimes there just isn’t an element with the right meaning. What we want are ways to extend what we’ve got, to add <em>extra semantics</em> that are <em>machine-readable</em> — data that a browser, script, or robot can use.</p></blockquote>
<p>First, he starts with the options HTML4 gave us and what options we now have with HTML5:</p>
<blockquote><p>There were five fundamental ways we could extend <abbr>HTML</abbr> 4:</p>
<ul>
<li><code>&lt;meta&gt;</code> element</li>
<li><code>class</code> attribute</li>
<li><code>rel</code> attribute</li>
<li><code>rev</code> attribute</li>
<li><code>profile</code> attribute</li>
</ul>
<p>In <abbr>HTML</abbr>5, <code>rev</code> has fallen by the wayside, becoming obsolete since hardly anyone used it correctly, and because it can be replaced by <code>rel</code>. <code>profile</code> is also obsolete, and there is no support for namespaces in <abbr>HTML</abbr>5. However,<code>&lt;meta&gt;</code>, <code>class</code>, and <code>rel</code> <em>are</em> all in <abbr>HTML</abbr>5. In fact, <code>&lt;meta&gt;</code> now has <a title="4 The elements of HTML — HTML5 (Edition for Web Authors)" href="http://dev.w3.org/html5/spec-author-view/semantics.html#standard-metadata-names">spec-defined <code>name</code>s</a> and a way to <a title="MetaExtensions - WHATWG Wiki" href="http://wiki.whatwg.org/wiki/MetaExtensions">submit new<code>name</code> values</a>, and <code>rel</code> has <a title="4.12 Links — HTML5 (Edition for Web Authors)" href="http://dev.w3.org/html5/spec-author-view/links.html#linkTypes">several new link types</a> defined in the <abbr>HTML</abbr>5 specification and <a title="RelExtensions - WHATWG Wiki" href="http://wiki.whatwg.org/wiki/RelExtensions">a way to submit more</a> too.</p>
<p>Even better, <a title="3.2.5 Content models — HTML5 (Edition for Web Authors)" href="http://dev.w3.org/html5/spec-author-view/content-models.html#annotations-for-assistive-technology-products-aria"><abbr>WAI</abbr>-<abbr>ARIA</abbr>’s <code>role</code> and <code>aria-*</code> attributes are allowed in <abbr>HTML</abbr>5</a>, and <abbr>HTML</abbr>5 validators can check <abbr>HTML</abbr>5+ <abbr>ARIA</abbr>. Other new methods of extending <abbr>HTML</abbr>5 include <strong>custom data attributes</strong> (<code>data-*</code>), <strong>microdata</strong>, and <strong><abbr>RDFa</abbr></strong>. Guest doctor <a title="Chris Bewick's web design and development blog" href="http://chrisbewick.com/">Chris Bewick</a> introduced us to <abbr>HTML</abbr>5’s <a title="HTML5 Custom Data Attributes (data-*) | HTML5 Doctor" href="http://html5doctor.com/html5-custom-data-attributes/">new <code>data-*</code> attribute system</a>, which is perfect for adding private custom data for JavaScript, and we’ll no doubt meet microdata and <abbr>RDFa</abbr> sooner or later.</p></blockquote>
<blockquote><p>Finally there are <strong>microformats</strong>. As Dr. Bruce touched on microformats in his article on <a title="The time element (and microformats) | HTML5 Doctor" href="http://html5doctor.com/the-time-element/">the <code>&lt;time&gt;</code> element</a>, let’s delve a little deeper into what microformats are and how to use them in HTML5.</p></blockquote>
<p>Oli then does a great deep dive of microformats, going over the different ones defined by the community to date (there are 33 microformat specifications!) and covering some of the common patterns that you can use if you need to roll your own microformat. If you&#8217;ve been wondering how to use things like hCard, hCalendar, XHTML Friends Network (XFN), etc. in your own systems then definitely give this article a gander.</p>
<p>[<a href="http://johnfallsopp.com/">via John Allsop</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/extending-html5/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>View Source Tutorial: Content Site Using HTML5 Canvas + CSS3</title>
		<link>http://ajaxian.com/archives/view-source-tutorial-content-site-using-html5-canvas-css3</link>
		<comments>http://ajaxian.com/archives/view-source-tutorial-content-site-using-html5-canvas-css3#comments</comments>
		<pubDate>Mon, 30 Aug 2010 10:00:56 +0000</pubDate>
		<dc:creator>Brad Neuberg</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[View Source]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=10022</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p ">Via <a href="http://twitter.com/phil_franks">Phil Franks</a> comes an interesting HTML5/CSS3 site for <a href="http://www.therestudio.com/">There Studio</a>, which is a kind of coworking space in London:<br />
<a href="http://ajaxian.com/wp-content/images/therestudio1.png"><img class="aligncenter size-full wp-image-10023" title="therestudio1" src="http://ajaxian.com/wp-content/images/therestudio1.png" alt="" width="505" height="241" /></a></p>
<p>The site itself has a number of circles with information bouncing on the screen that respond to mouse clicks and moves.</p>
<p>Let's crack the site open using View Source and see how they are doing things. First, they have a repeated background with a little plus symbol with the following style rule on the &lt;body&gt; tag:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-10');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-10">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">background</span>: #ddd <span style="color: #993333;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">'../images/bg.gif'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#800000;">50</span>% <span style="color:#800000;">0</span> <span style="color: #993333;">repeat</span> <span style="color: #993333;">fixed</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>The textual content in each of the circles is clean semantic HTML that is search engine friendly:</p>
<div class="igBar"><a href="javascript:showCodeTxt('html-11');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">HTML:</span>
<div id="html-11">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"section who first"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/h3.html"><span style="color: #000000; font-weight: bold;">&lt;h3&gt;</span></a></span>Who<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h3&gt;</span></span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></a></span>Creatives, makers, thinkers <span style="color: #009900;"><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"ampersand"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #ddbb00;">&amp;amp;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span> doers<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>To turn that into this:<br />
<center><a href="http://ajaxian.com/wp-content/images/therestudio2.png"><img src="http://ajaxian.com/wp-content/images/therestudio2.png" alt="" title="therestudio2" width="209" height="213" class="aligncenter size-full wp-image-10026" /></a></center></p>
<p>The &lt;h3&gt; is first transformed into having an underline with the padding and margin being on the bottom:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-12');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-12">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">h3 <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border-bottom</span>: 1px <span style="color: #993333;">solid</span> #ccc;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">display</span>: <span style="color: #993333;">block</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-size</span>: 25px;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">normal</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span>: <span style="color:#800000;">0</span> <span style="color:#800000;">0</span> 10px;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span>: <span style="color:#800000;">0</span> <span style="color:#800000;">0</span> 8px;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p><a href="http://www.therestudio.com/media/js/main.js">JavaScript creates the circle</a>. The script tags themselves are at the end of the HTML page at the bottom of the &lt;body&gt; tag, a good performance practice in general.</p>
<p>The heart of drawing each circle is in the createBall and createContentBall methods. If a ball will have HTML content, then the createContentBall method is used, otherwise the createBall method is used. Let's look at the createContentBall method; we'll break it down:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-13');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-13">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> createContentBall<span style="color:#006600; font-weight:bold;">&#40;</span>className,size,color,html<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> element = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">'div'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; element.<span style="color: #006600;">className</span> = className;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; element.<span style="color: #006600;">width</span> = element.<span style="color: #006600;">height</span> = size;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; element.<span style="color: #006600;">style</span>.<span style="color: #006600;">position</span> = <span style="color: #3366CC;">'absolute'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; element.<span style="color: #006600;">style</span>.<span style="color: #006600;">left</span> = -size + <span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; element.<span style="color: #006600;">style</span>.<span style="color: #006600;">top</span> = -size + <span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; element.<span style="color: #006600;">style</span>.<span style="color: #006600;">cursor</span> = <span style="color: #3366CC;">"default"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; canvas.<span style="color: #006600;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>element<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; elements.<span style="color: #006600;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span> element <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> circle = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">'canvas'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; circle.<span style="color: #006600;">width</span> = size;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; circle.<span style="color: #006600;">height</span> = size;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>className !==<span style="color: #3366CC;">'image'</span> &amp;&amp; className !==<span style="color: #3366CC;">'image first'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> graphics = circle.<span style="color: #006600;">getContext</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">'2d'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; graphics.<span style="color: #006600;">fillStyle</span> = color;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; graphics.<span style="color: #006600;">beginPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; graphics.<span style="color: #006600;">arc</span><span style="color:#006600; font-weight:bold;">&#40;</span> size * .<span style="color:#800000;">5</span>, size * .<span style="color:#800000;">5</span>, size * .<span style="color:#800000;">5</span>, <span style="color:#800000;">0</span>, PI2, <span style="color: #003366; font-weight: bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; graphics.<span style="color: #006600;">closePath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; graphics.<span style="color: #006600;">fill</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; element.<span style="color: #006600;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span> circle <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; content = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">'div'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; content.<span style="color: #006600;">className</span> = <span style="color: #3366CC;">"content"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; content.<span style="color: #006600;">onSelectStart</span> = <span style="color: #003366; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; content.<span style="color: #006600;">innerHTML</span> = html;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; element.<span style="color: #006600;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>content<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>className !==<span style="color: #3366CC;">'image'</span> &amp;&amp; className !==<span style="color: #3366CC;">'image first'</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; content.<span style="color: #006600;">style</span>.<span style="color: #006600;">width</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>size - contentPadding*<span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; content.<span style="color: #006600;">style</span>.<span style="color: #006600;">left</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>size - content.<span style="color: #006600;">clientWidth</span><span style="color:#006600; font-weight:bold;">&#41;</span> / <span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> +<span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; content.<span style="color: #006600;">style</span>.<span style="color: #006600;">top</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>size - content.<span style="color: #006600;">clientHeight</span><span style="color:#006600; font-weight:bold;">&#41;</span> / <span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> +<span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> b2body = <span style="color: #003366; font-weight: bold;">new</span> b2BodyDef<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> circle = <span style="color: #003366; font-weight: bold;">new</span> b2CircleDef<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; circle.<span style="color: #006600;">radius</span> = size / <span style="color:#800000;">2</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; circle.<span style="color: #006600;">density</span> = ballDensity;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; circle.<span style="color: #006600;">friction</span> = ballFriction;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; circle.<span style="color: #006600;">restitution</span> = ballRestitution;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; b2body.<span style="color: #006600;">AddShape</span><span style="color:#006600; font-weight:bold;">&#40;</span>circle<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; b2body.<span style="color: #006600;">userData</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>element: element<span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; b2body.<span style="color: #006600;">position</span>.<span style="color: #006600;">Set</span><span style="color:#006600; font-weight:bold;">&#40;</span> Math.<span style="color: #006600;">random</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * stage<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, Math.<span style="color: #006600;">random</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * <span style="color:#006600; font-weight:bold;">&#40;</span>stage<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>-size<span style="color:#006600; font-weight:bold;">&#41;</span> + size/<span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; b2body.<span style="color: #006600;">linearVelocity</span>.<span style="color: #006600;">Set</span><span style="color:#006600; font-weight:bold;">&#40;</span> Math.<span style="color: #006600;">random</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * <span style="color:#800000;">200</span>, Math.<span style="color: #006600;">random</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * <span style="color:#800000;">200</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; bodies.<span style="color: #006600;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span> world.<span style="color: #006600;">CreateBody</span><span style="color:#006600; font-weight:bold;">&#40;</span>b2body<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>First, we create an absolutely positioned DIV that will house our Canvas tag:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-14');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-14">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> element = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">'div'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">element.<span style="color: #006600;">className</span> = className;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">element.<span style="color: #006600;">width</span> = element.<span style="color: #006600;">height</span> = size;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">element.<span style="color: #006600;">style</span>.<span style="color: #006600;">position</span> = <span style="color: #3366CC;">'absolute'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">element.<span style="color: #006600;">style</span>.<span style="color: #006600;">left</span> = -size + <span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">element.<span style="color: #006600;">style</span>.<span style="color: #006600;">top</span> = -size + <span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">element.<span style="color: #006600;">style</span>.<span style="color: #006600;">cursor</span> = <span style="color: #3366CC;">"default"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">canvas.<span style="color: #006600;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>element<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">elements.<span style="color: #006600;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span> element <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Then we draw the actual circle itself using the Canvas tag and append it to our container DIV (Note that an SVG circle created programmatically could have also been used here):</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-15');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-15">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> circle = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">'canvas'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">circle.<span style="color: #006600;">width</span> = size;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">circle.<span style="color: #006600;">height</span> = size;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>className !==<span style="color: #3366CC;">'image'</span> &amp;&amp; className !==<span style="color: #3366CC;">'image first'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;">var</span> graphics = circle.<span style="color: #006600;">getContext</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">'2d'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;graphics.<span style="color: #006600;">fillStyle</span> = color;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;graphics.<span style="color: #006600;">beginPath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;graphics.<span style="color: #006600;">arc</span><span style="color:#006600; font-weight:bold;">&#40;</span> size * .<span style="color:#800000;">5</span>, size * .<span style="color:#800000;">5</span>, size * .<span style="color:#800000;">5</span>, <span style="color:#800000;">0</span>, PI2, <span style="color: #003366; font-weight: bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;graphics.<span style="color: #006600;">closePath</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;graphics.<span style="color: #006600;">fill</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">element.<span style="color: #006600;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span> circle <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Then we create another DIV to house the HTML content itself:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-16');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-16">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">content = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">'div'</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">content.<span style="color: #006600;">className</span> = <span style="color: #3366CC;">"content"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">content.<span style="color: #006600;">onSelectStart</span> = <span style="color: #003366; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">content.<span style="color: #006600;">innerHTML</span> = html;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">element.<span style="color: #006600;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>content<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>className !==<span style="color: #3366CC;">'image'</span> &amp;&amp; className !==<span style="color: #3366CC;">'image first'</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;content.<span style="color: #006600;">style</span>.<span style="color: #006600;">width</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>size - contentPadding*<span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;content.<span style="color: #006600;">style</span>.<span style="color: #006600;">left</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>size - content.<span style="color: #006600;">clientWidth</span><span style="color:#006600; font-weight:bold;">&#41;</span> / <span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> +<span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;content.<span style="color: #006600;">style</span>.<span style="color: #006600;">top</span> = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>size - content.<span style="color: #006600;">clientHeight</span><span style="color:#006600; font-weight:bold;">&#41;</span> / <span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> +<span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Notice that we are setting content.onSelectStart to null above; this is so that when you run the mouse button over the text it doesn't select (An alternative way to do this is to use the <a href="http://hacks.mozilla.org/2009/12/pointer-events-for-html-in-firefox-3-6/">HTML pointer-events CSS property</a>).</p>
<p>Next comes code to deal with the physics of the circles, which uses <a href="http://box2d-js.sourceforge.net/">Box2D.js</a>, a JavaScript physics engine ported from Flash:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-17');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-17">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> b2body = <span style="color: #003366; font-weight: bold;">new</span> b2BodyDef<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> circle = <span style="color: #003366; font-weight: bold;">new</span> b2CircleDef<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">circle.<span style="color: #006600;">radius</span> = size / <span style="color:#800000;">2</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">circle.<span style="color: #006600;">density</span> = ballDensity;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">circle.<span style="color: #006600;">friction</span> = ballFriction;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">circle.<span style="color: #006600;">restitution</span> = ballRestitution;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">b2body.<span style="color: #006600;">AddShape</span><span style="color:#006600; font-weight:bold;">&#40;</span>circle<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">b2body.<span style="color: #006600;">userData</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>element: element<span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">b2body.<span style="color: #006600;">position</span>.<span style="color: #006600;">Set</span><span style="color:#006600; font-weight:bold;">&#40;</span> Math.<span style="color: #006600;">random</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * stage<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, Math.<span style="color: #006600;">random</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * <span style="color:#006600; font-weight:bold;">&#40;</span>stage<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>-size<span style="color:#006600; font-weight:bold;">&#41;</span> + size/<span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">b2body.<span style="color: #006600;">linearVelocity</span>.<span style="color: #006600;">Set</span><span style="color:#006600; font-weight:bold;">&#40;</span> Math.<span style="color: #006600;">random</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * <span style="color:#800000;">200</span>, Math.<span style="color: #006600;">random</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * <span style="color:#800000;">200</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">bodies.<span style="color: #006600;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span> world.<span style="color: #006600;">CreateBody</span><span style="color:#006600; font-weight:bold;">&#40;</span>b2body<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Basically, we define a circle, give it a radius, density, friction, and restitution, and then add it to our collection of shapes with a position and linear velocity. Box2D will then handle the physics and we can just take the values back out to draw things on the screen with a setInterval, which happens in the loop method:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-18');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-18">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> loop<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; delta<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> += <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">0</span> - delta<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * .<span style="color:#800000;">5</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; delta<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> += <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">0</span> - delta<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> * .<span style="color:#800000;">5</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; world.<span style="color: #006600;">m_gravity</span>.<span style="color: #006600;">x</span> = <span style="color:#800000;">0</span> <span style="color: #009900; font-style: italic;">// -(0 + delta[0]);</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; world.<span style="color: #006600;">m_gravity</span>.<span style="color: #006600;">y</span> = -<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">100</span> + delta<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; mouseDrag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; world.<span style="color: #006600;">Step</span><span style="color:#006600; font-weight:bold;">&#40;</span>timeStep, iterations<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span>i = <span style="color:#800000;">0</span>; i &lt;bodies.<span style="color: #006600;">length</span>; i++<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> body = bodies<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> element = elements<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; element.<span style="color: #006600;">style</span>.<span style="color: #006600;">left</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>body.<span style="color: #006600;">m_position0</span>.<span style="color: #006600;">x</span> - <span style="color:#006600; font-weight:bold;">&#40;</span>element.<span style="color: #006600;">width</span>&gt;&gt; <span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; element.<span style="color: #006600;">style</span>.<span style="color: #006600;">top</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>body.<span style="color: #006600;">m_position0</span>.<span style="color: #006600;">y</span> - <span style="color:#006600; font-weight:bold;">&#40;</span>element.<span style="color: #006600;">height</span>&gt;&gt; <span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color: #3366CC;">'px'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>ballRotation &amp;&amp; element.<span style="color: #006600;">tagName</span> == <span style="color: #3366CC;">'DIV'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> rotationStyle = <span style="color: #3366CC;">'rotate('</span> + <span style="color:#006600; font-weight:bold;">&#40;</span>body.<span style="color: #006600;">m_rotation0</span> * <span style="color:#800000;">57</span>.<span style="color:#800000;">2957795</span><span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color: #3366CC;">'deg)'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; element.<span style="color: #006600;">style</span>.<span style="color: #006600;">WebkitTransform</span> = rotationStyle;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; element.<span style="color: #006600;">style</span>.<span style="color: #006600;">MozTransform</span> = rotationStyle;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; element.<span style="color: #006600;">style</span>.<span style="color: #006600;">OTransform</span> = rotationStyle;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>This method gets called with a setInterval periodically. Basically, we apply a delta and a gravity at each time step; see if the mouse is being pressed down (with hooks for touch devices like the iPhone to see if a finger is being pressed down); tell the Box2D World about our gravity and delta and to make an iteration step; and finally use the computed physics values from Box2D to apply CSS3 rotation transforms on our parent DIV and move the element's CSS top and left values around the screen.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/view-source-tutorial-content-site-using-html5-canvas-css3/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JavaScript Gameboy Emulator: Memory and GPU</title>
		<link>http://ajaxian.com/archives/javascript-gameboy-emulator-memory-and-gpu</link>
		<comments>http://ajaxian.com/archives/javascript-gameboy-emulator-memory-and-gpu#comments</comments>
		<pubDate>Wed, 18 Aug 2010 11:00:50 +0000</pubDate>
		<dc:creator>Brad Neuberg</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=10041</guid>
		<description><![CDATA[Jack Vaughn posted on Ajaxian recently about a new blog series on building a Gameboy emulator using JavaScript. Now Parts II and III have been posted in the series: Part 1: The CPU Part 2: Memory Part 3: GPU Timings In the Memory section, Imran Nazar builds up a JavaScript MMU that can interpret the <a href="http://ajaxian.com/archives/javascript-gameboy-emulator-memory-and-gpu">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://ajaxian.com/wp-content/images/jsgb-mmu-map.png"><img class="aligncenter size-full wp-image-10042" title="jsgb-mmu-map" src="http://ajaxian.com/wp-content/images/jsgb-mmu-map.png" alt="" width="476" height="116" /></a></p>
<p><a href="http://ajaxian.com/archives/looking-at-js-emulator-core-for-gameboy">Jack Vaughn posted on Ajaxian recently</a> about a new blog series on building a Gameboy emulator using JavaScript. Now Parts II and III have been posted in the series:</p>
<ul><em></p>
<li><a href="http://imrannazar.com/GameBoy-Emulation-in-JavaScript:-The-CPU">Part 1: The CPU</a></li>
<li><a href="http://imrannazar.com/GameBoy-Emulation-in-JavaScript:-Memory">Part 2: Memory</a></li>
<li><a href="http://imrannazar.com/GameBoy-Emulation-in-JavaScript:-GPU-Timings">Part 3: GPU Timings</a></li>
<p></em></ul>
<p><a href="http://imrannazar.com/GameBoy-Emulation-in-JavaScript:-Memory">In the Memory section</a>, <a href="http://imrannazar.com/">Imran Nazar</a> builds up a JavaScript MMU that can interpret the different parts of the Gamboy's memory:</p>
<blockquote><p>In the previous part of this series, the computer was introduced as a processing unit, which fetches its instructions from memory. In almost every case, a computer's memory is not a simple contiguous region; the GameBoy is no exception in this regard. Since the GameBoy CPU can access 65,536 individual locations on its address bus, a "memory map" can be drawn of all the regions where the CPU has access.</p></blockquote>
<p style="text-align: center;"><a href="http://ajaxian.com/wp-content/images/2324726929_9a5ff4edf9.jpg"><img class="aligncenter size-full wp-image-10043" title="2324726929_9a5ff4edf9" src="http://ajaxian.com/wp-content/images/2324726929_9a5ff4edf9.jpg" alt="" width="226" height="300" /></a></p>
<p style="text-align: center;">[<em><a href="http://www.flickr.com/photos/20179579@N00/2324726929/">CC-A by Michael Ngilen</a></em>]</p>
<p><a href="http://imrannazar.com/GameBoy-Emulation-in-JavaScript:-GPU-Timings">In the third part</a> Imran is now ready to actually draw things to the screen, using the Canvas tag:</p>
<blockquote><p>Nintendo's internal name for the GameBoy is "Dot Matrix Game"; its display is a pixel LCD of dimensions 160x144. If each pixel in the LCD is treated as a pixel in a HTML5 <code>&lt;canvas&gt;</code>, a direct mapping can be made to a canvas of width 160 and height 144. In order to directly address each pixel in the LCD, the contents of the canvas can be manipulated as a "framebuffer": a single block of memory containing the entirety of the canvas, as a series of 4-byte RGBA values.</p></blockquote>
<p>Next in the series will be a blog post on backgrounds and patterns.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/javascript-gameboy-emulator-memory-and-gpu/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tricks From Our Flash Friends: 3D in a 2D Context</title>
		<link>http://ajaxian.com/archives/tricks-from-our-flash-friends-3d-in-a-2d-context</link>
		<comments>http://ajaxian.com/archives/tricks-from-our-flash-friends-3d-in-a-2d-context#comments</comments>
		<pubDate>Mon, 16 Aug 2010 10:00:48 +0000</pubDate>
		<dc:creator>Brad Neuberg</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=9932</guid>
		<description><![CDATA[If you've seen some of the cool work that folks like Mr. Doob or Gerard Ferrandez have done with HTML5/CSS3/SVG/etc., you've probably seen them emulating nifty 3D effects in the browser (move your mouse to pan the camera): The demo above, by Gerard, uses SVG plus various mathematical tricks to emulate 3D. Mr. Doob has <a href="http://ajaxian.com/archives/tricks-from-our-flash-friends-3d-in-a-2d-context">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>If you've seen some of the cool work that folks like <a href="http://mrdoob.com/">Mr. Doob</a> or <a href="http://www.dhteumeuleu.com/">Gerard Ferrandez</a> have done with HTML5/CSS3/SVG/etc., you've probably seen them emulating nifty 3D effects in the browser (move your mouse to pan the camera):</p>
<div><a href="http://www.dhteumeuleu.com/lab/menu-walls-3D.html"><img src="http://ajaxian.com/wp-content/images/menuwalls.png" alt="" title="menuwalls" width="417" height="327" class="aligncenter size-full wp-image-10113" /></a></div>
<p><a href="http://www.dhteumeuleu.com/menu-walls-3d/">The demo above</a>, by Gerard, uses SVG plus various mathematical tricks to emulate 3D.</p>
<p>Mr. Doob has a <a href="http://mrdoob.com/projects/three.js/examples/particles_random.html">similar demo</a> that emulates 3D but using the Canvas tag using his <a href="http://mrdoob.com/blog/post/693">Three.js library</a>:</p>
<div><a href="http://mrdoob.com/projects/three.js/examples/particles_random.html"><img src="http://ajaxian.com/wp-content/images/particles1.png" alt="" title="particles1" width="417" height="327" class="aligncenter size-full wp-image-10115" /></a></div>
<p>What both of these samples have in common is they are using special math to simulate three dimensions on a two-dimensional surface (i.e. our screen using SVG, the Canvas tag, or CSS3 Transforms).</p>
<p>I've realized recently that the Flash world is a bit ahead of us in the HTML5 world in terms of doing nifty effects using special tricks such as simulating 3D in a 2D space. I've been actually trying to go deep into learning Flash so that I can learn some of these tricks but use them in an HTML5 context.</p>
<p>I reached out to Gerard Ferrandez recently to ask him where he learned the math to do his demos, and he told me he learned them from the Flash world. <a href="http://www.kirupa.com/developer/actionscript/3dindex.htm">He pointed me to an absolutely excellent Flash tutorial series</a> that explains in depth how to do such 3D tricks in your own code. It's straightforward to learn the math but apply it in an HTML5 context. The tutorial series is very complete and easy to understand, basically explaining how to do perspective drawing, <a href="http://www.webexhibits.org/sciartperspective/raphaelperspective1.html">first invented in the Renaissance</a>. A classic perspective drawing from the Renaissance:</p>
<p><a href="http://ajaxian.com/wp-content/images/raphael-fig3-large-01.jpg"><img src="http://ajaxian.com/wp-content/images/raphael-fig3-large-01.jpg" alt="" title="raphael-fig3-large-01" width="585" height="258" class="aligncenter size-full wp-image-9943" /></a></p>
<p>Notice the lines superimposed on the painting above; shapes that are closer to the viewer are scaled larger, while shapes in the background are smaller. In addition, the location of the shapes on the painting change based on where they located along what is called the 'vanishing point'. Instead of emulating these with paint, as the Old Masters used to do, we use simple mathematics that can then determine the correct x and y coordinates on our fake 2D 'window' in order to simulate a perspective point, then draw it using SVG, Canvas, etc.:</p>
<ul>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/3dexplore.htm" class="nounderline">Exploring 3D in Flash</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/zooming.htm" class="nounderline">Zooming Figures</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/3dwireframe.htm" class="nounderline">Static View with 3D Wire Frame Boxes</a>
                                              </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/shape_camera.htm" class="nounderline">Shape Movement vs. Camera Offset</a>
                                              </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/trigonometry.htm" class="nounderline">Trigonometry</a>
                                              </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/panning.htm" class="nounderline">Panning the Camera</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/camera_panning.htm" class="nounderline">Simple Camera Panning</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/more_panning.htm" class="nounderline">Panning Camera Forward and Backward</a>
                                              </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/shading.htm" class="nounderline">Basic Shading</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/pre_rendered.htm" class="nounderline">Integration of Pre-Rendered 3D Elements</a>
                                              </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/trig_multiple_axis.htm" class="nounderline">Trigonometry and Multiple Axes</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/camera_pitch_balloon.htm" class="nounderline">Camera Pitch in Viewing Balloon Arches</a>
                                              </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/rotation_center.htm" class="nounderline">Rotation Around A Common Center</a>
                                              </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/wireframe_examples.htm" class="nounderline">Wire Frame Examples Using the Drawing API</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/shapes_fills.htm" class="nounderline">Shapes and Fills</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/backface_culling.htm" class="nounderline">Backface Culling</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/solid_pyramids.htm" class="nounderline">Solid Pyramids</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/faces_depths.htm" class="nounderline">Faces and Depths</a> </li>
<li>
                                            <a href="http://www.kirupa.com/developer/actionscript/hourglass_spaceship.htm" class="nounderline">Triangular Hourglass and Spaceship</a>
                                              </li>
</ul>
<p>As I continue learning tricks from our Flash friends but in an HTML5 context I'll keep posting here on Ajaxian.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/tricks-from-our-flash-friends-3d-in-a-2d-context/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Three search engines, one interface &#8211; 25 minutes live code</title>
		<link>http://ajaxian.com/archives/three-search-engines-one-interface-25-minutes-live-code</link>
		<comments>http://ajaxian.com/archives/three-search-engines-one-interface-25-minutes-live-code#comments</comments>
		<pubDate>Wed, 09 Dec 2009 17:44:32 +0000</pubDate>
		<dc:creator>Chris Heilmann</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Screencast]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Yahoo!]]></category>
		<category><![CDATA[YUI]]></category>
		<category><![CDATA[bing]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[mashup]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=8183</guid>
		<description><![CDATA[It is amazing how much easier it is these days to build pretty sweet mashups by using hosted services. Here's a screencast of using Yahoo, Bing and Google to build a search interface in under 25 minutes without having to read any API docs or installing SDKs by using YQL: Building a search mashup with <a href="http://ajaxian.com/archives/three-search-engines-one-interface-25-minutes-live-code">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>It is amazing how much easier it is these days to build pretty sweet mashups by using hosted services. Here's a screencast of using Yahoo, Bing and Google to build a search interface in under 25 minutes without having to read any API docs or installing SDKs by using YQL:</p>
<p><object width="450" height="309"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=8075850&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00adef&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=8075850&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00adef&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="450" height="309"></embed></object>
<p><a href="http://vimeo.com/8075850">Building a search mashup with YQL using Google, Yahoo and Bing - live :)</a> from <a href="http://vimeo.com/user574521">Christian Heilmann</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Give it a lick of paint and you have a <a href="http://icant.co.uk/goohoobi/">pretty sweet little tool</a>: </p>
<p><a href="http://icant.co.uk/goohoobi/"><img src="http://farm3.static.flickr.com/2701/4170924993_3cc418285b.jpg" width="450" alt="GooHooBi - search Google, Yahoo and Bing in one go!"/></a></p>
<p>All the <a href="http://github.com/codepo8/GooHooBi">source code is available on GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/three-search-engines-one-interface-25-minutes-live-code/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>View Source Tutorial: Sticky Notes With HTML5 and CSS3</title>
		<link>http://ajaxian.com/archives/view-source-tutorial-sticky-notes-with-html5-and-css3</link>
		<comments>http://ajaxian.com/archives/view-source-tutorial-sticky-notes-with-html5-and-css3#comments</comments>
		<pubDate>Wed, 14 Oct 2009 12:30:08 +0000</pubDate>
		<dc:creator>Brad Neuberg</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[View Source]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=7646</guid>
		<description><![CDATA[View Source is a new series where we crack open cool web sites and applications and detail how they were made, step by step. Today we will take a look at the Webkit Sticky Notes demo that was created when Webkit first landed it's HTML 5 SQL storage support: In this demo you can create <a href="http://ajaxian.com/archives/view-source-tutorial-sticky-notes-with-html5-and-css3">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>View Source is a new series where we crack open cool web sites and applications and detail how they were made, step by step.</p>
<p>Today we will take a look at the <a href="http://webkit.org/demos/sticky-notes/">Webkit Sticky Notes demo</a> that was created when Webkit first landed it's HTML 5 SQL storage support:</p>
<p><a href="http://webkit.org/demos/sticky-notes/"><img src="http://ajaxian.com/wp-content/images/stickynotes_screenshot2.png" alt="stickynotes_screenshot" title="stickynotes_screenshot" width="441" height="360" class="aligncenter size-full wp-image-7651" style="border: 1px solid black;" /></a></p>
<p><a href="http://webkit.org/demos/sticky-notes/">In this demo</a> you can create new sticky notes that persist themselves into the local SQL storage and can be accessed while offline. When a sticky note is closed it 'swooshes' offscreen with a nice animated effect.</p>
<p>Technologies used in this View Source tutorial:</p>
<ul>
<li><a href="http://www.whatwg.org/specs/web-apps/current-work/#offline">HTML5 Application Cache</a></li>
<li><a href="http://dev.w3.org/html5/webdatabase/">HTML5 Database API</a></li>
<li>CSS Transitions [<a href="http://webkit.org/blog/138/css-animation/">1</a>, <a href="http://webkit.org/blog/130/css-transforms/">2</a>]</li>
<li><a href="http://www.crockford.com/javascript/javascript.html">JavaScript OOP programming</a> &#038; <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide:Creating_New_Objects:Defining_Getters_and_Setters">Getters and Setters</a></li>
</ul>
<p>Note that the demo will only currently work in Webkit 4+ based browsers, Safari only; the technologies behind it though are beginning to arrive in Firefox and Chrome however.</p>
<p>Let's break this demo down step by step.</p>
<p><span id="more-7646"></span></p>
<h3>Is there a Doctype in the house?</h3>
<p>First we have the HTML5 doctype at the top of the page:</p>
<div class="igBar"><a href="javascript:showCodeTxt('html-34');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">HTML:</span>
<div id="html-34">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>!doctype html&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>This causes an HTML5 supporting browser to switch into HTML5 parsing mode.</p>
<h3>Tune In, Turn On, Go Offline</h3>
<p>Since we want this application to work offline, we have to provide all of the resources necessary to 'draw' this application when away from the network; i.e. we need to tell the browser where to find all of it's HTML, CSS, JavaScript, images, etc. We can't depend on the browser's cache since some resources might not be in there. Instead, we have to use the HTML5 Application Cache API. </p>
<p>To use the HTML5 Application Cache, we first provide a file named <code>StickyNotes.manifest</code> that lists all the files we will need while offline:</p>
<div class="igBar"><a href="javascript:showCodeTxt('text-35');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">TEXT:</span>
<div id="text-35">
<div>
<ol>CACHE MANIFEST<br />
#version=1<br />
deleteButton.png<br />
deleteButtonPressed.png</ol>
</div>
</div>
</div>
<p>By default, the first line of this file must have the magic words <code>CACHE MANIFEST</code>. Following this you can provide comments starting with the # character. Afterward we provide all of the files to bring offline. You do not need to provide the originating HTML page since this is included by default, though it is recommended that you do provide it in your files. In our example almost everything is self-contained within the page so all we have to grab are a few image files necessary to draw the small closing X button on each sticky note. The file names must be relative or absolute file names or URLs, but must be on the same domain as the originating page.</p>
<p>Note that your manifest file can have any file name or file extension that you want, but it <em>must</em> be served with the MIME type <code>text/cache-manifest</code> to get recognized.</p>
<p>Finally we have to point to our manifest file using the <code>manifest</code> attribute on the <code>html</code> tag:</p>
<div class="igBar"><a href="javascript:showCodeTxt('html-36');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">HTML:</span>
<div id="html-36">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html</span></a> manifest=<span style="color: #ff0000;">"StickyNotes.manifest"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>When the browser first downloads this page, it will see and grab the manifest file. It will then proceed to download all of the files given in the manifest file. Afterward, in the background, the browser will periodically re-fetch the manifest file to see if it has changed. If it has changed in <em>any</em> way (such as adding or removing a file or changing a comment, such as the <code>#version=1</code> comment above), it will then do an HTTP HEAD request on each file in the manifest file to see if those have changed. If they have changed then a file is reloaded into the offline manifest.</p>
<h3>Swoosh!</h3>
<p>Let's break down the UI and the nice swoosh effect that happens when you close a sticky note.</p>
<p>First off, each sticky note is just a <code>DIV</code> with the following styling:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-37');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-37">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.note </span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span>: <span style="color: #993333;">rgb</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">255</span>, <span style="color:#800000;">240</span>, <span style="color:#800000;">70</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span>: 250px;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span>: 10px;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span>: <span style="color: #993333;">absolute</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span>: 200px;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; -webkit-box-shadow: 0px 5px 10px rgba<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">0</span>, <span style="color:#800000;">0</span>, <span style="color:#800000;">0</span>, <span style="color:#800000;">0</span>.<span style="color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Basically, we make the background yellow; give it a height and width; give it some internall padding so the text looks nice in the middle; and then position the note absolutely. We then add a black box shadow that is 50% transparent.</p>
<p>The little close button is just two PNG images:</p>
<p><center>
<div><img src="http://ajaxian.com/wp-content/images/deleteButton.png" alt="deleteButton.png" title="deleteButton.png" width="30" height="30" class="size-full wp-image-7655" />&nbsp;<img src="http://ajaxian.com/wp-content/images/deleteButtonPressed.png" alt="deleteButtonPressed.png" title="deleteButtonPressed" width="30" height="30" class="size-full wp-image-7656" /></div>
<p></center></p>
<p>The first PNG image we only show when the mouse hovers over the corner of the sticky note using a CSS <code>.note:hover</code> pseudo-class. The second PNG image is shown when the user clicks (or 'activates' in CSS pseudo-parlance) the image:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-38');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-38">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">.closebutton<span style="color: #3333ff;">:active </span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-image</span>: <span style="color: #993333;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span>deleteButtonPressed.png<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>The cool thing about both the <code>:hover</code> and <code>:active</code> pseudo-classes is it lets you do things like this elegantly without having to use any JavaScript.</p>
<p>The main close button itself is added to the page as a background-image and positioned absolutely within the overall note DIV:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-39');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-39">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.closebutton </span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">display</span>: <span style="color: #993333;">none</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-image</span>: <span style="color: #993333;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span>deleteButton.png<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span>: 30px;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">position</span>: <span style="color: #993333;">absolute</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">left</span>: -15px;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">top</span>: -15px;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span>: 30px;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>When you click the close button you get a nice swoosh effect. This is actually done in JavaScript as follows:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-40');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-40">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">note</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">webkitTransition</span> = <span style="color: #3366CC;">'-webkit-transform '</span> + duration + <span style="color: #3366CC;">'s ease-in, opacity '</span> + duration + <span style="color: #3366CC;">'s ease-in'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">note</span>.<span style="color: #006600;">offsetTop</span>; <span style="color: #009900; font-style: italic;">// Force style recalc</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">note</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">webkitTransformOrigin</span> = <span style="color: #3366CC;">"0 0"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">note</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">webkitTransform</span> = <span style="color: #3366CC;">'skew(30deg, 0deg) scale(0)'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">note</span>.<span style="color: #006600;">style</span>.<span style="color: #006600;">opacity</span> = <span style="color: #3366CC;">'0'</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>Let's break this down. Let's first take a look at the full CSS Transition property after it would be expanded, with the duration set to 2 seconds. Let's expand the rest of the CSS after the JavaScript has been applied to make this more readable:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-41');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-41">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">-webkit-transition: -webkit-transform 2s ease-in, opacity 2s ease-in;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">-webkit-transform-origin: <span style="color:#800000;">0</span> <span style="color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">-webkit-transform: skew<span style="color:#006600; font-weight:bold;">&#40;</span>30deg, 0deg<span style="color:#006600; font-weight:bold;">&#41;</span> scale<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">opacity: <span style="color:#800000;">0</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>We want two things to happen here; first, we want a transformation to happen on our DIV that will skew the top along the X axis causing a 'shearing' look while also scaling the DIV to zero so it disappears; at the same time, we want the opacity to go from 1 to 0 so it fades over time.</p>
<p>We define the two transformations using the <code>-webkit-transform</code> property: <code>skew(30deg, 0deg)</code> skews 30 degrees along the x-axis and none along the y-axis, and <code>scale(0)</code> scales things to zero. Transformations have to work according to an origin, which we set with <code>-webkit-transform-origin</code> to the upper-left corner: <code>0 0</code>. We also define the final state of the <code>opacity</code> to be <code>0</code>.</p>
<p>The next step is to define when all of this happens. We do this in one go by setting <code>-webkit-transition</code>. We use the magic property name <code>-webkit-transform</code> to refer to the transforms we defined earlier (i.e. the skewing and scaling) and say that it will happen over 2 seconds, easing in gradually (<code>ease-in</code>). We then declare that the <code>opacity</code> property will also happen over 2 seconds and also have a nice easing in effect.</p>
<p>The one thing to notice in the JavaScript code is the <code>this.note.offsetTop</code> property; ostensibly this is there to force a fix for a Webkit bug around style recalculations. It is a bit unclear whether this is now fixed in the latest versions of Webkit.</p>
<h3><img src="http://ajaxian.com/wp-content/images/yiddish_phrase1.png" alt="yiddish_phrase" title="yiddish_phrase" width="200" height="22" class="aligncenter size-full wp-image-7668" /></h3>
<p>(That's 'JavaScript' translated into Yiddish; I couldn't come up with a good catchy head line for this section).</p>
<p>The JavaScript in this sample is well put together and uses several modern JavaScript features, so let's take a quick look at that.</p>
<p>First, each note is encapsulated into a Note class that keeps track of its DOM elements on screen; handles all mouse actions; and stores its internal state, such as its text, x and y coordinates, etc.</p>
<p>This isn't the place to teach OOP JavaScript programming, but each Note class is a standard function that extends the prototype and internally binds the DOM elements to itself to handle the mouse:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-42');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-42">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// constructor</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> Note<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;">var</span> self = <span style="color: #000066; font-weight: bold;">this</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> note = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; note.<span style="color: #006600;">className</span> = <span style="color: #3366CC;">'note'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; note.<span style="color: #006600;">addEventListener</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'mousedown'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>e<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> self.<span style="color: #006600;">onMouseDown</span><span style="color:#006600; font-weight:bold;">&#40;</span>e<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color: #003366; font-weight: bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; note.<span style="color: #006600;">addEventListener</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'click'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> self.<span style="color: #006600;">onNoteClick</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color: #003366; font-weight: bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">note</span> = note;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// etc</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>The interesting thing about this JavaScript (or <img src="http://ajaxian.com/wp-content/images/yiddish_phrase1.png" alt="yiddish_phrase" title="yiddish_phrase" width="100" height="11" />  in Yiddish) is that it uses the new JavaScript getter and setter syntax to control getting and setting all internal attributes; this make even more sense when you treat each Note as a kind of <a href="http://en.wikipedia.org/wiki/Data_access_object">Data Access Object</a> that you will store into the local SQL storage, which we will detail in the next section. Here are some of the attributes defined on the Notes class:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-43');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-43">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">Note.<span style="color: #006600;">prototype</span> = <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; get id<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"_id"</span> <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>._id = <span style="color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._id;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; set id<span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>._id = x;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; get text<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">editField</span>.<span style="color: #006600;">innerHTML</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; set text<span style="color:#006600; font-weight:bold;">&#40;</span>x<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">editField</span>.<span style="color: #006600;">innerHTML</span> = x;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// etc. </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>When dealing with a particular Note, this now means you can simply say <code>console.log(note.text)</code> for example to grab its text, without having to be exposed to the particular ways in which these values are fetched or stored.</p>
<h3>SQL Storage</h3>
<p>Finally, it's time to detail how we save and load our notes.</p>
<p>When working with the HTML5 Database, the first step is to open a database by name; note the error handling code in our sample below as well ensuring that we actually have either permission or even the ability to do storage:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-44');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-44">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">try</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>window.<span style="color: #006600;">openDatabase</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; db = openDatabase<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"NoteTest"</span>, <span style="color: #3366CC;">"1.0"</span>, <span style="color: #3366CC;">"HTML5 Database API example"</span>, <span style="color:#800000;">200000</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!db<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"Failed to open the database on disk.&nbsp; This is probably because the"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + <span style="color: #3366CC;">"version was bad or there is not enough space left in this "</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + <span style="color: #3366CC;">"domain's quota"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"Couldn't open the database.&nbsp; Please try with a WebKit nightly with this feature enabled"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color:#006600; font-weight:bold;">&#40;</span>err<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>The magic is in the <code>openDatabase</code> method. This method takes a unique name for the database (<code>"NoteTest"</code>); a version number so you can later handle upgrading a database if necessary (<code>"1.0"</code>); a human friendly name that can be shown to users if they are exploring what data is saved locally by web sites (<code>"HTML5 Database API example"</code>); and finally the size in bytes that you estimate a web application will need in total (<code>200000</code>). This last value is important; when you first open a database, the user will be prompted on whether to give your site permission with the total you request here. You should estimate the total size you want so that the user isn't pestered whenever the quota is hit. In our example we ask for 200K.</p>
<p>Before jumping into directly using the database, it's important to note some features of the HTML5 Database API. First, it is highly asynchronous, which means most of its methods require a JavaScript callback that get the results. This is an unfortunate necessity so that a web browser's UI does not 'hang' due to JavaScript doing heavy file I/O, which might happen if JavaScript is reading from a particularly large database table for example. Second, every read or write to the database must be surrounded by a transaction, which is another necessity due to the unforgiving environment of the web: a user might leave the page in the middle of a database read or write, close the browser, etc. Both of these aspects make working with the Database API a bit trickier than would otherwise be true.</p>
<p>With this in mind, let's look at code in our sample that reads all of our post-it notes into memory on page load, line by line.</p>
<p>First, we have to grab a transaction, as mentioned above; this method takes a JavaScript callback that will receive the transaction on which we can execute actual SQL:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-45');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-45">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">db.<span style="color: #006600;">transaction</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>tx<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>The <code>tx</code> result is our transaction object that we can actually start calling SQL on.</p>
<p>Next, we then grab all of our notes from a table named <code>WebKitStickyNotes</code> that was created earlier in the code. This table has several columns: a unique ID, the note text, a timestamp, and the left, top, and z-index on where to place this on the page:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-46');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-46">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">db.<span style="color: #006600;">transaction</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>tx<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;tx.<span style="color: #006600;">executeSql</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"SELECT id, note, timestamp, left, top, zindex FROM WebKitStickyNotes"</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>, </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>tx, result<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// handle result</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>tx, error<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// handle error</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>In the code snippet above, you'll see that we execute our SQL on the transaction we were handed back earlier by calling <code>executeSql</code>. We then provide the SQL to execute, which is a simple <code>SELECT</code> statement grabbing all of our notes and columns. The second argument is an empty array and is only used if we are inserting or updating values, which we will see later. The final two arguments is a JavaScript callback that will receive the results, and a JavaScript callback if an error occurs, respectively.</p>
<p>Let's look at working with the results returned by this SQL call, focusing on just the successful results callback:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-47');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-47">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i = <span style="color:#800000;">0</span>; i &lt;result.<span style="color: #006600;">rows</span>.<span style="color: #006600;">length</span>; ++i<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> row = result.<span style="color: #006600;">rows</span>.<span style="color: #006600;">item</span><span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> note = <span style="color: #003366; font-weight: bold;">new</span> Note<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; note.<span style="color: #006600;">id</span> = row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'id'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; note.<span style="color: #006600;">text</span> = row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'note'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; note.<span style="color: #006600;">timestamp</span> = row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'timestamp'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; note.<span style="color: #006600;">left</span> = row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'left'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; note.<span style="color: #006600;">top</span> = row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'top'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; note.<span style="color: #006600;">zIndex</span> = row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'zindex'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900; font-style: italic;">// code snipped</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>We basically loop over each row of the result, getting the number of rows by calling 'results.rows.length'. We grab an individual row item by calling 'result.rows.item(i)'. Once we have a SQL row result, we can treat it as a normal JavaScript object, where each column just becomes a JavaScript member property that we can fetch. For example, we can grab the <code>timestamp property by calling <code>row['timestamp']</code> or <code>row.timestamp</code>.</p>
<p>We now see where our JavaScript getters and setters come in handy; we basically just copy over the value of a row into a new Note object, and set each one like a normal property, such as <code>note.text = row['note']</code>. Under the covers our JavaScript object takes this value and updates the DOM and UI based on the new value.</p>
<p>Inserting a new Note into our table works in a similar way. Here is a snippet of code from the <code>saveAsNew</code> function:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-48');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-48">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">db.<span style="color: #006600;">transaction</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>tx<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; tx.<span style="color: #006600;">executeSql</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"INSERT INTO WebKitStickyNotes "</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ <span style="color: #3366CC;">"(id, note, timestamp, left, top, zindex) "</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ <span style="color: #3366CC;">"VALUES (?, ?, ?, ?, ?, ?)"</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>note.<span style="color: #006600;">id</span>, note.<span style="color: #006600;">text</span>, note.<span style="color: #006600;">timestamp</span>, note.<span style="color: #006600;">left</span>, </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; note.<span style="color: #006600;">top</span>, note.<span style="color: #006600;">zIndex</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>Basically, we get a transaction object again. Once we have that asynchronously we execute a standard SQL <code>INSERT</code> statement. We provide all of the new values using question marks in the SQL, and then provide the values to fill in as a separate JavaScript array. We again see our JavaScript getters making the code cleaner and more encapsulated to easily grab the values for inserting into the database, even if doing so might involve actually reading them from the DOM.</p>
<p>Creating our initial table and updating existing rows is roughly the same and can be seen yourself by looking at the <a href="http://webkit.org/demos/sticky-notes/">sticky notes demo</a>.</p>
<h3>Conclusion</h3>
<p>At this point you've seen a nice example that uses CSS Transitions to create a fancy UI; modern JavaScript coding including using the new getter and setter syntax; working with the HTML5 Application Cache to create offline web apps; and using the HTML5 Database to store your data. Have fun!</html></p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/view-source-tutorial-sticky-notes-with-html5-and-css3/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>View Source Tutorial: Fancy Web Page Using HTML5, CSS, and SVG</title>
		<link>http://ajaxian.com/archives/view-source-tutorial-fancy-web-page-using-html5-css-and-svg</link>
		<comments>http://ajaxian.com/archives/view-source-tutorial-fancy-web-page-using-html5-css-and-svg#comments</comments>
		<pubDate>Wed, 07 Oct 2009 11:30:51 +0000</pubDate>
		<dc:creator>Brad Neuberg</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[View Source]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=7553</guid>
		<description><![CDATA[I recently ran across a site that made my jaw drop when I realized it's completely made with HTML5, CSS, and SVG. It's the site for the GNU Emacs for Mac OS X release: Who ever knew GNU Emacs could look so sexy? When I think of GNU Emacs I generally imagine Richard Stallman's beard <a href="http://ajaxian.com/archives/view-source-tutorial-fancy-web-page-using-html5-css-and-svg">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>I recently ran across a site that made my jaw drop when I realized it's completely made with HTML5, CSS, and SVG. It's the site for the <a href="http://emacsformacosx.com/">GNU Emacs for Mac OS X release</a>:</p>
<p style="text-align: center;"><a href="http://emacsformacosx.com/"><img class="aligncenter size-full wp-image-7554" title="emacssite1" src="http://ajaxian.com/wp-content/images/emacssite1.png" alt="emacssite1" width="445" height="298" /></a></p>
<p>Who ever knew GNU Emacs could look so sexy? When I think of GNU Emacs I generally imagine <a href="http://stallman.org/">Richard Stallman</a>'s beard rather than the fancy site shown above.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-7556" title="stallman" src="http://ajaxian.com/wp-content/images/stallman.png" alt="stallman" width="219" height="224" /></p>
<p>Wow, I've got to get that image out of my head :) Moving on.</p>
<p>Here is what is cool about this site: it's completely using open web technologies to put things together. That's not just a big image you're seeing on the site.</p>
<p>Let's crack this thing open with a View Source tutorial and see what makes it tick so you can apply similar techniques in your own work. View Source is a new series of tutorials where we look at open web technology 'in the wild' and break them down step by step so you can learn what they are doing.</p>
<p><span id="more-7553"></span></p>
<p>First, this is an HTML 5 site with the HTML5 doctype:</p>
<div class="igBar"><a href="javascript:showCodeTxt('html-58');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">HTML:</span>
<div id="html-58">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Much of the page uses directly embedded SVG into HTML5 to achieve it's affects, and works in Firefox, Opera, and Webkit based browsers (Safari, Chrome, etc.).</p>
<p>If you do a view source on the page the first thing you will notice is all the text is truly plain text; much of the text on the page is directly in the markup, meaning that search engines will correctly extract this text and index it.</p>
<p>The nice gradient background is done with the following:</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-7557" title="emacssite2" src="http://ajaxian.com/wp-content/images/emacssite2.png" alt="emacssite2" width="85" height="237" /></p>
<p>First, we define a rectangle to fill the background:</p>
<div class="igBar"><a href="javascript:showCodeTxt('xml-59');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">XML:</span>
<div id="xml-59">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;rect</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"0"</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">width</span>=<span style="color: #ff0000;">"100"</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">"100"</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fill</span>=<span style="color: #ff0000;">"url(#background_gradient_black)"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Notice that we reference a gradient in there with <code>fill="url(#background_gradient_black)"</code>. This is defined as follows:</p>
<div class="igBar"><a href="javascript:showCodeTxt('xml-60');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">XML:</span>
<div id="xml-60">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;lineargradient</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"background_gradient_black"</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x1=<span style="color: #ff0000;">"0%"</span> y1=<span style="color: #ff0000;">"10"</span> x2=<span style="color: #ff0000;">"0%"</span> y2=<span style="color: #ff0000;">"90"</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">gradientUnits</span>=<span style="color: #ff0000;">"userSpaceOnUse"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;stop</span> <span style="color: #000066;">offset</span>=<span style="color: #ff0000;">"0%"</span>&nbsp; &nbsp;<span style="color: #000066;">stop-color</span>=<span style="color: #ff0000;">"#000"</span> <span style="color: #000066;">stop-opacity</span>=<span style="color: #ff0000;">"1"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;stop</span> <span style="color: #000066;">offset</span>=<span style="color: #ff0000;">"45%"</span>&nbsp; <span style="color: #000066;">stop-color</span>=<span style="color: #ff0000;">"#444"</span> <span style="color: #000066;">stop-opacity</span>=<span style="color: #ff0000;">"1"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;stop</span> <span style="color: #000066;">offset</span>=<span style="color: #ff0000;">"55%"</span>&nbsp; <span style="color: #000066;">stop-color</span>=<span style="color: #ff0000;">"#444"</span> <span style="color: #000066;">stop-opacity</span>=<span style="color: #ff0000;">"1"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;stop</span> <span style="color: #000066;">offset</span>=<span style="color: #ff0000;">"100%"</span> <span style="color: #000066;">stop-color</span>=<span style="color: #ff0000;">"#000"</span> <span style="color: #000066;">stop-opacity</span>=<span style="color: #ff0000;">"1"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/lineargradient<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>A few things; notice that we give this gradient an id ('background_gradient_black'). We can then later use this gradient in other elements, which we do in the background rectangle. This is a sophisticated gradient; we are essentially giving it four different colors as it does it's drawing (each of these is the 'stops' defined above).</p>
<p>To have our rectangle and gradient fill the whole page, everything is nested into an svg element with the following style block, snipped a bit for brevity:</p>
<div class="igBar"><a href="javascript:showCodeTxt('xml-61');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">XML:</span>
<div id="xml-61">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;svg</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">"width:100%; height:100%; position:fixed; top:0; left:0; z-index:1"</span><span style="font-weight: bold; color: black;">&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Basically, we have the SVG embedded in our HTML fill up the whole page and 'pin it' to the upper left of the page.</p>
<p>Let's move on to the nice buttons on the page, which when hovered over get a nice blue background:</p>
<div style="text-align: center"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="360" height="270" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="scale" value="showall" /><param name="src" value="http://codinginparadise.org/images/emacs_buttons.swf" /><embed type="application/x-shockwave-flash" width="360" height="270" src="http://codinginparadise.org/images/emacs_buttons.swf" scale="showall"></embed></object></div>
<p style="margin-top: 1em;">I really like how these were put together. First, we have a CSS style block in our directly embedded SVG as follows:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-62');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-62">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">a <span style="color: #cc00cc;">#button <span style="color:#006600; font-weight:bold;">&#123;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; fill:<span style="color: #993333;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"#button_gradient"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; stroke:grey;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">a<span style="color: #3333ff;">:hover </span><span style="color: #cc00cc;">#button <span style="color:#006600; font-weight:bold;">&#123;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; fill:<span style="color: #993333;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"#active_button_gradient"</span><span style="color:#006600; font-weight:bold;">&#41;</span> !important;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; stroke:<span style="color: #000000; font-weight: bold;">blue</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Our buttons are standard SVG rectangles with hyperlinks around them, hence the 'a #button'. Each of the buttons on the page have the ID #button and have the style above applied to them (technically they should be using a CSS class instead, so this is a mistake in this example). The buttons have an SVG fill applied to each one, and when the mouse is hovered over the button we end up triggering the 'a:hover #button' style rule which changes the fill to a different gradient and changes the stroke outline to blue.</p>
<p>Let's look at just one of the buttons to get a sense of what the SVG looks like:</p>
<div style="text-align: center; margin-bottom: 1em;"><img class="aligncenter size-full wp-image-7564" title="emacssite5" src="http://ajaxian.com/wp-content/images/emacssite5.png" alt="emacssite5" width="140" height="58" /></div>
<div class="igBar"><a href="javascript:showCodeTxt('xml-63');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">XML:</span>
<div id="xml-63">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;g</span> <span style="color: #000066;">transform</span>=<span style="color: #ff0000;">"translate(950,635)"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"small-button"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;a</span> xlink:<span style="color: #000066;">href</span>=<span style="color: #ff0000;">"/about"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;rect</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"2"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"2"</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">width</span>=<span style="color: #ff0000;">"196"</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">"71"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">rx</span>=<span style="color: #ff0000;">"15"</span> <span style="color: #000066;">ry</span>=<span style="color: #ff0000;">"15"</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">stroke-width</span>=<span style="color: #ff0000;">"2px"</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"button"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;text</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"100"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"37"</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">transform</span>=<span style="color: #ff0000;">"translate(0,10)"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">font-size</span>=<span style="color: #ff0000;">"25px"</span> <span style="color: #000066;">font-weight</span>=<span style="color: #ff0000;">"bold"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text-anchor</span>=<span style="color: #ff0000;">"middle"</span><span style="font-weight: bold; color: black;">&gt;</span></span>About<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/text<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/a<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/g<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>There's a few things going on here. First we have the group element ('g'), which acts pretty much just like grouping in Photoshop: you can group things together into a single unit as you work with them, style them, make them interactive, etc. The 'transform' attribute is a way to have a nice, simple way to draw things inside the group, and then 'translate' everything to where you want them on the page.</p>
<p>Inside the group we see a hyperlink element, just like HTML, but with the entire button inside of it hyperlinked to the 'about' page.</p>
<p>Next comes our button's rectangle. The 'rx' and 'ry' properties are a way to get rounded corners (Look! Simple rounded corners in HTML!). We then overlay our text 'About' on top of the rectangle and make it centered. The CSS we saw above will then work with this button to add the nice gradient backgrounds and the mouse over behavior.</p>
<p>Moving on, check out the Emacs 'signature'; the Apple logo, and the fancy Mac OS X. These are defined as SVG <code>symbols</code> that can be referenced and moved around the page. Each of them is essentially a symbol with an ID, filled with a bunch of gradients and path statements probably taken from a tool like <a href="http://www.inkscape.org/">Inkscape</a> or grabbed from <a href="http://commons.wikipedia.org/">Wikimedia Commons</a>.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-7565" title="emacssite6" src="http://ajaxian.com/wp-content/images/emacssite6.png" alt="emacssite6" width="400" height="128" /></p>
<p>Once they are defined elsewhere, they can be referenced using the <code>use</code> tag and each of their IDs ('#mac-os-x'), have hyperlinks attached to them, and placed on the screen where necessary; finally the whole thing is grouped together with a G tag and translated right into the page where you want it to appear:</p>
<div class="igBar"><a href="javascript:showCodeTxt('xml-64');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">XML:</span>
<div id="xml-64">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;g</span> <span style="color: #000066;">transform</span>=<span style="color: #ff0000;">"translate(100,0)"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;use</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"250"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">"500"</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">"500"</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;xlink:<span style="color: #000066;">href</span>=<span style="color: #ff0000;">"#mac-os-x"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;a</span> xlink:<span style="color: #000066;">href</span>=<span style="color: #ff0000;">"http://www.gnu.org/software/emacs/"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;use</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"240"</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">"300"</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">"300"</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xlink:<span style="color: #000066;">href</span>=<span style="color: #ff0000;">"#emacs"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/a<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;a</span> xlink:<span style="color: #000066;">href</span>=<span style="color: #ff0000;">"http://www.apple.com/macosx/"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;use</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"700"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"225"</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">"275"</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">"275"</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xlink:<span style="color: #000066;">href</span>=<span style="color: #ff0000;">"#apple-shiny"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/a<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/g<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Next, a subtle shadow is placed on the large text at the top of the screen so it falls on the large X; here's a screenshot where we zoom in to show the shadow:</p>
<p><img class="aligncenter size-full wp-image-7566" title="emacssite7" src="http://ajaxian.com/wp-content/images/emacssite7.png" alt="emacssite7" width="291" height="123" /></p>
<p>This is achieved with an SVG filter. I'm not going to show the source for this, but you can find it by searching the example page for the the element with the ID "shadow". The cool thing about this is since its just markup so you can learn from it and adapt it for your own needs (remember copyright of course). On the page we apply the shadow as follows using the filter attribute and reference it by name:</p>
<div class="igBar"><a href="javascript:showCodeTxt('xml-65');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">XML:</span>
<div id="xml-65">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;text</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"600"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"120"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">font-size</span>=<span style="color: #ff0000;">"100px"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">text-anchor</span>=<span style="color: #ff0000;">"middle"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">font-weight</span>=<span style="color: #ff0000;">"bold"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">fill</span>=<span style="color: #ff0000;">"white"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">filter</span>=<span style="color: #ff0000;">"url(#shadow)"</span><span style="font-weight: bold; color: black;">&gt;</span></span>Emacs For Mac OS X<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/text<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Finally, we have the little Pure Emacs! label on the lower-left:</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-7567" title="emacssite8" src="http://ajaxian.com/wp-content/images/emacssite8.png" alt="emacssite8" width="220" height="221" /></p>
<p>First, the star is just a symbol with an ID again, drawn with a bunch of paths either drawn by hand or grabbed from a clip art library or drawing tool. We use the &lt;use&gt; tags to reference this and orient its size and position. Then, we draw all of our text and group them together, rotating and scaling the entire thing at once to turn it to the side: <code>transform="translate(80,80) rotate(-30) scale(.9)"</code></p>
<div class="igBar"><a href="javascript:showCodeTxt('xml-66');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">XML:</span>
<div id="xml-66">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;g</span> <span style="color: #000066;">transform</span>=<span style="color: #ff0000;">"translate(100,550)"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;use</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">"150"</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">"150"</span> xlink:<span style="color: #000066;">href</span>=<span style="color: #ff0000;">"#star"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/g<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;g</span> <span style="color: #000066;">transform</span>=<span style="color: #ff0000;">"translate(80,80) rotate(-30) scale(.9)"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;text</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"-40"</span> <span style="color: #000066;">font-size</span>=<span style="color: #ff0000;">"30px"</span> <span style="color: #000066;">font-weight</span>=<span style="color: #ff0000;">"bold"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">text-anchor</span>=<span style="color: #ff0000;">"middle"</span><span style="font-weight: bold; color: black;">&gt;</span></span>Pure<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/text<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;text</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"-15"</span> <span style="color: #000066;">font-size</span>=<span style="color: #ff0000;">"30px"</span> <span style="color: #000066;">font-weight</span>=<span style="color: #ff0000;">"bold"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">text-anchor</span>=<span style="color: #ff0000;">"middle"</span><span style="font-weight: bold; color: black;">&gt;</span></span>Emacs!<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/text<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;text</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"+10"</span> <span style="color: #000066;">font-size</span>=<span style="color: #ff0000;">"20px"</span> <span style="color: #000066;">font-weight</span>=<span style="color: #ff0000;">"bold"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text-anchor</span>=<span style="color: #ff0000;">"middle"</span><span style="font-weight: bold; color: black;">&gt;</span></span>No Extras!<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/text<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;text</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">"+30"</span> <span style="color: #000066;">font-size</span>=<span style="color: #ff0000;">"18px"</span> <span style="color: #000066;">font-weight</span>=<span style="color: #ff0000;">"bold"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">text-anchor</span>=<span style="color: #ff0000;">"middle"</span><span style="font-weight: bold; color: black;">&gt;</span></span>No Nonsense!<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/text<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/g<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Two cool things about all of this; first, on Webkit based browsers all the text is selectable. Also, the page truly scales based on the monitor it's on. If you are a full page on a 40" monitor it will scale to the full size and remain legible and beautiful, as well as scale down on the iPhone. That's cool.</p>
<p>I love this example because it shows a few things. First, that SVG is definitely not dead; this works on every browser but IE -- that doesn't sound like a dead technology to me. Second, this example is much better done with SVG than the Canvas tag. I'm a huge fan of the Canvas tag; in fact I originally liked it much better than SVG when it came out a few years ago. I used to be an SVG-skeptic as well, until I realized making a choice between the two was like being forced to choose as a programmer just Hashtables or Linked Lists; they both are needed. Finally, this sample is in a form that makes it easy for others to learn from this markup to adapt it to their own needs. Have fun!</svg></p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/view-source-tutorial-fancy-web-page-using-html5-css-and-svg/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Writing a JavaScript Tetris; Lessons learned from a Ruby chap</title>
		<link>http://ajaxian.com/archives/writing-a-javascript-tetris-lessons-learned-from-a-ruby-chap</link>
		<comments>http://ajaxian.com/archives/writing-a-javascript-tetris-lessons-learned-from-a-ruby-chap#comments</comments>
		<pubDate>Mon, 02 Feb 2009 13:18:12 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=5852</guid>
		<description><![CDATA[We often get games sent our way, and try to keep those posts for Fridays. This one is different though. Thomas Kjeldahl Nilsson didn't just write another Tetris clone in JavaScript, he documented his experience. He posted a series of articles on the various steps, and not only do you learn how to build a <a href="http://ajaxian.com/archives/writing-a-javascript-tetris-lessons-learned-from-a-ruby-chap">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>We often get games sent our way, and try to keep those posts for Fridays. This one is different though. Thomas Kjeldahl Nilsson didn't just write another Tetris clone in JavaScript, he documented his experience. He posted a series of articles on the various steps, and not only do you learn how to build a nice Tetris game, but you get to see how to develop nice testable code. Thomas comes from the Ruby world and it shows.</p>
<p>Take some time to poke through his series on JavaScript Tetris:</p>
<ol>
<li><a href="http://kjeldahlnilsson.net/blog/?p=71">Rationale</a></li>
<li><a href="http://kjeldahlnilsson.net/blog/?p=72">Planning</a></li>
<li><a href="http://kjeldahlnilsson.net/blog/?p=73">Infrastructure</a></li>
<li><a href="http://kjeldahlnilsson.net/blog/?p=74">Graphics &#038; Input</a></li>
<li><a href="http://kjeldahlnilsson.net/blog/?p=75">The Life Of A Piece</a></li>
<li><a href="http://kjeldahlnilsson.net/blog/?p=77">Lights, Action, Music!</a></li>
<li><a href="http://kjeldahlnilsson.net/blog/?p=76">Gameplay</a></li>
<li><a href="http://kjeldahlnilsson.net/blog/?p=78">Javascript Tetris Pt 8: Post Mortem &#038; References</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/writing-a-javascript-tetris-lessons-learned-from-a-ruby-chap/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Becoming More Productive With JavaScript and Vim Screencast</title>
		<link>http://ajaxian.com/archives/becoming-more-productive-with-javascript-and-vim-screencast</link>
		<comments>http://ajaxian.com/archives/becoming-more-productive-with-javascript-and-vim-screencast#comments</comments>
		<pubDate>Fri, 30 Jan 2009 11:29:53 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Dojo]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=5840</guid>
		<description><![CDATA[Matthew Russell has created a nice screencast showing how to be more productive in Vim: I’ve been doing some reflecting this week on how I can work smarter (instead of harder), and one of the things I came up with was adding a few more tools to my Vim repertoire. I spend more than half <a href="http://ajaxian.com/archives/becoming-more-productive-with-javascript-and-vim-screencast">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>Matthew Russell has created a nice <a href="http://dojotdg.zaffra.com/2009/01/becoming-more-productive-with-dojo-and-vim-screencast/">screencast showing how to be more productive in Vim</a>:</p>
<blockquote>
<p>I’ve been doing some reflecting this week on how I can work smarter (instead of harder), and one of the things I came up with was adding a few more tools to my Vim repertoire. I spend more than half of my engineering time in <a href="http://vim.org" target="_blank">Vim</a> (the other half usually being in a web browser), so I figured that a few minutes here and there would eventually add up in a big way.</p>
<p>In hopes of inspiring you to do the same, I put together a short <a href="http://dojotdg.zaffra.com/wp-content/uploads/2009/01/dojo_vim.mov" target="_blank">screencast</a> (~4mins; 14.5MB QuickTime file) that talks you through how to generate a custom tags file for Dojo’s API and the keystrokes to put it to work. Although I’m specifically using Dojo, I think this technique should probably apply to a lot of other toolkits as well assuming that they define API call in a consistent manner that can be approximated by a regex.</p>
<p>But like anything else with Vim, there are always multiple ways of accomplishing the very same thing, so I make no guarantees that there aren’t simpler ways of getting this done — but I can say that this way gets the job done, and is pretty easy to get working on your own system.</p>
<p>By the way, here are links to the <a href="http://dojotdg.zaffra.com/wp-content/uploads/2009/01/generateTags.sh">generateTags.sh</a> script and the <a href="http://dojotdg.zaffra.com/wp-content/uploads/2009/01/tags" target="_blank">tags</a> file (for Core) mentioned in the screencast. I’ve slightly tweaked the tags file to remove duplicate tag names and a few things that weren’t really parts of the public API (regexes are obviously imperfect heuristics). I can’t say that the tags file may not be missing a few API calls, but tags are easy enough to add in manually if you do notice any omissions.</p>
</blockquote>
<p>How do you extend your tools to give you a hammer that is suited to your work?</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/becoming-more-productive-with-javascript-and-vim-screencast/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
<enclosure url="http://dojotdg.zaffra.com/wp-content/uploads/2009/01/dojo_vim.mov" length="15191455" type="video/quicktime" />
		</item>
		<item>
		<title>Ajaxian Featured Tutorial: Show/Hide Login Panel Built with MooTools</title>
		<link>http://ajaxian.com/archives/ajaxian-featured-tutorial-showhide-login-panel-built-with-mootools</link>
		<comments>http://ajaxian.com/archives/ajaxian-featured-tutorial-showhide-login-panel-built-with-mootools#comments</comments>
		<pubDate>Tue, 19 Aug 2008 15:27:04 +0000</pubDate>
		<dc:creator>Rey Bango</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=4129</guid>
		<description><![CDATA[Conserving screen real-estate while still providing good content to the user has always been a challenge for designers and developers and while larger screen dimensions are becoming more prominent, it's still important to take full advantage of the space available to you. Jeeremie over at Web Kreation came up with a very cool method of <a href="http://ajaxian.com/archives/ajaxian-featured-tutorial-showhide-login-panel-built-with-mootools">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>Conserving screen real-estate while still providing good content to the user has always been a challenge for designers and developers and while larger screen dimensions are becoming more prominent, it's still important to take full advantage of the space available to you. Jeeremie over at <a href="http://web-kreation.com/">Web Kreation</a> came up with <a href="http://web-kreation.com/index.php/tutorials/nice-login-and-signup-panel-using-mootools-12/">a very cool method of display a login panel</a> using <a href="http://mootools.net/download">MooTools v1.2's</a> built-in effects capabilities:</p>
<blockquote><p>Some of you were wondering what script I used to show/hide the login panel on top of this page (or in my latest WordPress theme: “Night Transition”). In this tutorial, we will see how to create a similar login/signup panel for your website using Mootools 1.2.</p></blockquote>
<p><a href="http://web-kreation.com/index.php/tutorials/nice-login-and-signup-panel-using-mootools-12/"><img src="http://ajaxian.com/wp-content/uploads/rb_moo_showhide.jpg" alt="" title="rb_moo_showhide" width="300" height="49" class="alignnone size-medium wp-image-4133" /></a></p>
<p>Jeeremie walks you through the steps of dropping this code into your site and provides the final source code as well to make the whole process painless. <a href="http://web-kreation.com/demos/login_form_mootools_1.2/">The end result</a> is a very nice and intuitive slide down login panel which provides a nice balance of functionality and preserving screen real-estate.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/ajaxian-featured-tutorial-showhide-login-panel-built-with-mootools/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Is &#8220;finally&#8221; the answer to all IE6 memory leak issues?</title>
		<link>http://ajaxian.com/archives/is-finally-the-answer-to-all-ie6-memory-leak-issues</link>
		<comments>http://ajaxian.com/archives/is-finally-the-answer-to-all-ie6-memory-leak-issues#comments</comments>
		<pubDate>Mon, 09 Jun 2008 15:22:05 +0000</pubDate>
		<dc:creator>Chris Heilmann</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/archives/is-finally-the-answer-to-all-ie6-memory-leak-issues</guid>
		<description><![CDATA[Hedger Wang has been scanning a lot of Chinese blogs lately for solutions to IE6 and memory leak issues. One of the things he stumbled upon is a pretty nifty way of nulling the objects to stop memory leaks by using the try ... finally construct. So instead of this solution which leaks memory: PLAIN <a href="http://ajaxian.com/archives/is-finally-the-answer-to-all-ie6-memory-leak-issues">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.hedgerwow.com">Hedger Wang</a> has been scanning a lot of Chinese blogs lately for solutions to IE6 and memory leak issues. One of the things he stumbled upon is a pretty nifty way of <code>null</code>ing the objects to stop memory leaks by using the <code>try ... finally</code> construct. So instead of this solution which leaks memory:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-69');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-69">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> createButton<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> obj = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"button"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">innerHTML</span> = <span style="color: #3366CC;">"click me"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">onclick</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//handle onclick</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">onmouseover</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//handle onmouseover</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> obj;<span style="color: #009900; font-style: italic;">//return a object which has memory leak problem in IE6</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> dButton = document.<span style="color: #006600;">getElementsById</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"d1"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>createButton<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//skipped....</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>You can use the following which doesn't:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-70');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-70">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> createButton<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> obj = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"button"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">innerHTML</span> = <span style="color: #3366CC;">"click me"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">onclick</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//handle onclick</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">onmouseover</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//handle onmouseover</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//this helps to fix the memory leak issue</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">try</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> obj;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color: #000066; font-weight: bold;">finally</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; obj = <span style="color: #003366; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> dButton = document.<span style="color: #006600;">getElementsById</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"d1"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>createButton<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>More demos, proof of concept examples and the "finally" explanation is available on Hedger's blog: <a href="http://www.hedgerwow.com/360/dhtml/ie6_memory_leak_fix/">Finally, the alternative fix for IE6's memory leak is available</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/is-finally-the-answer-to-all-ie6-memory-leak-issues/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Ajaxian Featured Tutorial: Coda Slider Effect</title>
		<link>http://ajaxian.com/archives/ajaxian-featured-tutorial-coda-slider-effect</link>
		<comments>http://ajaxian.com/archives/ajaxian-featured-tutorial-coda-slider-effect#comments</comments>
		<pubDate>Tue, 03 Jun 2008 14:28:30 +0000</pubDate>
		<dc:creator>Rey Bango</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=3712</guid>
		<description><![CDATA[The effect of "sliding panels" has become extremely popular for categorizing &#038; displaying large amounts of data on a single page. One of the most notable implementations of this effect was done by Panic to display all of the features and benefits of their Coda web development IDE. Since then, many implementations of this effect <a href="http://ajaxian.com/archives/ajaxian-featured-tutorial-coda-slider-effect">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>The effect of "sliding panels" has become extremely popular for categorizing &#038; displaying large amounts of data on a single page. One of the most notable implementations of this effect was done by <a href="http://www.panic.com/">Panic</a> to display all of the features and benefits of their <a href="http://www.panic.com/coda/">Coda web development IDE</a>. Since then, many implementations of this effect have been built and most are now referred to as "Coda sliders" since they provide very similar scrolling capabilities.</p>
<p>Remy Sharp of <a href="http://jqueryfordesigners.com">jQuery for Designers</a> has created a new screencast and tutorial on <a href="http://jqueryfordesigners.com/coda-slider-effect/">how to create a coda slider effect using </a><a href="http://jquery.com">jQuery</a>:</p>
<blockquote><p>Although Panic didn't really invent the effect, the sliding panels on the Coda is great implementation of this effect.<br />
This article will pick apart the pieces required to create the effect, and how to better it.</p></blockquote>
<p><a href="http://jqueryfordesigners.com/coda-slider-effect/"><img src="http://ajaxian.com/wp-content/images/rb_codaremy.gif" alt="" border="0" width="452" height="212"/></a></p>
<p>Remy's tutorial aimed for several goals:</p>
<ol>
<li>Degrades perfectly without JavaScript enabled</li>
<li>Sliding panels effect without hogging browser CPU</li>
<li>Next and previous buttons added using JavaScript because they hold no use without JavaScript</li>
<li>Hitting the page with a specific hash (i.e. page.html#preview) shows the right tab, and highlights the right navigation</li>
<li>Any link on the page that refers back to a panel should trigger the effect and highlight the right navigation - this should happen <em>without</em> any extra work</li>
</ol>
<p>The tutorial is very detailed walking you through the markup of the page, use of several jQuery plugins, setting up the navigation, and handling the events for the slider. Along with that, Remy created a screencast, available in both <a href="http://jqueryfordesigners.com/media/coda-slider.mov">Quicktime </a>and <a href="http://jqueryfordesigners.com/video.php?f=coda-slider.flv">Flash</a> formats, that explain how everything is put together.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/ajaxian-featured-tutorial-coda-slider-effect/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ajaxian Featured Tutorial: Writing Your First YUI Application</title>
		<link>http://ajaxian.com/archives/ajaxian-featured-tutorial-writing-your-first-yui-application</link>
		<comments>http://ajaxian.com/archives/ajaxian-featured-tutorial-writing-your-first-yui-application#comments</comments>
		<pubDate>Thu, 15 May 2008 11:36:35 +0000</pubDate>
		<dc:creator>Rey Bango</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Yahoo!]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=3655</guid>
		<description><![CDATA[Eric Miraglia has posted a great tutorial on how to build your first YUI application. He runs you through the steps of creating a simple application that leverages YUI's AutoComplete Control to create a site-search form powered by the Yahoo!'s Search web service. The tutorial is a great walkthrough of both how to build the <a href="http://ajaxian.com/archives/ajaxian-featured-tutorial-writing-your-first-yui-application">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>Eric Miraglia has posted a great tutorial on <a href="http://www.insideria.com/2008/05/writing-your-first-yui-applica.html">how to build your first YUI application</a>. He runs you through the steps of creating a simple application that leverages <a href="http://developer.yahoo.com/yui/">YUI</a>'s AutoComplete Control to create a site-search form  powered by the Yahoo!'s Search web service.</p>
<p><a href="http://www.insideria.com/2008/05/writing-your-first-yui-applica.html"><img src="http://ajaxian.com/wp-content/images/rb_sitesearchui.png" alt="" border="0" width="535" height="342"/></a></p>
<p>The tutorial is a great walkthrough of both how to build the application and also leverage YUI's extensive documentation. It also touches on some great points such as:</p>
<ul>
<li>How to configure a YUI implementation and put YUI on the page</li>
<li>How to set up the markup for a progressively-enhanced YUI widget</li>
<li>How to instantiate and configure a YUI widget</li>
<li>How to subscribe to and make use of the "custom evens" provided by a YUI widget</li>
<li>And how to override default behavior to get a bespoke implementation that maps to our requirements.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/ajaxian-featured-tutorial-writing-your-first-yui-application/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The seven rules of pragmatic progressive enhancement</title>
		<link>http://ajaxian.com/archives/the-seven-rules-of-pragmatic-progressive-enhancement</link>
		<comments>http://ajaxian.com/archives/the-seven-rules-of-pragmatic-progressive-enhancement#comments</comments>
		<pubDate>Wed, 07 May 2008 22:58:24 +0000</pubDate>
		<dc:creator>Chris Heilmann</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Unobtrusive JS]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://ajaxian.com/archives/the-seven-rules-of-pragmatic-progressive-enhancement</guid>
		<description><![CDATA[I've been talking about progressive enhancement here before and got a lot of flak in comments about it. It seemed that there was a general misunderstanding of progressive enhancement and unobtrusive scripting as a "passing fad" or "backward facing rather than being innovative". I was asked by a design agency in London to go there <a href="http://ajaxian.com/archives/the-seven-rules-of-pragmatic-progressive-enhancement">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>I've been talking about progressive enhancement here before and got a lot of flak in comments about it. It seemed that there was a general misunderstanding of progressive enhancement and unobtrusive scripting as a "passing fad" or "backward facing rather than being innovative". </p>
<p>I was asked by a design agency in London to go there and give a brown bag presentation (during lunch break) on the matter and took this as an opportunity to write up reasons and examples for progressive enhancement concentrating more on the why than on the how. </p>
<p>The gist would be to say: enhancing a product progressively means you'll always deliver a working product - as you have no idea how your product can fail in certain environments, you plan for it to fail. This ties in nicely with the <a href="http://agilemanifesto.org/">agile manifesto</a> - you always deliver software that works. </p>
<p>In my talk I came up with seven "rules" of pragmatic progressive enhancement:</p>
<ol>
<li>Separate as much as possible</li>
<li>Build on things that work</li>
<li>Generate dependent markup</li>
<li>Test for everything before you apply it</li>
<li>Explore the environment</li>
<li>Load on demand</li>
<li>Modularize code</li>
</ol>
<p>I've taken these ideas and backed them up with benefits you get by following them and code examples in a full article: <a href="http://icant.co.uk/articles/pragmatic-progressive-enhancement/">Pragmatic Progressive Enhancement</a>. </p>
<p>The article is licensed with Creative Commons and uses YUI in the example scripts, feel free to translate, remix and create examples using other libraries.</p>
<p>You can also read the slides on slideshare:</p>
<div class="slideshare"><a href="http://www.slideshare.net/cheilmann/pragmatic-progressive-enhancement?src=embed#progressiveenhancement-1210189562112719-9">View 'Pragmatic Progressive Enhancement' on SlideShare</a><script src="http://chrisslidesharehacks.googlecode.com/files/previewer2.js"></script></div>
<p>Pending the quality of the recording, there'll also be a video available sooner or later.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/the-seven-rules-of-pragmatic-progressive-enhancement/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ajaxian Featured Tutorial: Using YSlow for Performance Analysis</title>
		<link>http://ajaxian.com/archives/ajaxian-featured-tutorial-using-yslow-for-performance-analysis</link>
		<comments>http://ajaxian.com/archives/ajaxian-featured-tutorial-using-yslow-for-performance-analysis#comments</comments>
		<pubDate>Mon, 05 May 2008 15:14:55 +0000</pubDate>
		<dc:creator>Rey Bango</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=3619</guid>
		<description><![CDATA[Kristopher William Zyp has written a post on how to use YSlow to analyze the performance of JavaScript applications. To understand what aspects of a Web application you need to improve, you must properly analyze the components of the application. This article looks at how you can use the Firebug extension to Firefox and the <a href="http://ajaxian.com/archives/ajaxian-featured-tutorial-using-yslow-for-performance-analysis">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>Kristopher William Zyp has written a post on <a href="http://www.ibm.com/developerworks/web/library/wa-aj-perform/?ca=dgr-lnxw01FasterAjax">how to use YSlow to analyze the performance of JavaScript applications</a>. </p>
<blockquote><p>To understand what aspects of a Web application you need to improve, you must properly analyze the components of the application. This article looks at how you can use the Firebug extension to Firefox and the YSlow add-on to instrument a Web application. After you install these tools, connect to the site that you are developing and click YSlow on the Firefox status bar. This opens the YSlow interface in Firebug. Now click the Performance button. YSlow performs an analysis of your application and provides a report on the different parts of the network transfer time of your application, as Figure 1 shows.</p></blockquote>
<p>Most of the concepts mentioned are derived from the <a href="http://developer.yahoo.com/performance/rules.html">10 rules defined by Yahoo!</a> for better web application performance but Kristopher breaks down some of the concepts into examples and provides explanation on how to interpret the data. The explanation of the FireBug profiler is especially helpful to those just coming into the Ajax development space and want a better understanding of how to optimize their code:</p>
<p><a href="http://www.ibm.com/developerworks/web/library/wa-aj-perform/?ca=dgr-lnxw01FasterAjax"><img src="http://ajaxian.com/wp-content/images/rb_firebugprofile.jpg" alt="" border="0" width="560" height="406"/></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/ajaxian-featured-tutorial-using-yslow-for-performance-analysis/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ajaxian Featured Tutorial: Simple Save Message Using MooTools</title>
		<link>http://ajaxian.com/archives/ajaxian-featured-tutorial-simple-save-message-using-mootools</link>
		<comments>http://ajaxian.com/archives/ajaxian-featured-tutorial-simple-save-message-using-mootools#comments</comments>
		<pubDate>Tue, 04 Mar 2008 13:54:00 +0000</pubDate>
		<dc:creator>Rey Bango</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=3399</guid>
		<description><![CDATA[It's been awhile since we've put up an Ajaxian Featured Tutorial and so we're going to get back into the swing of things with a nice, simple tutorial using MooTools. Giving users feedback during a "save" process is a very good idea. It allows the user to feel a sense of confidence that the site <a href="http://ajaxian.com/archives/ajaxian-featured-tutorial-simple-save-message-using-mootools">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>It's been awhile since we've put up an <em>Ajaxian Featured Tutorial</em> and so we're going to get back into the swing of things with a nice, simple tutorial using <a href="http://mootools.net">MooTools</a>.</p>
<p>Giving users feedback during a "save" process is a very good idea. It allows the user to feel a sense of confidence that the site is responding and their data is being processed. While we're at it, why not make it look good as well? <a href="http://woork.blogspot.com/2008/03/nice-ajax-effect-for-message-box-using.html">Antonio Lupetti  has written a short tutorial</a> which does just that.</p>
<blockquote><p>My friend David asked to me how to implement a message box which appears when an user submit a form and disappear (with a nice fade effect after some seconds) when a generic Ajax request is completed.</p></blockquote>
<p>In the image below, Antonio has described the sequence of effects:</p>
<p><a href="http://woork.blogspot.com/2008/03/nice-ajax-effect-for-message-box-using.html"><img src="http://ajaxian.com/wp-content/images/rb_effectchain.gif" alt="" border="0" width="402" height="102"/></a></p>
<p>To break it down, when the user submits the form, a message box will appear first giving the user an indicator that the save is in progress followed by a message to let them know that the save process has completed. The fade-out effect is very cool window dressing. </p>
<p>Antonio leveraged the <a href="http://mootools.net">MooTools JavaScript</a> library for this tutorial which, apart from making the code a trivial task, already includes their "fx" module which makes adding nice effects very easy. </p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-72');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-72">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script type=<span style="color: #3366CC;">"text/javascript"</span>&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">window.<span style="color: #006600;">addEvent</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'domready'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> box = $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'box'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> fx = box.<span style="color: #006600;">effects</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>duration: <span style="color:#800000;">1000</span>, transition: Fx.<span style="color: #006600;">Transitions</span>.<span style="color: #006600;">Quart</span>.<span style="color: #006600;">easeOut</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'save_button'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">addEvent</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'click'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">box.<span style="color: #006600;">style</span>.<span style="color: #006600;">display</span>=<span style="color: #3366CC;">"block"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">box.<span style="color: #006600;">setHTML</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'Save in progress...'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">/* AJAX Request here... */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">fx.<span style="color: #006600;">start</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">chain</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">box.<span style="color: #006600;">setHTML</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'Saved!'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">start</span>.<span style="color: #006600;">delay</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">1000</span>, <span style="color: #000066; font-weight: bold;">this</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color: #3366CC;">'opacity'</span> : <span style="color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">chain</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">box.<span style="color: #006600;">style</span>.<span style="color: #006600;">display</span>=<span style="color: #3366CC;">"none"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">start</span>.<span style="color: #006600;">delay</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">0100</span>, <span style="color: #000066; font-weight: bold;">this</span>, <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color: #3366CC;">'opacity'</span> : <span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/script&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Antonio has <a href="http://woork.bravehost.com/chainMootools/index.html">created a demo</a> to show off the results.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/ajaxian-featured-tutorial-simple-save-message-using-mootools/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Ajaxian Featured Tutorial: Ajax for Chat</title>
		<link>http://ajaxian.com/archives/ajaxian-featured-tutorial-ajax-for-chat</link>
		<comments>http://ajaxian.com/archives/ajaxian-featured-tutorial-ajax-for-chat#comments</comments>
		<pubDate>Thu, 06 Dec 2007 13:40:42 +0000</pubDate>
		<dc:creator>Rey Bango</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=3087</guid>
		<description><![CDATA[Ever wanted to build a chat module for your application? Jack Herrington shows you how in this tutorial on the IBM Developerworks site. Learn to build a chat system into your Web application with Asynchronous JavaScriptâ„¢ + XML (Ajax) and PHP. Your customers can talk to you and to each other about the content of <a href="http://ajaxian.com/archives/ajaxian-featured-tutorial-ajax-for-chat">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to build a chat module for your application? <a href="http://www.ibm.com/developerworks/xml/library/x-ajaxxml8/index.html?ca=drs-#author">Jack Herrington</a> shows you how in <a href="http://www.ibm.com/developerworks/xml/library/x-ajaxxml8/index.html?ca=drs-">this tutorial on the IBM Developerworks site</a>.</p>
<blockquote><p>Learn to build a chat system into your Web application with Asynchronous JavaScriptâ„¢ + XML (Ajax) and PHP. Your customers can talk to you and to each other about the content of the site without having to download or install any special instant-messaging software.</p></blockquote>
<p>While not exactly Meebo, the tutorial does provide the foundation for building your own little chat app and uses the powerful <a href="http://prototypejs.org">Prototype library</a> for it's client-side code.</p>
<p><a href="http://www.ibm.com/developerworks/xml/library/x-ajaxxml8/index.html?ca=drs-"><img src="http://ajaxian.com/wp-content/images/rb_ajaxchat.jpg" alt="" border="0" width="400" height="352"/></a></p>
<p>Here is some of the code that Jack listed in the tutorial. The full <a href="http://www.ibm.com/developerworks/xml/library/x-ajaxxml8/index.html?ca=drs-#download">code for the tutorial can be found here</a>.</p>
<div class="igBar"><a href="javascript:showCodeTxt('language-74');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">LANGUAGE:</span>
<div id="language-74">
<div>
<ol>
&lt;?php<br />
if ( array_key_exists( 'username', $_POST ) ) {<br />
&nbsp; $_SESSION['user'] = $_POST['username'];<br />
}<br />
$user = $_SESSION['user'];<br />
?&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;&lt;title&gt;&lt;?php echo( $user ) ?&gt; - Chatting&lt;/title&gt;<br />
&lt;script src=&quot;prototype.js&quot;&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;</p>
<p>&lt;div id=&quot;chat&quot; style=&quot;height:400px;overflow:auto;&quot;&gt;<br />
&lt;/div&gt;</p>
<p>&lt;script&gt;<br />
function addmessage()<br />
{<br />
&nbsp; new Ajax.Updater( 'chat', 'add.php',<br />
&nbsp; {<br />
&nbsp; &nbsp; &nbsp;method: 'post',<br />
&nbsp; &nbsp; &nbsp;parameters: $('chatmessage').serialize(),<br />
&nbsp; &nbsp; &nbsp;onSuccess: function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp;$('messagetext').value = '';<br />
&nbsp; &nbsp; &nbsp;}<br />
&nbsp; } );<br />
}<br />
&lt;/script&gt;</p>
<p>&lt;form id=&quot;chatmessage&quot;&gt;<br />
&lt;textarea name=&quot;message&quot; id=&quot;messagetext&quot;&gt;<br />
&lt;/textarea&gt;<br />
&lt;/form&gt;</p>
<p>&lt;button onclick=&quot;addmessage()&quot;&gt;Add&lt;/button&gt;</p>
<p>&lt;script&gt;<br />
function getMessages()<br />
{<br />
&nbsp; new Ajax.Updater( 'chat', 'messages.php', {<br />
&nbsp; &nbsp; onSuccess: function() { window.setTimeout( getMessages, 1000 ); }<br />
&nbsp; } );<br />
}<br />
getMessages();<br />
&lt;/script&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p>
</ol>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/ajaxian-featured-tutorial-ajax-for-chat/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Ajaxian Featured Tutorial: JavaScript Basics</title>
		<link>http://ajaxian.com/archives/ajaxian-featured-tutorial-javascript-basics</link>
		<comments>http://ajaxian.com/archives/ajaxian-featured-tutorial-javascript-basics#comments</comments>
		<pubDate>Thu, 29 Nov 2007 11:30:02 +0000</pubDate>
		<dc:creator>Rey Bango</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=3057</guid>
		<description><![CDATA[I have to say that at one point, I truly thought that JavaScript was using some type of "black magic". Things such as closures really threw me for a loop and I was fortunate to have some good folks to walk me through some of the tougher concepts. Not everyone is as lucky and thankfully, <a href="http://ajaxian.com/archives/ajaxian-featured-tutorial-javascript-basics">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>I have to say that at one point, I truly thought that JavaScript was using some type of "black magic". Things such as closures really threw me for a loop and I was fortunate to have some good folks to walk me through some of the tougher concepts. Not everyone is as lucky and thankfully, we have developers like Christian Heilmann who continue to put out great postings that cover a broad range of topics and experience levels.</p>
<p>In his latest posting, <a href="http://www.wait-till-i.com/2007/11/27/javascript-shortcut-notations-that-shouldnt-be-black-magic-to-the-average-developer/">Christian outlines certain JavaScript shortcut notations</a> which make understanding specific JS techniques a whole lot easier. For example, when dealing with objects, there's the involved way of defining objects:</p>
<p><em><br />
var links = new Object();<br />
links['Cute Overload'] = 'http://cuteoverload.com';<br />
links['I can has cheeseburger'] = 'http://icanhascheezburger.com';<br />
links['Pencils at dawn'] = 'http://pencilsatdawn.wordpress.com';<br />
links['Hobotopia'] = 'http://apelad.blogspot.com';<br />
</em></p>
<p>and then there's the easier way using object literals:<br />
<em><br />
var links = {<br />
  'Cute Overload' : 'http://cuteoverload.com',<br />
  'I can has cheeseburger' : 'http://icanhascheezburger.com',<br />
  'Pencils at dawn' : 'http://pencilsatdawn.wordpress.com',<br />
  'Hobotopia' : 'http://apelad.blogspot.com' // < -- again, no comma!<br />
}<br />
</em></p>
<p>Christian provides <a href="http://www.wait-till-i.com/2007/11/27/javascript-shortcut-notations-that-shouldnt-be-black-magic-to-the-average-developer/">plenty of great examples</a> that should substantially help new JavaScript developers. </em></p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/ajaxian-featured-tutorial-javascript-basics/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

