<?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>BlogmyQuery - BMQ &#187; Javascript</title>
	<atom:link href="http://blogmyquery.com/index.php/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogmyquery.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 15:17:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to adjust an iframe elementâ€™s height to fit its content</title>
		<link>http://blogmyquery.com/index.php/2011/12/how-to-adjust-an-iframe-elementae%e2%84%a2s-height-to-fit-its-content/</link>
		<comments>http://blogmyquery.com/index.php/2011/12/how-to-adjust-an-iframe-elementae%e2%84%a2s-height-to-fit-its-content/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 08:06:31 +0000</pubDate>
		<dc:creator>Roger Johansson</dc:creator>
				<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.456bereastreet.com/archive/201112/how_to_adjust_an_iframe_elements_height_to_fit_its_content/</guid>
		<description><![CDATA[In an ideal world there would always be a clean way of displaying data supplied by a third party on your site. Two examples would be getting the data in JSON or XML format from a Web Service and having an API to code against. But you donâ€™t alway...]]></description>
			<content:encoded><![CDATA[<p class="preamble">In an ideal world there would always be a clean way of displaying data supplied by a third party on your site. Two examples would be getting the data in JSON or XML format from a Web Service and having an API to code against. But you donâ€™t always have any of those options.</p>

<p>Sometimes the only way of incorporating data from a third party is by loading it in an <code>iframe</code> element. A few examples are financial reports, e-commerce applications, and ticket booking applications. Using an <code>iframe</code> is not ideal for many reasons, one of which is that it can make multiple sets of scrollbars appear on the page. Not only does it look ugly, it also makes the site less user-friendly. But there is a workaround.</p><p><a href="http://www.456bereastreet.com/archive/201112/how_to_adjust_an_iframe_elements_height_to_fit_its_content/">Read full post</a></p><p>Posted in <a href="http://www.456bereastreet.com/archive/categories/javascript/" rel="tag">JavaScript</a>, <a href="http://www.456bereastreet.com/archive/categories/usability/" rel="tag">Usability</a>.</p><p>Copyright Â© <a href="http://www.456bereastreet.com/">Roger Johansson</a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/ArraBJwN4OE8zL-nktBh582onsQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/ArraBJwN4OE8zL-nktBh582onsQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ArraBJwN4OE8zL-nktBh582onsQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/ArraBJwN4OE8zL-nktBh582onsQ/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/456bereastreet?a=1FEAp_9wLiA:7fK5zikHKuc:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=1FEAp_9wLiA:7fK5zikHKuc:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=bcOpcFrp8Mo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=1FEAp_9wLiA:7fK5zikHKuc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=1FEAp_9wLiA:7fK5zikHKuc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=1FEAp_9wLiA:7fK5zikHKuc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=1FEAp_9wLiA:7fK5zikHKuc:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/456bereastreet/~4/1FEAp_9wLiA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/12/how-to-adjust-an-iframe-elementae%e2%84%a2s-height-to-fit-its-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto-Save User&#8217;s Input In Your Forms With HTML5 and Sisyphus.js</title>
		<link>http://blogmyquery.com/index.php/2011/12/auto-save-users-input-in-your-forms-with-html5-and-sisyphus-js/</link>
		<comments>http://blogmyquery.com/index.php/2011/12/auto-save-users-input-in-your-forms-with-html5-and-sisyphus-js/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 19:16:48 +0000</pubDate>
		<dc:creator>Alexander Kaupanin</dc:creator>
				<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://mgmt.smashingmagazine.com/?p=120009</guid>
		<description><![CDATA[<table width="650">
  <tr>
    <td width="650">
      <div>
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=1" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=1" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=2" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=2" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=3" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=3" border="0" alt="" />
        </a>
      </div>
    </td>
  </tr>
</table><p><em><strong>Editorâ€™s note</strong>: This article is the third in our new series that introduces new, useful and freely available tools and techniques, developed and released by active members of the Web design community. The first article covered <a href="http://coding.smashingmagazine.com/2011/10/12/prefixfree-break-free-from-css-prefix-hell/">PrefixFree</a>; the second introduced <a href="http://coding.smashingmagazine.com/2011/10/25/rapid-prototyping-for-any-device-with-foundation/">Foundation</a>, a responsive framework that helps you build prototypes and production code. This time, weâ€™re presenting Sisyphus.js, a library developed by Alexander Kaupanin to provide Gmail-like client-side drafts and a bit more.</em></p>

<p>Have you ever been filling out a long form online or writing an eloquent and spirited comment when suddenly the browser crashes? Or perhaps you closed the browser tab accidentally, or your Internet connection cuts off, or the electricity goes down (and, being ever obedient to Murphyâ€™s Law, you had no backup power supply). If not, then youâ€™re lucky. But no one is protected from such minor catastrophes.</p>

<p><a href="http://coding.smashingmagazine.com/2011/12/05/sisyphus-js-client-side-drafts-and-more/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/11/make-everything-better.jpg" alt="screenshot" width="500" height="500" /></a></p>

<p>Imagine the storm of emotions felt by a user who had to add just a bit more information before submitting a form and then loses all data. Horrible, huh? Now, if only there was a way to recover that data, rather than undertake a <a href="http://en.wikipedia.org/wiki/Sisyphus">Sisyphean</a> pursuit.</p>]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=1" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=1" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=2" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=2" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=3" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=3" border="0" alt="" /><br />
        </a>
      </div>
</td>
</tr>
</table>
<p><em><strong>Editorâ€™s note</strong>: This article is the third in our new series that introduces new, useful and freely available tools and techniques, developed and released by active members of the Web design community. The first article covered <a href="http://coding.smashingmagazine.com/2011/10/12/prefixfree-break-free-from-css-prefix-hell/">PrefixFree</a>; the second introduced <a href="http://coding.smashingmagazine.com/2011/10/25/rapid-prototyping-for-any-device-with-foundation/">Foundation</a>, a responsive framework that helps you build prototypes and production code. This time, weâ€™re presenting Sisyphus.js, a library developed by Alexander Kaupanin to provide Gmail-like client-side drafts and a bit more.</em></p>
<h4>What Problem Needs Solving?</h4>
<p>Have you ever been filling out a long form online or writing an eloquent and spirited comment when suddenly the browser crashes? Or perhaps you closed the browser tab accidentally, or your Internet connection cuts off, or the electricity goes down (and, being ever obedient to Murphyâ€™s Law, you had no backup power supply). If not, then youâ€™re lucky. But no one is protected from such minor catastrophes.</p>
<p><a href="http://www.flickr.com/photos/bjornmeansbear/5081930704/sizes/m/in/set-72157624427149887/"><img title="Make Everything Better" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/11/make-everything-better.jpg" alt="screenshot" width="500" height="500" /></a><br />
<em>(Image: <a href="http://www.flickr.com/photos/bjornmeansbear/5081930704/sizes/m/in/set-72157624427149887/">Kristian Bjornard</a>)</em></p>
<p>Imagine the storm of emotions felt by a user who had to add just a bit more information before submitting a form and then loses all data. Horrible, huh? Now, if only there was a way to recover that data, rather than undertake a <a href="http://en.wikipedia.org/wiki/Sisyphus">Sisyphean</a> pursuit.</p>
<h4>Existing Solutions</h4>
<p>One common solution is to write oneâ€™s comments in a local document, saving the file periodically, and then copying and pasting the text into the form once itâ€™s complete. Some forms also allow you to save your draft by clicking a button, but not all forms have this feature, and itâ€™s not the most convenient solution. The product that does this best is Gmail, with its auto-save feature for drafts: just type away, and all of the content is stored automatically, without you even needing to press a button.</p>
<p>After releasing Sisyphus.js, I learned of Lazarus, an extension for Firefox and Chrome that helps to recover form data. But browser plugins lead to an even bigger problem: distribution. Some users donâ€™t have a clue what a browser extension is â€” many users donâ€™t, in fact, which makes this approach inadequate on a large scale.</p>
<p>The people with a direct line to users are Web developers themselves. So, addressing the problem of user input at the stage of development seems more practical than expecting users to add to their skyscraper of extensions.</p>
<h3>A Solution: Sisyphus.js</h3>
<p>Implementing Gmail-like auto-saving of drafts is not straightforward at all. I wanted the solution to be simple and easy to use, which would rule out the use of server-side magic.</p>
<p>The result is an unassuming script that stores form data to the local storage of the userâ€™s browser and restores it when the user reloads or reopens the page or opens the page in a new tab. The data is cleared from local storage when the user submits or resets the form.</p>
<h4>How to Use It</h4>
<p>Implementing Sisyphus.js is pretty simple. Just select which forms youâ€™d like to protect:</p>
<pre class="brush: js">$('#form1, #form2').sisyphus();</pre>
<p>Or protect all forms on the page:</p>
<pre class="brush: js">$('form').sisyphus();</pre>
<p>The following values are the defaults but are customizable:</p>
<pre class="brush: js">{
customKeyPrefix: '',
timeout: 0,
onSave: function() {},
onRestore: function() {},
onRelease: function() {}
}</pre>
<p>Letâ€™s break these options down:</p>
<ul>
<li><code>customKeyPrefix</code><br />
An addition to key in local storage details in order to store the values of form fields.</li>
<li><code>timeout</code><br />
The interval, in seconds, after which to save data. If set to <code>0</code>, it will save every time a field is updated.</li>
<li><code>onSave</code><br />
A function that fires every time data is saved to local storage.</li>
<li><code>onRestore</code><br />
A function that fires when a formâ€™s data is restored from local storage. Unlike <code>onSaveCallback</code>, it applies to the whole form, not individual fields.</li>
<li><code>onRelease</code><br />
A function that fires when local storage is cleared of stored data.</li>
</ul>
<p>Even after Sisyphus.js has been implemented in a form, you can apply it to any other form and the script wonâ€™t create redundant instances, and it will use the same options. For example:</p>
<pre class="brush: js">// Save form1 data every 5 seconds
$('#form1').sisyphus( {timeout: 5 } );

â€¦

// If you want to protect second form, too
$('#form2').sisyphus( {timeout: 10} )

// Now the data in both forms will be saved every 10 seconds</pre>
<p>Of course, you can change options on the fly:</p>
<pre class="brush: js">var sisyphus = $('#form1').sisyphus();

â€¦

// If you decide that saving by timeout would be better
$.sisyphus().setOptions( {timeout: 15} );

â€¦

// Or
sisyphus.setOptions( {timeout: 15} );</pre>
<h4>Usage Details</h4>
<p><strong>Requirements:</strong> Sisyphus.js requires jQuery version 1.2 or higher.</p>
<p><strong>Browser support:</strong></p>
<ul>
<li>Chrome 4+,</li>
<li>Firefox 3.5+,</li>
<li>Opera 10.5+,</li>
<li>Safari 4+,</li>
<li>IE 8+,</li>
<li>It also works on Android 2.2 (both the native browser and Dolphin HD). Other mobile platforms have not been tested.</li>
</ul>
<p><strong>Download the script:</strong> <a href="http://simsalabim.github.com/sisyphus/">Sisyphus.js and the demo</a> are hosted on GitHub; the minified version is about 3.5 KB. A <a href="https://github.com/simsalabim/sisyphus/issues?labels=feature">road map</a> and <a href="https://github.com/simsalabim/sisyphus/issues?labels=">issue tracker</a> are also available.</p>
<p><em>(al)</em></p>
<hr />
<p><small>Â© Alexander Kaupanin for <a href="http://www.smashingmagazine.com">Smashing Magazine</a>, 2011.</small></p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/12/auto-save-users-input-in-your-forms-with-html5-and-sisyphus-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Create Web Animations With Paper.js</title>
		<link>http://blogmyquery.com/index.php/2011/11/how-to-create-web-animations-with-paper-js/</link>
		<comments>http://blogmyquery.com/index.php/2011/11/how-to-create-web-animations-with-paper-js/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 16:14:53 +0000</pubDate>
		<dc:creator>Zack Grossbart</dc:creator>
				<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://mgmt.smashingmagazine.com/?p=119556</guid>
		<description><![CDATA[<table width="650">
  <tr>
    <td width="650">
      <div>
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=1" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=1" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=2" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=2" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=3" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=3" border="0" alt="" />
        </a>
      </div>
    </td>
  </tr>
</table><p>The Web is just starting to use animation well. For years, animated GIFs and Flash ruled. Text moved and flashed, but it was never seamless. Animations had boxes around them like YouTube videos. HTML5 canvas changes everything about Web animation.</p>

<a href="http://coding.smashingmagazine.com/2011/11/21/create-web-animations-with-paperjs/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/11/Dandelion.jpg" /></a>

<p>The canvas element makes it possible to integrate drawings and animations with the rest of your page. You can combine them with text and make animations interactive. This drawing mechanism is powerful, but very low-level. <strong>Animations get more power and need less coding</strong> when you combine the canvas tag with higher-level libraries such as Paper.js. This article introduces HTML5 animation and walks you through creating an animation of dandelion seeds blowing in the wind.</p>]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=1" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=1" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=2" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=2" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=3" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=3" border="0" alt="" /><br />
        </a>
      </div>
</td>
</tr>
</table>
<p>The Web is just starting to use animation well. For years, animated GIFs and Flash ruled. Text moved and flashed, but it was never seamless. Animations had boxes around them like YouTube videos. HTML5 <code>canvas</code> changes everything about Web animation.</p>
<p>The <code>canvas</code> element makes it possible to integrate drawings and animations with the rest of your page. You can combine them with text and make animations interactive. This drawing mechanism is powerful, but very low-level.</p>
<p>Animations get more power and need less coding when you combine the <code>canvas</code> tag with higher-level libraries such as <a href="http://paperjs.org/">Paper.js</a>. This article introduces HTML5 <a href="http://paperjs.org/tutorials/animation/creating-animations/">animation</a> and walks you through creating an animation of dandelion seeds blowing in the wind.</p>
<h3>Neat Is Easy, But Messy Is Hard</h3>
<p>Computers love clean. They make spreadsheets, do statistics and plot multivariate curves; they always color inside the lines.</p>
<p>In the real world, even simple things are messy. Leaves falling from trees, water splashing â€” all the little interactions around us feel simple because weâ€™re used to them; but little bursts of wind are actually messy and unpredictable.</p>
<p>For this article, weâ€™ll animate dandelion seeds blowing in the breeze.</p>
<p>Dandelions are tricky because we all know what they look like: weâ€™ve touched them and blown their seeds off. Commonplace objects produce instant recognition and feelings. I donâ€™t have to tell you what dandelions are â€” you just know. Dandelions are a chaos of seeds piled on top of each other.</p>
<p><a href="http://commons.wikimedia.org/wiki/File:Taraxacum_seed_3.jpg"><img title="Messy Dandelion Seeds" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/messy_seeds2.jpg" alt="screenshot" width="450" height="450" /></a></p>
<p><em>(Image: <a href="http://commons.wikimedia.org/wiki/User:Arnoldius">Arnoldius</a>)</em></p>
<p>Our dandelion animation will never reproduce the complexity of the real thing, and it will work better if we donâ€™t try: make it too close to real and it will feel funny. Instead, weâ€™ll create a stylized dandelion that makes the right impression without all of the details.</p>
<p><a href="http://zgrossbart.github.com/Dandelion/"><img title="See the animation running and edit the code" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/basic_dandelion.jpg" alt="screenshot" width="403" height="417" /></a></p>
<h3>Paper.js</h3>
<p>Drawing simple shapes with the <code>canvas</code> tag, without any special drawing libraries, is easy. Create your <code>canvas</code>:</p>
<pre class="brush: html">&#60;canvas id="canvas" width="300" height="300"&#62;&#60;/canvas&#62;</pre>
<p>Then add a little JavaScript.</p>
<pre class="brush: javascript">// Get our canvas
var canvas = $('#canvas')[0].getContext("2d");

// Draw a circle
canvas.beginPath();
canvas.arc(100, 100, 15, 0, Math.PI*2, true); 

// Close the path
canvas.closePath();

// Fill it in
canvas.fill();</pre>
<p><img title="Circle" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/circle.png" alt="screenshot" width="360" height="295" /></p>
<p><a href="http://blog.nihilogic.dk/2009/02/html5-canvas-cheat-sheet.html">Cheat sheets for canvas</a> show you the basics, but when you get into more serious drawing, youâ€™ll want a higher-level library, such as <a href="http://paperjs.org/">Paper.js</a>.</p>
<p>Paper.js is a JavaScript library for drawings and animations. Itâ€™s based largely on <a href="http://scriptographer.org/">Scriptographer</a>, a scripting language for <a href="http://en.wikipedia.org/wiki/Adobe_Illustrator">Adobe Illustrator</a>. You can <a href="http://paperjs.org/tutorials/getting-started/using-javascript-directly/">write JavaScript with Paper.js</a>, but most of the time youâ€™ll be working with a JavaScript variant called PaperScript.</p>
<p>Paper.js calls itself â€œ<a href="http://paperjs.org/about/">The Swiss Army Knife of Vector Graphics Scripting</a>,â€� and the â€œ<a href="http://paperjs.org/features/#vector-geometry">vector</a>â€� part is important.</p>
<p>There are two basic types of graphics, <a href="http://en.wikipedia.org/wiki/Vector_graphics">vectorized</a> and <a href="http://en.wikipedia.org/wiki/Raster_graphics">rasterized</a>. Rasterized graphics are like the pictures you take with your camera: big rectangles with maps denoting the color of each pixel. Enlarge them and youâ€™ll get blurry dots.</p>
<p>Vector graphics are like connect-the-dots pictures: theyâ€™re sets of lines and shapes that give instructions on how to draw the image at any size. Using vector graphics, you can make an image of the letter Z really big and it will still look sharp. If you turned it into a rasterized graphic by taking a picture of it and then blowing it up, the letter would get all blurry.</p>
<p><img title="Raster vs. Vector" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/rastervector.png" alt="" width="402" height="181" /></p>
<p>Vector graphics libraries are perfect for animation because they make resizing, rotating and moving objects easy. Theyâ€™re also much faster, because the program has instructions for drawing each object instead of needing to figure it out.</p>
<p>The <a href="http://paperjs.org/examples/">Paper.js examples page</a> shows some of the amazing things you can do with vectorized graphics.</p>
<p>The dandelion is a complete functioning example, and you can see it all running on the <a href="http://zgrossbart.github.com/Dandelion/">example page</a>. You can also change the code by clicking the â€œEditâ€� button, see your changes live, and copy and paste the code to your own website. Over the course of the article, weâ€™ll explain each part of the code in turn, but please note that in order to run the code yourself, you will need to head over to the example page and copy and paste it to your own environment.</p>
<h3>Drawing Our Dandelion</h3>
<p>The first step is to import our JavaScript and PaperScript files.</p>
<pre class="brush: html">&#60;script src="paper.js" type="text/javascript" charset="utf-8"&#62;&#60;/script&#62;
&#60;script type="text/paperscript" canvas="canvas" src="dandelion.pjs" id="script"&#62;&#60;/script&#62;</pre>
<p>The PaperScript code for running the animation is declared as <code>text/paperscript</code>. Now weâ€™re ready to start drawing.</p>
<p>The first part of our dandelion is the stem. The stem is the green arc, with a circle on the top for the bulb. Weâ€™ll make both shapes with a <a href="http://paperjs.org/reference/path">path</a>, a list of shapes, points and lines that the browser is instructed to display.</p>
<p>Paths are the basic building blocks of animation. They render lines, curves and polygons. You can also fill them in to make complex shapes. Our path looks like this:</p>
<pre class="brush: javascript">var path = new Path();
path.strokeColor = '#567e37';
path.strokeWidth = 5;

var firstPoint = new Point(0, 550);
path.add(firstPoint);

var throughPoint = new Point(75, 400);
var toPoint = new Point(100, 250);
path.arcTo(throughPoint, toPoint);</pre>
<p>Our path is an arc, so it needs three points: the start, the end and a midpoint to arc through. Three points are enough to define any arc we need. The <code>arcTo</code> function draws the line between them. The path item also supports styling information, such as stroke color and stroke width; <code>#567e37</code> and <code>5</code> will make our arcing line green and thick. Paper.js supports the same color definitions as CSS.</p>
<p>We can add a few more items to make it all easier to see:</p>
<pre class="brush: javascript">path.fullySelected = true;

var circle = new Path.Circle(throughPoint, 5);
circle.fillColor = '#CC0000';</pre>
<p>Fully selecting the path will display some lines to show us the arc; the red circle shows us where the through point is.</p>
<p><img title="Stem Paths" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/stem_paths.png" alt="screenshot" width="360" height="295" /></p>
<p>The stem ends with a circle to show the bulb of the flower and give us a place to attach all of the seeds. Circles are much easier in Paper.js than in direct <code>canvas</code>.</p>
<pre class="brush: javascript">var bulb = new Path.Circle(toPoint, 10);
bulb.fillColor = '#567e37';</pre>
<p>One line of code draws our circle, one more makes it green, and now weâ€™re ready to add our seeds.</p>
<h3>Drawing The Seeds</h3>
<p>Each seed has a bulb, a little stem and a wispy part on top.</p>
<p><a href="http://commons.wikimedia.org/wiki/File:Dandelionseed.JPG"><img title="Dandelion seed" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/dandelionseed.jpg" alt="screenshot" width="450" height="450" /></a></p>
<p><em>(Image: <a href="http://commons.wikimedia.org/wiki/User:Hmbascom">Hmbascom</a>)</em></p>
<p>Our seed starts with a small oval for the bulb and an arc for the stem. The oval is a rectangle with rounded corners:</p>
<pre class="brush: javascript">var size = new Size(4, 10);
var rectangle = new Rectangle(p, size);
var bottom = new Path.Oval(rectangle);
bottom.fillColor = '#d0aa7b';</pre>
<p>The seed stem is another arc, but this one is much thinner than the flower stem:</p>
<pre class="brush: javascript">var stem = new Path();
stem.strokeColor = '#567e37';
stem.strokeWidth = 1;
stem.add(new Point(p.x + 2, p.y));

var throughPoint = new Point(p.x + 4, p.y - height / 2);
var toPoint = new Point(p.x + 3, p.y - height);
stem.arcTo(throughPoint, toPoint);</pre>
<p>The wisps are more arcs with a circle at the end of each line. Each seed has a random number of wisps that start at the top of the stem arc and curve out in different directions. Randomness makes them look a little bit messy and thus more natural. Each seed gets a random number of wisps, between 4 and 10.</p>
<pre class="brush: javascript">for (var i = 0; i &#60; random(4, 10); i++) {
    path = new Path();
    path.strokeColor = '#fff3c9';
    path.strokeWidth = 1;

    var p1 = new Point(p.x, p.y);
    path.add(new Point(p1.x + 2, p1.y + 2));

    // Each flutter extends a random amount up in the air
    var y = random(1, 5);

    // We draw every other stem on the right or the left so they're
    // spaced out in the seed.
    if (i % 2 == 0) {
        throughPoint = new Point(p1.x + random(1, 3), p1.y - y);
        toPoint = new Point(p1.x + random(5, 35), p1.y - 20 - y);
    } else {
        throughPoint = new Point(p1.x - random(1, 3), p1.y - y);
        toPoint = new Point(p1.x - random(5, 35), p1.y - 20 - y);
    }

    path.arcTo(throughPoint, toPoint);

    // Now we put the circle at the tip of the flutter.
    circle = new Path.Circle(toPoint, 2);
    circle.fillColor = '#fff3c9';
}</pre>
<p>Now that weâ€™ve drawn the seed, we need to manage it; later, weâ€™ll want to move and rotate it. The seed is made up of a lot of parts, and we donâ€™t want to have to manage each one separately. Paper.js has a nice <a href="http://paperjs.org/reference/group">group</a> object. Groups associate a set of objects together so that we can manipulate them all at once.</p>
<pre class="brush: javascript">var group = new Group();
group.addChild(bottom);
group.addChild(stem);

this.group = group;</pre>
<p>The last step is to package our seed into a reusable object called <code>Seed</code>. We add all of the code weâ€™ve been writing to a new function with the name <code>Seed</code> and add a function to create the initial variables. This example calls that function <code>create</code>, but you can name it anything you want.</p>
<pre class="brush: javascript">function Seed() {

    this.create = function (/*Point*/ p, /*boolean*/ shortStem) {
    â€¦</pre>
<p>The <code>create</code> function draws the seed at the specified <a href="http://paperjs.org/reference/point">Point</a>, and the <code>shortStem</code> boolean tells us whether this is a short stem. Weâ€™ll look at short-stemmed seeds a little later.</p>
<p>These types of functions donâ€™t work as <a href="http://en.wikipedia.org/wiki/Constructor_(object-oriented_programming)">constructors</a> in JavaScript, but are supported in PaperScript.</p>
<pre class="brush: javascript">var seed = new Seed()
seed.create(new Point(100, 100), false);</pre>
<p>Our seeds will look like this when we draw them:</p>
<p><img title="Dandelion seed" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/seed.png" alt="screenshot" width="360" height="295" /></p>
<p>The <code>Seed</code> object draws our random dandelion seeds. Now we can add them to our flower.</p>
<h3>Adding A Little Chaos</h3>
<p>The seeds will look better when we space them out around the circle of our dandelion bulb to feel like a halo of seeds. The bulb is a circle, and the circle is a path, so we can get each point on the path.</p>
<pre class="brush: javascript">var bulb = new Path.Circle(toPoint, 10); bulb.fillColor = '#567e37';

var angle = 360 / bulb.length;
var seeds = [];

for (var i = 0; i &#60; bulb.length; i++) {
    var seed = new Seed()
    seed.create(bulb.getPointAt(i));

    // Rotate each seed so that it points out from the bulb
    seed.rotate(i * angle);
    seeds.push(seed);
}</pre>
<p>This will make a circle of seeds around the bulb but leave a space in the middle. Weâ€™ll add a few more seeds to fill in the center. Weâ€™re giving the center seeds short stems so that they show the white of the wisps more than the beige of the stems.</p>
<pre class="brush: javascript">for (var i = 0; i &#60; 18; i++) {
    var seed = new Seed()
    var point = new Point(toPoint.x + random(-3, 3),
                          toPoint.y + random(-3, 3));
    seed.create(new Point(toPoint), true);
    seed.rotate(random(0, 360));
    seeds.push(seed);
}</pre>
<p>The seeds in the middle will bunch randomly and make our dandelion look nicely messy. Now we can make them blow off.</p>
<h3>Animating The Seeds</h3>
<p>Wind pushes seeds in complex patterns, and two seeds will never blow off the same way. We want to make them look real, so weâ€™ll need a little more randomness.</p>
<p>Reproducing real wind is much too complicated, so weâ€™ll make the seeds float off in a random-looking pattern. Each seed is assigned a random point on the right side of the screen as a final destination:</p>
<pre class="brush: javascript">this.dest = new  Point(1800, random(-300, 1100));</pre>
<p>The <code>rotateMove</code> function pushes each seed toward its destination point and rotates it. We can work with our Seed object as a group to rotate and move it with one function.</p>
<pre class="brush: javascript">this.rotateMove = function(/*int*/ angle) {
    if (this.group.position.x &#60; 850 &#38;&#38; this.group.position.y &#60; 650) {
        var vector = this.dest - this.group.position;
        this.group.position += vector / 150;

        this.angle += angle;
        this.group.rotate(angle);
    } else {
        this.isOffScreen = true
    }
}</pre>
<p>This function will move the seed until itâ€™s off the screen. Calling <code>rotateMove</code> for each frame of our animation will make the seed float across the screen.</p>
<p>Paper.js gives us an easy way to make animations with the <code>onFrame</code> function; when we implement <code>onFrame</code>, Paper.js will call it for every frame of our animation. With each frame, we iterate over each seed and move it across the screen.</p>
<pre class="brush: javascript">function onFrame(event) {
    for (var i = 0; i &#60; seedCount; i++) {
        if (!seeds[i].isOffscreen()) {
            seeds[i].rotateMove(random(2, 4));
        }
    }
}</pre>
<p>The seeds slide and rotate a little closer to the destination point with each frame of the animation. Starting all of the seeds at the same point and ending them far apart makes them space out nicely as they move.</p>
<p><img title="Dandelion seeds offscreen" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/dandelion_seed_offscreen2.png" alt="screenshot" width="500" /></p>
<p>We donâ€™t want all of the seeds to fall off at once, so weâ€™ll use a timer to make them drift away.</p>
<pre class="brush: javascript">function start() {
    var id = setInterval(function() {
        seedCount++;
        if (seedCount === seeds.length) {
            clearInterval(id);
        }
    }, 1000);
}</pre>
<p>The timer waits for one second before releasing the next seed, giving our dandelion a nice floaty feel.</p>
<p>Some green grass and blue sky as a background image for our <code>canvas</code> puts it all into context. Now we have a dandelion with seeds floating on the breeze.</p>
<p><a href="http://zgrossbart.github.com/Dandelion"><img title="See the animation running and edit the code" src="http://coding.smashingmagazine.com/wp-content/uploads/2011/10/dandelion.jpg" alt="screenshot" width="500" /></a></p>
<p>See the dandelion <a href="http://zgrossbart.github.com/Dandelion/">running here</a>. You can edit and run the source code as part of the animation or download it from the <a href="https://github.com/zgrossbart/Dandelion">dandelion GitHub page</a>.</p>
<h3>Paper.js In The Real World</h3>
<p>Paper.js has some impressive examples and a nice coding model, but you should know a few gotchas before using it on your website.</p>
<h4>It Doesnâ€™t Work In Old Browsers</h4>
<p>All Paper.js drawings use the <code>canvas</code> tag and require HTML5. This means that you need Internet Explorer 9+, Firefox 4+, Safari 5+ or Chrome. If your website must support older browsers, then you wonâ€™t be able to use <code>canvas</code>.</p>
<p>Thereâ€™s no way around this requirement; if you need older browsers, youâ€™re out of luck. As the Paper.js website says, â€œ<a href="http://paperjs.org/about/#browser-support">Letâ€™s go forward!</a>.â€�</p>
<h4>Performance Can Be Slow</h4>
<p>Paper.js can make a browser grind to a halt even if the browser supports HTML5. Pixar renders Buzz and Woody on giant server farms â€” all you get is your userâ€™s cheap MacBook.</p>
<p>Not only are laptops slower than server clusters, but browsers make things worse by rendering the <code>canvas</code> tag with the <a href="http://en.wikipedia.org/wiki/CPU">CPU</a> instead of the <a href="http://en.wikipedia.org/wiki/GPU">GPU</a>. Games like Halo and Rage take advantage of the graphics processor on your video card to render rocket launchers and mutants. The CPU is less efficient with graphics, so the same computer that handles complex video games smoothly can make floating dandelion seeds look slow and jerky.</p>
<p>Make sure to test all of your animations with slower hardware, and watch the CPU usage. Use groups to minimize the calculations, and be very careful about what you do in each invocation of the <code>onFrame</code> function.</p>
<h4>Mobile Devices Are Slower</h4>
<p>Mobile performance is even worse. Most mobile devices support <code>canvas</code>, but they are mostly too slow to render <code>canvas</code> animations well. Even more powerful devices, like the iPad 2, canâ€™t handle the dandelion seeds smoothly.</p>
<h4>It Doesnâ€™t Support Object-Level Events</h4>
<p>Other drawing libraries, such as SVG (see below), support object-level mouse and keyboard events. Those events make it easy to respond when a path or a polygon is clicked, hovered over or touched.</p>
<p>The <code>canvas</code> tag doesnâ€™t support object-level events. Paper.js has some basic functionality for <a href="http://paperjs.org/examples/hit-testing/">hit testing</a>, but itâ€™s very low-level. You can listen for <a href="http://paperjs.org/tutorials/interaction/mouse-tool-events/">mouse</a> and <a href="http://paperjs.org/tutorials/interaction/keyboard-interaction/">keyboard</a> events on the whole canvas, but youâ€™ll need to handle mapping those events to individual controls.</p>
<h3>What About SVG?</h3>
<p>The <a href="http://en.wikipedia.org/wiki/SVG">SVG</a> (Scalable Vector Graphics) specification was defined over 10 years ago, but came to the forefront with support libraries such as <a href="http://raphaeljs.com/">RaphaÃ«l.js</a>, which make it easy to generate SVG images with JavaScript. SVG is powerful, works well for smaller images, and is supported all the way back to Internet Explorer 7 with conversion to <a href="http://en.wikipedia.org/wiki/VML">VML</a> (Vector Markup Language). SVG is the best choice if you need to support older browsers.</p>
<p>The real issues with SVG are speed, future support and mobile devices. Every browser maker is actively working on making <code>canvas</code> faster. Safari 5 already offers hardware acceleration with the GPU for <code>canvas</code>, and the rest are working on it. SVG is also unsupported on Android devices.</p>
<p>Thereâ€™s a growing community around <code>canvas</code>, the new technology that vendors are focusing on. Theyâ€™re adding new features, fixing bugs and making it better every day.</p>
<h3>Other Canvas Drawing Libraries</h3>
<p>Paper.js isnâ€™t the only option for <code>canvas</code>. <a href="http://processingjs.org/">Processing.js</a>, from the <a href="http://ejohn.org/">creator of jQuery</a>, ports the <a href="http://en.wikipedia.org/wiki/Processing_(programming_language)">Processing</a> programming language to JavaScript. It supports animations and has <a href="http://processingjs.org/exhibition">many examples</a>.</p>
<p>The <a href="https://github.com/mrdoob/three.js/">three.js</a> engine supports <code>canvas</code> and the <a href="http://en.wikipedia.org/wiki/Webgl">WebGL</a> library, and it focuses more on 3-D drawings. <a href="http://www.dartlang.org/">Google Dart</a> will also support <code>canvas</code> with built-in rendering objects.</p>
<p>Paper.js is a mature library with a very supportive community on the <a href="http://groups.google.com/group/paperjs">Paper.js Google Group</a> and many impressive and well-documented examples. Check out some of the amazing things people are doing with it.</p>
<h3>More Paper.js Examples</h3>
<p>Our dandelion is just the beginning. Below are a few other impressive animations written in Paper.js.</p>
<ul>
<li><a href="http://paperjs.org/examples/">Examples</a>, Paper.jsPaper.js has a page full of incredible examples. <a href="http://paperjs.org/examples/voronoi/">Voronoi</a> is one of the best. Make sure to press the space bar and see the paths. More examples are in the <a href="https://github.com/paperjs/paper.js/tree/master/examples">GitHub folder</a>.</li>
<li><a href="http://nardove.com/">Nardove</a>, Ricardo SÃ¡nchezJellyfish and a koi pond written with Processing.js. Wait a minute, the jellies are shy.</li>
<li>â€œ<a href="http://barbariangroup.com/posts/8960-a_node_garden_in_paper_js">Node Garden in Paper.js</a>,â€� Andrew Berg</li>
<li>â€œ<a href="http://zgrossbart.github.com/hborecycling/">The HBO Recycling Program</a>â€�An infographic that I created using Paper.js to show how often different HBO series use the same actors.</li>
<li>â€œ<a href="http://zgrossbart.github.com/touch_gestures/">20 Multi-Touch Gestures You Should Learn Today</a>,â€� Zack GrossbartI created the interactive tutorial with the help of Paper.js.</li>
</ul>
<p>Whereâ€™s your Paper.js amazingness?</p>
<p><em>(al)</em></p>
<hr />
<p><small>Â© Zack Grossbart for <a href="http://www.smashingmagazine.com">Smashing Magazine</a>, 2011.</small></p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/11/how-to-create-web-animations-with-paper-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript-created markup also needs to be semantic and accessible</title>
		<link>http://blogmyquery.com/index.php/2011/11/javascript-created-markup-also-needs-to-be-semantic-and-accessible/</link>
		<comments>http://blogmyquery.com/index.php/2011/11/javascript-created-markup-also-needs-to-be-semantic-and-accessible/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 18:07:25 +0000</pubDate>
		<dc:creator>Roger Johansson</dc:creator>
				<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.456bereastreet.com/archive/201111/javascript-created_markup_also_needs_to_be_semantic_and_accessible/</guid>
		<description><![CDATA[Back in the day you used to be able to view source on a web page to see the markup used to create it. These days, on many sites, a large portion of the markup is not visible when you view source because it is inserted by JavaScript functions.

That isn...]]></description>
			<content:encoded><![CDATA[<p class="preamble">Back in the day you used to be able to view source on a web page to see the markup used to create it. These days, on many sites, a large portion of the markup is not visible when you view source because it is inserted by JavaScript functions.</p>

<p>That isn't necessarily a problem provided that you use <a href="http://en.wikipedia.org/wiki/Progressive_enhancement">progressive enhancement</a> and <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript">unobtrusive JavaScript</a>. If you follow those principles, content and basic functionality will still be there when scripting is unavailable. Many of us understand that. But one thing Iâ€™ve noticed is that some developers forget to consider semantics or accessibility in the markup they use JavaScript to insert.</p><p><a href="http://www.456bereastreet.com/archive/201111/javascript-created_markup_also_needs_to_be_semantic_and_accessible/">Read full post</a></p><p>Posted in <a href="http://www.456bereastreet.com/archive/categories/xhtml/" rel="tag">(X)HTML</a>, <a href="http://www.456bereastreet.com/archive/categories/accessibility/" rel="tag">Accessibility</a>, <a href="http://www.456bereastreet.com/archive/categories/javascript/" rel="tag">JavaScript</a>.</p><p>Copyright Â© <a href="http://www.456bereastreet.com/">Roger Johansson</a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/qnHPdqCWsZKzI7383KQh6jwZKoE/0/da"><img src="http://feedads.g.doubleclick.net/~a/qnHPdqCWsZKzI7383KQh6jwZKoE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qnHPdqCWsZKzI7383KQh6jwZKoE/1/da"><img src="http://feedads.g.doubleclick.net/~a/qnHPdqCWsZKzI7383KQh6jwZKoE/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/456bereastreet?a=i987-bl_AlM:CNA59r86z_A:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=i987-bl_AlM:CNA59r86z_A:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=bcOpcFrp8Mo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=i987-bl_AlM:CNA59r86z_A:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=i987-bl_AlM:CNA59r86z_A:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=i987-bl_AlM:CNA59r86z_A:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=i987-bl_AlM:CNA59r86z_A:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/456bereastreet/~4/i987-bl_AlM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/11/javascript-created-markup-also-needs-to-be-semantic-and-accessible/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An accessible, keyboard friendly custom select menu</title>
		<link>http://blogmyquery.com/index.php/2011/11/an-accessible-keyboard-friendly-custom-select-menu/</link>
		<comments>http://blogmyquery.com/index.php/2011/11/an-accessible-keyboard-friendly-custom-select-menu/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 19:04:17 +0000</pubDate>
		<dc:creator>Roger Johansson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.456bereastreet.com/archive/201111/an_accessible_keyboard_friendly_custom_select_menu/</guid>
		<description><![CDATA[Iâ€™ve always been wary of styling form elements too much. Possible usability and accessibility issues, browser quirks, and the fact that the CSS specification does not define form control styling are the main reasons.

With that said, sometimes y...]]></description>
			<content:encoded><![CDATA[<p class="preamble">Iâ€™ve always been wary of styling form elements too much. Possible usability and accessibility issues, browser quirks, and the fact that <a href="http://www.w3.org/TR/CSS21/conform.html#conformance">the CSS specification does not define form control styling</a> are the main reasons.</p>

<p>With that said, sometimes you have to do things you donâ€™t really want to. Like styling <code>select</code> elements, which Iâ€™ve recently had to find a way to do. There are quite a few workarounds for doing this out there. However, most of the ones I looked at replace the <code>select</code> element with a bunch of links which changes semantics and behaviour a bit too much for my tastes. I couldnâ€™t find any implementation that I was completely happy with, so I took the best one I could find and tweaked it.</p><p><a href="http://www.456bereastreet.com/archive/201111/an_accessible_keyboard_friendly_custom_select_menu/">Read full post</a></p><p>Posted in <a href="http://www.456bereastreet.com/archive/categories/accessibility/" rel="tag">Accessibility</a>, <a href="http://www.456bereastreet.com/archive/categories/css/" rel="tag">CSS</a>, <a href="http://www.456bereastreet.com/archive/categories/javascript/" rel="tag">JavaScript</a>.</p><p>Copyright Â© <a href="http://www.456bereastreet.com/">Roger Johansson</a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/c741rU3z65u_Snswk2AN66XhOWE/0/da"><img src="http://feedads.g.doubleclick.net/~a/c741rU3z65u_Snswk2AN66XhOWE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/c741rU3z65u_Snswk2AN66XhOWE/1/da"><img src="http://feedads.g.doubleclick.net/~a/c741rU3z65u_Snswk2AN66XhOWE/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/456bereastreet?a=CxJ24wNeuqQ:9dxLbAJowZw:I9og5sOYxJI"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=I9og5sOYxJI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=CxJ24wNeuqQ:9dxLbAJowZw:bcOpcFrp8Mo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?d=bcOpcFrp8Mo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=CxJ24wNeuqQ:9dxLbAJowZw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=CxJ24wNeuqQ:9dxLbAJowZw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/456bereastreet?a=CxJ24wNeuqQ:9dxLbAJowZw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/456bereastreet?i=CxJ24wNeuqQ:9dxLbAJowZw:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/456bereastreet/~4/CxJ24wNeuqQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/11/an-accessible-keyboard-friendly-custom-select-menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lessons From A Review Of JavaScript Code</title>
		<link>http://blogmyquery.com/index.php/2011/10/lessons-from-a-review-of-javascript-code/</link>
		<comments>http://blogmyquery.com/index.php/2011/10/lessons-from-a-review-of-javascript-code/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 12:33:13 +0000</pubDate>
		<dc:creator>Addy Osmani</dc:creator>
				<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://www.smashingmagazine.com/?p=117584</guid>
		<description><![CDATA[<table width="650">
  <tr>
    <td width="650">
      <div>
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=1" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=1" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=2" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=2" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=3" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=3" border="0" alt="" />
        </a>
      </div>
    </td>
  </tr>
</table><p>Before we start, Iâ€™d like to pose a question: when was the last time you asked someone to review your code? Reviewing code is possibly the single best technique to improve the overall quality of your solutions, and if youâ€™re not actively taking advantage of it, then youâ€™re missing out on identifying bugs and hearing suggestions that could make your code better.</p>

<p><a href="http://coding.smashingmagazine.com/2011/10/27/lessons-from-a-review-of-javascript-code/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/10/exhaustion.jpg" width="500" height="196" /></a></p>

<p>None of us write 100% bug-free code all of the time, so donâ€™t feel thereâ€™s a stigma attached to seeking help. Some of the most experienced developers in our industry, from framework authors to browser developers, regularly request reviews of their code from others; asking whether something could be tweaked should in no way be considered embarrassing. <strong>Reviews are a technique like any other</strong> and should be used where possible.</p>]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=1" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=1" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=2" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=2" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=3" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=3" border="0" alt="" /><br />
        </a>
      </div>
</td>
</tr>
</table>
<p>Before we start, Iâ€™d like to pose a question: when was the last time you asked someone to review your code? Reviewing code is possibly the single best technique to improve the overall quality of your solutions, and if youâ€™re not actively taking advantage of it, then youâ€™re missing out on identifying bugs and hearing suggestions that could make your code better.</p>
<p>None of us write 100% bug-free code all of the time, so donâ€™t feel thereâ€™s a stigma attached to seeking help. Some of the most experienced developers in our industry, from framework authors to browser developers, regularly request reviews of their code from others; asking whether something could be tweaked should in no way be considered embarrassing. Reviews are a technique like any other and should be used where possible.</p>
<p>Today weâ€™ll look at <em>where </em>to get your code reviewed, <em>how</em> to structure your requests, and <em>what </em>reviewers look for. I was recently asked to review some code for a new JavaScript application, and thought Iâ€™d like to share some of my feedback, because it covers some JavaScript fundamentals that are always useful to bear in mind.</p>
<h3>Introduction</h3>
<p>Reviewing code goes hand in hand with maintaining strong coding standards. That said, standards donâ€™t usually prevent logical errors or misunderstandings about the quirks of a programming language, whether itâ€™s JavaScript, Ruby, Objective-C or something else. Even the most experienced developers can make these kinds of mistakes, and reviewing code can greatly assist with catching them.</p>
<p>The first reaction most of us have to criticism is to defend ourselves (or our code), and perhaps lash back. While criticism can be slightly demoralizing, <strong>think of it as a learning experience</strong> that spurs us to do better and to improve ourselves; because in many cases, once weâ€™ve calmed down, it actually does.</p>
<p>Also remember that no one is obliged to provide feedback on your work, and if the comments are indeed constructive, then be grateful for the time spent offering the input.</p>
<p>Reviews enable us to build on the experience of others and to benefit from a second pair of eyes. And at the end of the day, they are an opportunity for us to write better code. Whether we take advantage of them is entirely our choice.</p>
<h3>Where Can I Get My Code Reviewed?</h3>
<p>Often the most challenging part is actually finding an experienced developer who you trust to do the review. Below are some places where you can request others to review your code (sometimes in other languages, too).</p>
<ul>
<li><a href="http://jsmentors.com">JSMentors</a><br />
JSMentors is a mailing list that discusses everything to do with JavaScript (including Harmony), and a number of experienced developers are on its review panel (including JD Dalton, Angus Croll and Nicholas Zakas). These mentors might not always be readily available, but they do their best to provide useful, constructive feedback on code thatâ€™s been submitted. If youâ€™re looking for assistance with a specific JavaScript framework beyond vanilla JavaScript, the majority of frameworks and libraries have mailing lists or forums that you can post to and that might provide a similar level of assistance.</li>
<li><a href="http://webchat.freenode.net">freenode IRC</a><br />
Many chat rooms here are dedicated both to discussing the JavaScript language and to requests for help or review. The most popular rooms are obviously named, and #javascript is particularly useful for generic JavaScript requests, while channels such as #jquery and #dojo are better for questions and requests related to particular libraries and frameworks.</li>
<li><a href="http://codereview.stackexchange.com">Code Review</a> (beta)<br />
You would be forgiven for confusing Code Review with StackOverflow, but itâ€™s actually a very useful, broad-spectrum, subjective tool for getting peer review of code. While on StackOverflow you might ask the question â€œWhy isnâ€™t my code working?,â€� Code Review is more suited to questions like â€œWhy is my code so ugly?â€� If you still have any doubt about what it offers, I strongly recommend checking out the <a href="http://codereview.stackexchange.com/faq">FAQs</a>.</li>
<li><a href="http://twitter.com">Twitter</a><br />
This might sound odd, but at least half of the code that I submit for review is through social networks. Social networks work best, of course, if your code is open source, but trying them never hurts. The only thing I suggest is to ensure that the developers who you follow and interact with are experienced; a review by a developer with insufficient experience can sometimes be worse than no review at all, so be careful!</li>
<li><a href="http://github.com/">GitHub + reviewth.is</a><br />
We all know that GitHub provides an excellent architecture for reviewing code. It comes with commits, file and line comments, update notifications, an easy way to track forks of gits and repositories, and more. All thatâ€™s missing is a way to actually initiate reviews. A tool called <a href="http://reviewth.is">reviewth.is</a> attempts to rectify that by giving you a post-commit hook that helps to automate this process, so changes that get posted in the wild have a clear #reviewthis hash tag, and you can tag any users who you wish to review your updates. If many of your colleagues happen to develop in the same language as you do, this set-up can work well for code reviews sourced closer to home. One <a href="http://stackoverflow.com/questions/3730527/workflow-for-github-based-code-review">workflow that works well with this</a> (if youâ€™re working on a team or on a collaborative project) is to perform your own work in a topic branch in a repository and then send through pull requests on that branch. Reviewers would examine the changes and commits and could then make line-by-line and file-by-file comments. You (the developer) would then take this feedback and do a destructive rebase on that topic branch, re-push it, and allow the review cycle to repeat until merging them would be acceptable.</li>
</ul>
<h3>How Should I Structure My Review Requests?</h3>
<p>The following are some guidelines (based on experience) on how to structure your requests for code reviews, to increase the chances of them being accepted. You can be more liberal with them if the reviewer is on your team; but if the reviewer is external, then these might save you some time:</p>
<ul>
<li>Isolate what you would like to be reviewed; ensure that it can be easily run, forked and commented; be clear about where you think improvements could be made; and, above all, be patient.</li>
<li>Make it as easy as possible for the reviewer to look at, demo and change your code.</li>
<li>Donâ€™t submit a ZIP file of your entire website or project; very few people have the time to go through all of this. The only situation in which this would be acceptable is if your code absolutely required local testing.</li>
<li>Instead, isolate and reduce what you would like to be reviewed on <a href="http://jsfiddle.net">jsFiddle</a>, on <a href="http://www.jsbin.com">jsbin</a> or in a <a href="http://gist.github.com">GitHub</a> gist. This will allow the reviewer to easily fork what youâ€™ve provided and to show changes and comments on what can be improved. If you would prefer a â€œdiffâ€� between your work and any changes theyâ€™ve recommended, you might also be interested in <a href="http://pastebin.com">PasteBin</a>, which supports this.</li>
<li>Similarly, donâ€™t just submit a link to a page and ask them to â€œView sourceâ€� in order to see what can be improved. On websites with a lot of scripts, this task would be challenging and lowers the chances of a reviewer agreeing to help. No one wants to work to find what you want reviewed.</li>
<li>Clearly indicate where you <em>personally</em> feel the implementation could be improved. This will help the reviewer quickly home in on what youâ€™re most interested in having reviewed and will save them time. Many reviewers will still look at other parts of the code youâ€™ve submitted regardless, but at least help them prioritize.</li>
<li>Indicate what (if any) research youâ€™ve done into techniques for improving the code. The reviewer might very well suggest the same resources, but if theyâ€™re aware that you already know of them, then they might offer alternative suggestions (which is what you want).</li>
<li>If English isnâ€™t your first language, thereâ€™s no harm in saying so. When other developers inform me of this, I know whether to keep the language in my review technical or simple.</li>
<li><strong>Be patient</strong>. Some reviews take several days to get back to me, and nothingâ€™s wrong with that. Other developers are usually busy with other projects, and someone who agrees to schedule a look at your work is being kind. Be patient, donâ€™t spam them with reminders, and be understanding if they get delayed. Doing this sometimes pay off, because the reviewer can provide even more detailed feedback when they have more time.</li>
</ul>
<h3>What Should Code Reviews Provide?</h3>
<p>Jonathan Betz, a former developer at Google, once said that a code review should ideally address six things:</p>
<ol>
<li><strong>Correctness</strong><br />
Does the code do everything it claims?</li>
<li><strong>Complexity</strong><br />
Does it accomplish its goals in a straightforward way?</li>
<li><strong>Consistency</strong><br />
Does it achieve its goals consistently?</li>
<li><strong>Maintainability</strong><br />
Could the code be easily extended by another member of the team with a reasonable level of effort?</li>
<li><strong>Scalability</strong><br />
Is the code written in such a way that it would work for both 100 users and 10,000? Is it optimized?</li>
<li><strong>Style</strong><br />
Does the code adhere to a particular style guide (preferably one agreed upon by the team if the project is collaborative)?</li>
</ol>
<p>While I agree with this list, expanding it into an action guide of what reviewers should <strong>practically</strong> aim to give developers would be useful. So, reviewers should do the following:</p>
<ul>
<li>Provide clear comments, demonstrate knowledge, and communicate well.</li>
<li>Point out the shortfalls in an implementation (without being overly critical).</li>
<li>State why a particular approach isnâ€™t recommended, and, if possible, refer to blog posts, gists, specifications, <a href="http://developer.mozilla.org">MDN</a> pages and <a href="http://jsperf.com">jsPerf</a> tests to back up the statement.</li>
<li>Suggest alternative solutions, either in a separate runnable form or integrated in the code via a fork, so that the developer can clearly see what they did wrong.</li>
<li>Focus on solutions first, and style second. Suggestions on style can come later in the review, but address the fundamental problem as thoroughly as possible before paying attention to this.</li>
<li>Review beyond the scope of what was requested. This is entirely at the reviewerâ€™s discretion, but if I notice issues with other aspects of a developerâ€™s implementation, then I generally try to advise them on how those, too, might be improved. Iâ€™ve yet to receive a complaint about this, so I assume itâ€™s not a bad thing.</li>
</ul>
<h3>Collaborative Code Reviews</h3>
<p>Although a review by one developer can work well, an alternative approach is to bring more people into the process. This has a few distinct advantages, including reducing the load on individual reviewers and exposing more people to your implementation, which could potentially lead to more suggestions for improvements. It also allows a reviewerâ€™s comments to be screened and corrected if they happen to make a mistake.</p>
<p>To assist the group, you may wish to employ a collaborative tool to allow all reviewers to simultaneously inspect and comment on your code. Luckily, a few decent ones out there are worth checking out:</p>
<ul>
<li><a href="http://www.reviewboard.org/">Review Board</a><br />
This Web-based tool is available for free under the MIT license. It integrates with Git, CVS, Mercurial, Subversion and a number of other source-control systems. Review Board can be installed on any server running Apache or lighttpd and is free for personal and commercial use.</li>
<li><a href="http://www.atlassian.com/software/crucible">Crucible</a><br />
This tool by Australian software company Atlassian is also Web-based. Itâ€™s aimed at the enterprise and works best with distributed teams. Crucible facilitates both live review and live commenting and, like Review Board, integrates with a number of source-control tools, including Git and Subversion.</li>
<li><a href="http://code.google.com/p/rietveld/">Rietveld</a><br />
Like the other two, Rietveld also supports collaborative review, but it was actually written by the creator of Python, Guido van Rossum. It is designed to run on Googleâ€™s cloud service and benefits from Guidoâ€™s experience writing Mondrian, the proprietary app that Google uses internally to review its code.</li>
<li>Others<br />
A number of other options for collaborative code review werenâ€™t created for that purpose. These include <a href="http://collabedit.com/">CollabEdit</a> (free and Web-based) and, my personal favorite, <a href="http://piratepad.net/front-page/">EtherPad</a> (also free and Web-based).</li>
</ul>
<p><a href="http://www.flickr.com/photos/joelogon/324259281/sizes/m/in/photostream/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/10/exhaustion.jpg"></a><br />
<em>(Image Source: <a href="http://www.flickr.com/photos/joelogon/324259281/sizes/m/in/photostream/">joelogon</a>)</em></p>
<h3>Lessons From A JavaScript Code Review</h3>
<p>On to the review.</p>
<p>A developer recently wrote in, asking me to review their code and provide some useful suggestions on how they might improve it. While Iâ€™m certainly not an expert on reviewing code (donâ€™t let the above fool you), here are the problems and solutions that I proposed.</p>
<h4>Problem 1</h4>
<p><strong>Problem:</strong> Functions and objects are passed as arguments to other functions without any type validation.</p>
<p><strong>Feedback:</strong> Type validation is an essential step in ensuring that youâ€™re working only with input of a desired type. Without sanitization checks in place, you run the risk of users passing in just about anything (a string, a date, an array, etc.), which could easily break your application if you havenâ€™t developed it defensively. For functions, you should do the following at a minimum:</p>
<ol>
<li>Test to ensure that arguments being passed actually exist,</li>
<li>Do a <code>typeof</code> check to prevent the app from executing input that is not a valid function at all.</li>
</ol>
<pre class="brush: js">
if (callback &#38;&#38; typeof callback === &#34;function&#34;){
    /* rest of your logic */
}else{
    /* not a valid function */
}
</pre>
<p>Unfortunately, a simple <code>typeof</code> check <strong>isnâ€™t enough</strong> on its own. As Angus Croll points out in his post â€œ<a href="http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/">Fixing the typeof operator</a>,â€� you need to be aware of a number of issues with <code>typeof</code> checking if youâ€™re using them for anything other than functions.</p>
<p>For example, <code>typeof null</code> returns <code>object</code>, which is technically incorrect. In fact, when <code>typeof</code> is applied to any object type that isnâ€™t a function, it returns <code>object</code>, not distinguishing between <code>Array</code>, <code>Date</code>, <code>RegEx</code> or whatever else.</p>
<p>The solution is to use <code>Object.prototype.toString</code> to call the underlying internal property of JavaScript objects known as <code>[[Class]]</code>, the class property of the object. Unfortunately, specialized built-in objects generally overwrite <code>Object.prototype.toString</code>, but you can force the generic <code>toString</code> function on them:</p>
<pre class="brush: js">
Object.prototype.toString.call([1,2,3]); //&#34;[object Array]&#34;
</pre>
<p>You might also find Angusâ€™s function below useful as a more reliable alternative to <code>typeof</code>. Try calling <code>betterTypeOf()</code> against objects, arrays and other types to see what happens.</p>
<pre class="brush: js">
function betterTypeOf( input ){
    return Object.prototype.toString.call(input).match(/^\[object\s(.*)\]$/)[1];
}
</pre>
<p>Here, <code>parseInt()</code> is being blindly used to parse an integer value of user input, but no base is specified. This can cause issues.</p>
<p>In <a href="http://shop.oreilly.com/product/9780596517748.do"><em>JavaScript: The Good Parts</em></a>, Douglas Crockford refers to <code>parseInt()</code> as being dangerous. Although you probably know that passing it a string argument returns an integer, you should also ideally specify a base or radix as the second argument, otherwise it might return unexpected output. Take the following example:</p>
<pre class="brush: js">
parseInt('20');       // returns what you expect, howeverâ€¦
parseInt('020');      // returns 16
parseInt('000020');   // returns 16
parseInt('020', 10);  // returns 20 as we've specified the base to use
</pre>
<p>Youâ€™d be surprised by how many developers omit the second argument, but it happens quite regularly. Remember that your users (if permitted to freely enter numeric input) wonâ€™t necessarily follow standard number conventions (because theyâ€™re crazy!). Iâ€™ve seen <code>020</code>, <code>,20</code>, <code>;'20</code> and many other variations used, so do your best to parse as broad a range of inputs as possible.  The following tricks to using <code>parseInt()</code> are occasionally better:</p>
<pre class="brush: js">
Math.floor("020");   // returns 20
Math.floor("0020");  //returns 20
Number("020");  //returns 20
Number("0020"); //returns 20
+"020"; //returns 20
</pre>
<h4>Problem 2</h4>
<p><strong>Problem:</strong> Checks for browser-specific conditions being met are repeated throughout the code base (for example, feature detection, checks for supported ES5 features, etc.).</p>
<p><strong>Feedback:</strong> Ideally, your code base should be as DRY as possible, and there are some elegant solutions to this problem. For example, you might benefit from the <strong>load-time configuration</strong> pattern here (also called load-time and init-time branching). The basic idea is that you test a condition only once (when the application loads) and then access the result of that test for all subsequent checks. This pattern is commonly found in JavaScript libraries that configure themselves at load time to be optimized for a particular browser.</p>
<p>This pattern could be implemented as follows:</p>
<pre class="brush: js">
var tools = {
    addMethod: null,
    removeMethod: null
};

if(/* condition for native support */){
    tools.addMethod = function(/* params */){
        /* method logic */
    }
}else{
    /* fallback - eg. for IE */
    tools.addMethod = function(/* */){
        /* method logic */
    }
}
</pre>
<p>The example below demonstrates how this can be used to normalize getting an <code>XMLHttpRequest</code> object.</p>
<pre class="brush: js">
var utils = {
    getXHR: null
};

if(window.XMLHttpRequest){
    utils.getXHR = function(){
        return new XMLHttpRequest;
    }
}else if(window.ActiveXObject){
    utils.getXHR = function(){
        /* this has been simplified for example sakes */
        return new ActiveXObject(â€™Microsoft.XMLHTTPâ€™);
    }
}
</pre>
<p>For a great example, Stoyan Stefanov applies this to attaching and removing event listeners cross-browser, in his book <a href="http://shop.oreilly.com/product/9780596806767.do"><em>JavaScript Patterns</em></a>:</p>
<pre class="brush: js">
var utils = {
    addListener: null,
    removeListener: null
};
// the implementation
if (typeof window.addEventListener === â€™functionâ€™) {
    utils.addListener = function ( el, type, fn ) {
        el.addEventListener(type, fn, false);
    };
    utils.removeListener = function ( el, type, fn ) {
        el.removeEventListener(type, fn, false);
    };
} else if (typeof document.attachEvent === â€™functionâ€™) { // IE
    utils.addListener = function ( el, type, fn ) {
        el.attachEvent(â€™onâ€™ + type, fn);
    };
    utils.removeListener = function ( el, type, fn ) {
        el.detachEvent(â€™onâ€™ + type, fn);
    };
} else { // older browsers
    utils.addListener = function ( el, type, fn ) {
        el[â€™onâ€™ + type] = fn;
    };
    utils.removeListener = function ( el, type, fn ) {
        el[â€™onâ€™ + type] = null;
    };
}
</pre>
<h4>Problem 3</h4>
<p><strong>Problem:</strong> The native <code>Object.prototype</code> is being extended regularly.</p>
<p><strong>Feedback:</strong> Extending native types is generally frowned upon, and few (if any) popular code bases should dare to extend <code>Object.prototype</code>. The reality is that there is not likely a situation in which you absolutely need to extend it in this way. In addition to breaking the object-as-hash tables in JavaScript and increasing the chance of naming collisions, itâ€™s generally considered bad practice, and modifying it should only be a last resort (this is quite different from extending your own <em>custom</em> <code>object</code> properties).</p>
<p>If for some reason you <em>do</em> end up extending the <code>object</code> prototype, ensure that the method doesnâ€™t already exist, and document it so that the rest of the team is aware why itâ€™s necessary. You can use the following code sample as a guide:</p>
<pre class="brush: js">
if(typeof Object.prototype.myMethod != â€™functionâ€™){
    Object.prototype.myMethod = function(){
        //implem
    };
}
</pre>
<p><a href="http://twitter.com/kangax">Juriy Zaytsev</a> has a great post on <a href="http://perfectionkills.com/extending-built-in-native-objects-evil-or-not/">extending native and host objects</a>, which may be of interest.</p>
<h4>Problem 4</h4>
<p><strong>Problem:</strong> Some of the code is heavily blocking the page because itâ€™s either waiting on processes to complete or data to load before executing anything further.</p>
<p><strong>Feedback:</strong> Page-blocking makes for a poor user experience, and there are a number of ways to work around it without impairing the application.</p>
<p>One solution is to use â€œdeferred executionâ€� (via promises and futures). The basic idea with promises is that, rather than issuing blocking calls for resources, you immediately return a promise for a future value that will eventually be fulfilled. This rather easily allows you to write non-blocking logic that can be run asynchronously. It is common to introduce callbacks into this equation that execute once the request completes.</p>
<p>Iâ€™ve written a relatively comprehensive <a href="http://msdn.microsoft.com/en-us/scriptjunkie/gg723713">post</a> on this with Julian Aubourg, if youâ€™re interested in doing this through jQuery, but it can of course be implemented with vanilla JavaScript as well.</p>
<p>Micro-framework <a href="https://github.com/kriskowal/">Q</a> offers a CommonJS-compatible implementation of promises and futures that is relatively comprehensive and can be used as follows:</p>
<pre class="brush: js">
/* define a promise-only delay function that resolves when a timeout completes */
function delay(ms) {
    var deferred = Q.defer();
    setTimeout(deferred.resolve, ms);
    return deferred.promise;
}

/* usage of Q with the 'when' pattern to execute a callback once delay fulfils the promise */
Q.when(delay(500), function () {
        /* do stuff in the callback */
});
</pre>
<p>If youâ€™re looking for something more basic that can be read through, then here is Douglas Crockfordâ€™s implementation of promises:</p>
<pre class="brush: js">
function make_promise() {
  var status = â€™unresolvedâ€™,
      outcome,
      waiting = [],
      dreading = []; 

  function vouch( deed, func ) {
    switch (status) {
    case â€™unresolvedâ€™:
      (deed === â€™fulfilledâ€™ ? waiting : dreading).push(func);
      break;
    case deed:
      func(outcome);
      break;
    }
  };

  function resolve( deed, value ) {
    if (status !== â€™unresolvedâ€™) {
      throw new Error(â€™The promise has already been resolved:â€™ + status);
    }
    status = deed;
    outcome = value;
    (deed == â€™fulfilledâ€™ ? waiting : dreading).forEach(function (func) {
      try {
        func(outcome);
      } catch (ignore) {}
    });
    waiting = null;
    dreading = null;
  };

  return {
    when: function ( func ) {
      vouch(â€™fulfilledâ€™, func);
    },
    fail: function ( func ) {
      vouch(â€™smashedâ€™, func);
    },
    fulfill: function ( value ) {
      resolve(â€™fulfilledâ€™, value);
    },
    smash: function ( string ) {
      resolve(â€™smashedâ€™, string);
    },
    status: function () {
      return status;
    }
  };
};
</pre>
<h4>Problem 5</h4>
<p><strong>Problem:</strong> Youâ€™re testing for explicit numeric equality of a property using the <code>==</code> operator, but you should probably be using <code>===</code> instead</p>
<p><strong>Feedback:</strong> As you may or may not know, the identity <code>==</code> operator in JavaScript is fairly liberal and considers values to be equal even if theyâ€™re of completely different types. This is due to the operator forcing a coercion of values into a single type (usually a number) prior to performing any comparison. The <code>===</code> operator will, however, not do this conversion, so if the two values being compared are not of the same type, then <code>===</code> will just return <code>false</code>.</p>
<p>The reason I recommend considering <code>===</code> for more specific type comparison (in this case) is that <code>==</code> is known to have a number of gotchas and is considered to be unreliable by many developers.</p>
<p>You might also be interested to know that in abstractions of the language, such as CoffeeScript, the <code>==</code> operator is completely dropped in favor of <code>===</code> beneath the hood due to the formerâ€™s unreliability.</p>
<p>Rather than take my word for it, see the examples below of boolean checks for equality using <code>==</code>, some of which result in rather unexpected outputs.</p>
<pre class="brush: js">
3 == &#34;3&#34; // true
3 == &#34;03&#34; // true
3 == &#34;0003&#34; // true
3 == &#34;+3&#34; //true
3 == [3] //true
3 == (true+2) //true
â€™ \t\r\n â€™ == 0 //true
"\t\r\n" == 0 //true
"\t" == 0 // true
"\t\n" == 0 // true
"\t\r" == 0 // true
" " == 0 // true
" \t" == 0 // true
" \ " == 0 // true
" \r\n\ " == 0 //true
</pre>
<p>The reason that many of the (stranger) results in this list evaluate to <code>true</code> is because JavaScript is a weakly typed language: it applies type coercion <em>wherever</em> possible. If youâ€™re interested in learning more about why some of the expressions above evaluate to <code>true</code>, look at the <a href="http://es5.github.com/#x9.3.1">Annotated ES5</a> guide, whose explanations are rather fascinating.</p>
<p>Back to the review. If youâ€™re 100% certain that the values being compared cannot be interfered with by the user, then proceed with using the <code>==</code> operator with caution. Just remember that <code>===</code> covers your bases better in the event of an unexpected input.</p>
<h4>Problem 6</h4>
<p><strong>Problem:</strong> An uncached array <code>length</code> is being used in all <code>for</code> loops. This is particularly bad because youâ€™re using it when iterating through an HTMLCollection.</p>
<p>Hereâ€™s an example:</p>
<pre class="brush: js">
for( var i=0; i&#60;myArray.length;i++ ){
    /* do stuff */
}
</pre>
<p>
<p><strong>Feedback:</strong> The problem with this approach (which I still see a number of developers using) is that the array <code>length</code> is unnecessarily re-accessed on each loopâ€™s iteration. This can be very slow, especially when working with HTMLCollections (in which case, caching the <code>length</code> can be anywhere up to 190 times faster than repeatedly accessing it, as Nicholas C. Zakas mentions in his book <a href="http://shop.oreilly.com/product/9780596802806.do"><em>High-Performance JavaScript</em></a>). Below are some options for caching the array <code>length</code>.</p>
<pre class="brush: js">
/* cached outside loop */
var len = myArray.length;
for ( var i = 0; i &#60; len; i++ ) {
}

/* cached inside loop */
for ( var i = 0, len = myArray.length; i &#60; len; i++ ) {
}

/* cached outside loop using while */
var len = myArray.length;
while (len--) {
}
</pre>
<p>A <a href="http://jsperf.com">jsPerf</a> test that compares the performance benefits of caching the array <code>length</code> inside and outside the loop, using prefix increments, counting down and more is also <a href="http://jsperf.com/caching-array-length/7">available</a>, if you would like to study which performs the best.</p>
<h4>Problem 7</h4>
<p><strong>Problem:</strong> jQueryâ€™s <code>$.each()</code> is being used to iterate over objects and arrays, in some cases while <code>for</code> is being used in others.</p>
<p><strong>Feedback:</strong> In jQuery, we have two ways to seamlessly iterate over objects and arrays. The generic <a href="http://api.jquery.com/jQuery.each/"><code>$.each</code></a> iterates over both of these types, whereas <a href="http://api.jquery.com/each/"><code>$.fn.each()</code></a> iterates over a jQuery object specifically (where standard objects can be wrapped with <code>$()</code> should you wish to use them with the latter). While the lower-level <code>$.each</code> performs better than <code>$.fn.each()</code>, both standard JavaScript <code>for</code> and <code>while</code> loops perform much better than either, as proven by this <a href="http://jsperf.com/jquery-each-vs-for-loop/24/">jsPerf test</a>. Below are some examples of loop alternatives that also perform better:</p>
<pre class="brush: js">
/* jQuery $.each */
$.each(a, function() {
 e = $(this);
});

/* classic for loop */
var len = a.length;
for ( var i = 0; i &#60; len; i++ ) {
    //if this must be a jQuery object do..
    e = $(a[i]);
    //otherwise just e = a[i] should suffice
};

/* reverse for loop */
for ( var i = a.length; i-- ) {
    e = $(a[i]);
}

/* classic while loop */
var i = a.length;
while (i--) {
    e = $(a[i]);
}

/* alternative while loop */
var i = a.length - 1;

while ( e = a[i--] ) {
    $(e)
};
</pre>
<p>You might find Angus Crollâ€™s post on â€œ<a href="http://javascriptweblog.wordpress.com/2010/10/11/rethinking-javascript-for-loops/">Rethinking JavaScript <code>for</code> Loops</a>â€� an interesting extension to these suggestions.</p>
<p>Given that this is a data-centric application with a potentially large quantity of data in each object or array, you should consider a refactor to use one of these. From a scalability perspective, you want to shave off as many milliseconds as possible from process-heavy routines, because these can build up when hundreds or thousands of elements are on the page.</p>
<h4>Problem 8</h4>
<p><strong>Problem:</strong> JSON strings are being built in-memory using string concatenation.</p>
<p><strong>Feedback:</strong> This could be approached in more optimal ways. For example, why not use <code>JSON.stringify()</code>, a method that accepts a JavaScript object and returns its JSON equivalent. Objects can generally be as complex or as deeply nested as you wish, and this will almost certainly result in a simpler, shorter solution.</p>
<pre class="brush: js">
var myData = {};
myData.dataA = [â€™aâ€™, â€™bâ€™, â€™câ€™, â€™dâ€™];
myData.dataB = {
    â€™animalâ€™: â€™catâ€™,
    â€™colorâ€™: â€™brownâ€™
};
myData.dataC = {
    â€™vehiclesâ€™: [{
        â€™typeâ€™: â€™fordâ€™,
        â€™tintâ€™: â€™silverâ€™,
        â€™yearâ€™: â€™2015â€™
    }, {
        â€™typeâ€™: â€™hondaâ€™,
        â€™tintâ€™: â€™blackâ€™,
        â€™yearâ€™: â€™2012â€™
    }]
};
myData.dataD = {
    â€™buildingsâ€™: [{
        â€™housesâ€™: [{
            â€™streetNameâ€™: â€™sycamore closeâ€™,
            â€™numberâ€™: â€™252â€™
        }, {
            â€™streetNameâ€™: â€™slimdon closeâ€™,
            â€™numberâ€™: â€™101â€™
        }]
    }]
};
console.log(myData); //object
var jsonData = JSON.stringify(myData);

console.log(jsonData);
/*
{&#34;dataA&#34;:[&#34;a&#34;,&#34;b&#34;,&#34;c&#34;,&#34;d&#34;],&#34;dataB&#34;:{&#34;animal&#34;:&#34;cat&#34;,&#34;color&#34;:&#34;brown&#34;},&#34;dataC&#34;:{&#34;vehicles&#34;:[{&#34;type&#34;:&#34;ford&#34;,&#34;tint&#34;:&#34;silver&#34;,&#34;year&#34;:&#34;2015&#34;},{&#34;type&#34;:&#34;honda&#34;,&#34;tint&#34;:&#34;black&#34;,&#34;year&#34;:&#34;2012&#34;}]},&#34;dataD&#34;:{&#34;buildings&#34;:[{&#34;houses&#34;:[{&#34;streetName&#34;:&#34;sycamore close&#34;,&#34;number&#34;:&#34;252&#34;},{&#34;streetName&#34;:&#34;slimdon close&#34;,&#34;number&#34;:&#34;101&#34;}]}]}}
 */
</pre>
<p>As an extra debugging tip, if you would like to pretty-print JSON in your console for easier reading, then the following extra arguments to <code>stringify()</code> will achieve this:</p>
<pre class="brush: js">
JSON.stringify({ foo: "hello", bar: "world" }, null, 4);
</pre>
<h4>Problem 9</h4>
<p><strong>Problem:</strong> The namespacing pattern used is technically invalid.</p>
<p><strong>Feedback:</strong> While namespacing is implemented correctly across the rest of the application, the initial check for namespace existence is invalid. Hereâ€™s what you currently have:</p>
<pre class="brush: js">
if ( !MyNamespace ) {
  MyNamespace = { };
}
</pre>
<p>The problem is that <code>!MyNamespace</code> will throw a <code>ReferenceError</code>, because the <code>MyNamespace</code> variable was never declared. A better pattern would take advantage of boolean conversion with an inner variable declaration, as follows:</p>
<pre class="brush: js">
if ( !MyNamespace ) {
  var MyNamespace = { };
}

//or
var myNamespace = myNamespace || {};

// Although a more efficient way of doing this is:
// myNamespace || ( myNamespace = {} );
// jsPerf test: http://jsperf.com/conditional-assignment

//or
if ( typeof MyNamespace == â€™undefinedâ€™ ) {
  var MyNamespace = { };
}
</pre>
<p>This could, of course, be done in numerous other ways. If youâ€™re interested in reading about more namespacing patterns (as well as some ideas on namespace extension), I recently wrote â€œ<a href="http://addyosmani.com/blog/essential-js-namespacing/">Essential JavaScript Namespacing Patterns</a>.â€� <a href="http://twitter.com/kangax">Juriy Zaytsev</a> also has a pretty <a href="http://perfectionkills.com/unnecessarily-comprehensive-look-into-a-rather-insignificant-issue-of-global-objects-creation/">comprehensive post on namespacing patterns</a>.</p>
<h3>Conclusion</h3>
<p>Thatâ€™s it. Reviewing code is a great way to enforce and maintain quality, correctness and consistency in coding standards at as high a level as possible. I strongly recommend that all developers give them a try in their daily projects, because theyâ€™re an excellent learning tool for both the developer and the reviewer. Until next time, try getting your code reviewed, and good luck with the rest of your project!</p>
<p><em>(al) (il)</em></p>
<hr />
<p><small>Â© Addy Osmani for <a href="http://www.smashingmagazine.com">Smashing Magazine</a>, 2011.</small></p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/10/lessons-from-a-review-of-javascript-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Quick Look Into The Math Of Animations With JavaScript</title>
		<link>http://blogmyquery.com/index.php/2011/10/a-quick-look-into-the-math-of-animations-with-javascript/</link>
		<comments>http://blogmyquery.com/index.php/2011/10/a-quick-look-into-the-math-of-animations-with-javascript/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 11:32:55 +0000</pubDate>
		<dc:creator>Christian Heilmann</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://mgmt.smashingmagazine.com/?p=115320</guid>
		<description><![CDATA[<table width="650">
  <tr>
    <td width="650">
      <div>
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=1" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=1" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=2" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=2" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=3" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=3" border="0" alt="" />
        </a>
      </div>
    </td>
  </tr>
</table><p>In school, I hated math. It was a dire, dry and boring thing with stuffy old books and very theoretical problems. Even worse, a lot of the tasks were repetitive, with a simple logical change in every iteration (dividing numbers by hand, differentials, etc.). It was exactly the reason why we invented computers. Suffice it to say, a lot of my math homework was actually done by my trusty Commodore 64 and some lines of Basic, with me just copying the results later on.</p>

<p><a href="http://coding.smashingmagazine.com/2011/10/04/quick-look-math-animations-javascript/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/circle.png" alt="Circle" width="300" height="300" /></a></p>

<p>These tools and the few geometry lessons I had gave me the time and inspiration to make math interesting for myself. I did this first and foremost by creating visual effects that followed mathematical rules in demos, intros and other seemingly pointless things. There is a lot of math in the visual things we do, even if we donâ€™t realize it. If you want to make something look natural and move naturally, you need to add a bit of physics and rounding to it.</p>]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=1" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=1" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=2" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=2" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=3" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=3" border="0" alt="" /><br />
        </a>
      </div>
</td>
</tr>
</table>
<p>In school, I hated math. It was a dire, dry and boring thing with stuffy old books and very theoretical problems. Even worse, a lot of the tasks were repetitive, with a simple logical change in every iteration (dividing numbers by hand, differentials, etc.). It was exactly the reason why we invented computers. Suffice it to say, a lot of my math homework was actually done by my trusty Commodore 64 and some lines of Basic, with me just copying the results later on.</p>
<p>These tools and the few geometry lessons I had gave me the time and inspiration to make math interesting for myself. I did this first and foremost by creating visual effects that followed mathematical rules in demos, intros and other seemingly pointless things.</p>
<p>There is a lot of math in the visual things we do, even if we donâ€™t realize it. If you want to make something look natural and move naturally, you need to add a bit of physics and rounding to it. Nature doesnâ€™t work in right angles or linear acceleration. This is why zombies in movies are so creepy. This was <a href="http://coding.smashingmagazine.com/2011/09/14/the-guide-to-css-animation-principles-and-examples/">covered here before in relation to CSS animation</a>, but today letâ€™s go a bit deeper and look at the simple math behind the smooth looks.</p>
<h3>Going From 0 To 1 Without Being Boring</h3>
<p>If youâ€™ve just started programming and are asked to go from 0 to 1 with a few steps in between, you would probably go for a <code>for</code> loop:</p>
<pre class="brush: js">for ( i = 0; i &#60;= 1; i += 0.1 ) {
  x = i;
  y = i;
â€¦
}</pre>
<p>This would result in a line on a graph that is 45 degrees. Nothing in nature moves with this precision:</p>
<p><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/forloop.png" alt="45 degree graph, a result of a simple for loop" width="300" height="300" /></p>
<p>A simple way to make this movement a bit more natural would be to simply multiply the value by itself:</p>
<pre class="brush: js">for ( i = 0; i &#60;= 1; i += 0.1 ) {
  x = i;
  y = i * i;
}</pre>
<p>This means that <code>0.1</code> is <code>0.01</code>, <code>0.2</code> is <code>0.04</code>, <code>0.3</code> is <code>0.09</code>, <code>0.4</code> is <code>0.16</code>, <code>0.5</code> is <code>0.25</code> and so on. The result is a curve that starts flat and then gets steeper towards the end:</p>
<p><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/multiply.png" alt="graph of the value multiplied with itself" width="300" height="300" /></p>
<p>You can make this even more pronounced by continuing to multiply or by using the â€œto the power ofâ€� <code>Math.pow()</code> function:</p>
<pre class="brush: js">for ( i = 0; i &#60;= 1; i += 0.1 ) {
  x = i;
  y = Math.pow( i, 4 );
}</pre>
<p><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/powerto.png" alt="graph with several multiplications" width="300" height="300" /></p>
<p>This is one of the tricks of the easing functions used in libraries such as jQuery and YUI, as well as in CSS transitions and animations in modern browsers.</p>
<p>You can use this the same way, but there is an even simpler option for getting a value between 0 and 1 that follows a natural motion.</p>
<h3>Not A Sin, Just A Natural Motion</h3>
<p><a href="http://en.wikipedia.org/wiki/Sine_wave">Sine waves</a> are probably the best thing ever for smooth animation. They happen in nature: witness a spring with a weight on it, ocean waves, sound and light.<br />
In our case, we want to move from 0 to 1 smoothly.</p>
<p>To create a movement that goes from 0 to 1 and back to 0 smoothly, we can use a sine wave that goes from 0 to Ï€ in a few steps. The full sine wave going from 0 to Ï€ Ã— 2 (i.e. a whole circle) would result in values from -1 to 1, and we donâ€™t want that (yet).</p>
<pre class="brush: js">var counter = 0;

// 100 iterations
var increase = Math.PI / 100;

for ( i = 0; i &#60;= 1; i += 0.01 ) {
  x = i;
  y = Math.sin(counter);
  counter += increase;
}</pre>
<p><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/sine.png" alt="half a sine wave" width="300" height="300" /></p>
<p><strong>A quick aside on numbers for sine and cosine:</strong> Both <code>Math.sin()</code> and <code>Math.cos()</code> take as the parameter an angle that should be in <a href="http://en.wikipedia.org/wiki/Radian">radians</a>. As humans, however, degrees ranging from 0 to 360 are much easier to read. Thatâ€™s why you can and should convert between them with this simple formula:</p>
<pre class="brush: js">var toRadian = Math.PI / 180;
var toDegree = 180 / Math.PI;

var angle = 30;

var angleInRadians = angle * toRadian;
var angleInDegrees = angleInRadians * toDegree;</pre>
<p>Back to our sine waves. You can play with this a lot. For example, you could use the absolute value of a full 2 Ã— Ï€ loop:</p>
<pre class="brush: js">var counter = 0;
// 100 iterations
var increase = Math.PI * 2 / 100;

for ( i = 0; i &#60;= 1; i += 0.01 ) {
  x = i;
  y = Math.abs( Math.sin( counter ) );
  counter += increase;
}</pre>
<p><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/msine.png" alt="absolute value of a sine wave" width="300" height="300" /></p>
<p>But again, this looks dirty. If you want the full up and down, without a break in the middle, then you need to shift the values. You have to half the sine and then add 0.5 to it:</p>
<pre class="brush: js">var counter = 0;
// 100 iterations
var increase = Math.PI * 2 / 100;

for ( i = 0; i &#60;= 1; i += 0.01 ) {
  x = i;
  y = Math.sin( counter ) / 2 + 0.5;
  counter += increase;
}</pre>
<p><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/shiftingup.png" alt="halfed and moved sine wave" width="300" height="300" /></p>
<p>So, how can you use this? Having a function that returns -1 to 1 to whatever you feed it can be very cool. All you need to do is multiply it by the values that you want and add an offset to avoid negative numbers.</p>
<p>For example, check out <a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/sinejump.html">this sine movement demo</a>:</p>
<p><a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/sinejump.html"> </a></p>
<p><a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/sinejump.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/sinejump.png" alt="Sine jump demo" width="224" height="222" /></a></p>
<p>Looks neat, doesnâ€™t it? A lot of the trickery is already in the CSS:</p>
<pre class="brush: css">.stage {
  width:200px;
  height:200px;
  margin:2em;
  position:relative;
  background:#6cf;
  overflow:hidden;
}

.stage div {
  line-height:40px;
  width:100%;
  text-align:center;
  background:#369;
  color:#fff;
  font-weight:bold;
  position:absolute;
}</pre>
<p>The <code>stage</code> element has a fixed dimension and is positioned relative. This means that everything that is positioned absolutely inside it will be relative to the element itself.</p>
<p>The div inside the stage is 40 pixels high and positioned absolutely. Now, all we need to do is move the div with JavaScript in a sine wave:</p>
<pre class="brush: js">var banner = document.querySelector( '.stage div' ),
    start = 0;
function sine(){
  banner.style.top = 50 * Math.sin( start ) + 80 + 'px';
  start += 0.05;
}
window.setInterval( sine, 1000/30 );</pre>
<p>The start value changes constantly, and with <code>Math.sin()</code> we get a nice wave movement. We multiply this by 50 to get a wider wave, and we add 80 pixels to center it in the stage element. Yes, the element is 200 pixels high and 100 is half of that, but because the banner is 40 pixels high, we need to subtract half of that to center it.</p>
<p>Right now, this is a simple up-and-down movement. Nothing stops you, though, from making it more interesting. The multiplying factor of 50, for example, could be a sine wave itself with a different value:</p>
<pre class="brush: js">var banner = document.querySelector( '.stage div' ),
    start = 0,
    multiplier = 0;
function sine(){
  multiplier = 50 * Math.sin( start * 2 );
  banner.style.top = multiplier * Math.sin( start ) + 80 + 'px';
  start += 0.05;
}
window.setInterval( sine, 1000/30 );</pre>
<p>The <a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/growingsinejump.html">result of this</a> is a banner that seems to tentatively move up and down. Back in the day and on the very slow Commodore 64, calculating the sine wave live was too slow. Instead, we had tools to generate sine tables (arrays, if you will), and we plotted those directly. One of the tools for creating great sine waves so that you could have bouncing scroll texts was the Wix Bouncer:</p>
<p><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/wixbouncer.png" alt="Wixbouncer - a tool to create sine waves" width="384" height="282" /></p>
<h3>Circles In The Sand, Round And Roundâ€¦</h3>
<p>Circular motion is a thing of beauty. It pleases the eye, reminds us of spinning wheels and the earth we stand on, and in general has a â€œthis is not computer stuffâ€� feel to it. The math of plotting something on a circle is not hard.</p>
<p>It goes back to <a href="http://en.wikipedia.org/wiki/Pythagoras">Pythagoras</a>, who, as rumor has it, drew a lot of circles in the sand until he found his famous <a href="http://en.wikipedia.org/wiki/Pythagorean_theorem">theorem</a>. If you want to use all the good stuff that comes from this theorem, then try to find a triangle with a right angle. If this triangleâ€™s hypothenuse is 1, then you can easily calculate the horizontal leg as the cosine of the angle and the vertical leg as the sine of the angle:</p>
<p><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/sincos.png" alt="Sincos" width="300" height="300" /></p>
<p>How is this relevant to a circle? Well, it is pretty simple to find a right-angle triangle in a circle to every point of it:</p>
<p><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/circle.png" alt="Circle" width="300" height="300" /></p>
<p>This means that if you want to plot something on a circle (or draw one), you can do it with a loop and sine and cosine. A full circle is 360Â°, or 2 Ã— Ï€ in radians. We could have a go at itâ€Šâ€”â€Šbut first, some plotting code needs to be done.</p>
<h3>A Quick DOM Plotting Routine</h3>
<p>Normally, my weapon of choice here would be canvas, but in order to play nice with older browsers, letâ€™s do it in plain DOM. The following helper function adds div elements to a stage element and allows us to position them, change their dimensions, set their color, change their content and rotate them without having to go through the annoying style settings on DOM elements.</p>
<pre class="brush: js">Plot = function ( stage ) {

  this.setDimensions = function( x, y ) {
    this.elm.style.width = x + 'px';
    this.elm.style.height = y + 'px';
    this.width = x;
    this.height = y;
  }
  this.position = function( x, y ) {
    var xoffset = arguments[2] ? 0 : this.width / 2;
    var yoffset = arguments[2] ? 0 : this.height / 2;
    this.elm.style.left = (x - xoffset) + 'px';
    this.elm.style.top = (y - yoffset) + 'px';
    this.x = x;
    this.y = y;
  };
  this.setbackground = function( col ) {
    this.elm.style.background = col;
  }
  this.kill = function() {
    stage.removeChild( this.elm );
  }
  this.rotate = function( str ) {
    this.elm.style.webkitTransform = this.elm.style.MozTransform =
    this.elm.style.OTransform = this.elm.style.transform =
    'rotate('+str+')';
  }
  this.content = function( content ) {
    this.elm.innerHTML = content;
  }
  this.round = function( round ) {
    this.elm.style.borderRadius = round ? '50%/50%' : '';
  }
  this.elm = document.createElement( 'div' );
  this.elm.style.position = 'absolute';
  stage.appendChild( this.elm );

};</pre>
<p>The only things that might be new here are the transformation with different browser prefixes and the positioning. People often make the mistake of creating a div with the dimensions <code>w</code> and <code>h</code> and then set it to <code>x</code> and <code>y</code> on the screen. This means you will always have to deal with the offset of the height and width. By subtracting half the width and height before positioning the div, you really set it where you want itâ€Šâ€”â€Šregardless of the dimensions. <a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/offsetissue1.html">Hereâ€™s a proof</a>:</p>
<p><a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/offsetissue.html"> </a></p>
<p><a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/offsetissue.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/offsetissue.png" alt="offset issue" width="481" height="229" /></a></p>
<p>Now, letâ€™s use that to <a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/simplecircle.html">plot 10 rectangles in a circle</a>, shall we?</p>
<p><a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/simplecircle.html"> </a></p>
<p><a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/simplecircle.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/simplecircle.png" alt="Simple circle" width="414" height="419" /></a></p>
<pre class="brush: js">var stage = document.querySelector('.stage'),
    plots = 10;
    increase = Math.PI * 2 / plots,
    angle = 0,
    x = 0,
    y = 0;

for( var i = 0; i &#60; plots; i++ ) {
  var p = new Plot( stage );
  p.setBackground( 'green' );
  p.setDimensions( 40, 40 );
  x = 100 * Math.cos( angle ) + 200;
  y = 100 * Math.sin( angle ) + 200;
  p.position( x, y );
  angle += increase;
}</pre>
<p>We want 10 things in a circle, so we need to find the angle that we want to put them at. A full circle is two times <code>Math.PI</code>, so all we need to do is divide this. The x and y position of our rectangles can be calculated by the angle we want them at. The x is the cosine, and the y is the sine, as explained earlier in the bit on Pythagoras. All we need to do, then, is center the circle that weâ€™re painting in the stage (<code>200,200</code> is the center of the stage), and we are done. Weâ€™ve painted a circle with a radius of 100 pixels on the canvas in 10 steps.</p>
<p>The problem is that this looks terrible. If we really want to plot things on a circle, then their angles should also point to the center, right? For this, we need to calculate the tangent of the right-angle square, as explained in this <a href="http://www.mathsisfun.com/algebra/trig-finding-angle-right-triangle.html">charming â€œMath is funâ€� page</a>. In JavaScript, we can use <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/atan2"><code>Math.atan2()</code></a> as a shortcut. The result looks much better:</p>
<p><a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/tancircle.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/tancircle.png" alt="Tancircle" width="411" height="414" /></a></p>
<pre class="brush: js">var stage = document.querySelector('.stage'),
    plots = 10;
    increase = Math.PI * 2 / plots,
    angle = 0,
    x = 0,
    y = 0;

for( var i = 0; i &#60; plots; i++ ) {
  var p = new Plot( stage );
  p.setBackground( 'green' );
  p.setDimensions( 40, 40 );
  x = 100 * Math.cos( angle ) + 200;
  y = 100 * Math.sin( angle ) + 200;
  p.rotate( Math.atan2( y - 200, x - 200 ) + 'rad' );
  p.position( x, y );
  angle += increase;
}</pre>
<p>Notice that the rotate transformation in CSS helps us heaps in this case. Otherwise, the math to rotate our rectangles would be much less fun. CSS transformations also take radians and degrees as their value. In this case, we use <code>rad</code>; if you want to rotate with degrees, simply use <code>deg</code> as the value.</p>
<p>How about animating the circle now? Well, the first thing to do is change the script a bit, because we donâ€™t want to have to keep creating new plots. Other than that, all we need to do to <a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/rotatingcircle.html">rotate the circle is to keep increasing the start angle</a>:</p>
<pre class="brush: js">var stage = document.querySelector('.stage'),
    plots = 10;
    increase = Math.PI * 2 / plots,
    angle = 0,
    x = 0,
    y = 0,
    plotcache = [];

for( var i = 0; i &#60; plots; i++ ) {
  var p = new Plot( stage );
  p.setBackground( 'green' );
  p.setDimensions( 40, 40 );
  plotcache.push( p );
}

function rotate(){
  for( var i = 0; i &#60; plots; i++ ) {
    x = 100 * Math.cos( angle ) + 200;
    y = 100 * Math.sin( angle ) + 200;
    plotcache[ i ].rotate( Math.atan2( y - 200, x - 200 ) + 'rad' );
    plotcache[ i ].position( x, y );
    angle += increase;
  }
  angle += 0.06;
}

setInterval( rotate, 1000/30 );</pre>
<p>Want more? How about a <a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/rotatingmessage.html">rotating text message</a> based on this? The tricky thing about this is that we also need to turn the characters 90Â° on each iteration:</p>
<p><a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/rotatingmessage.html"> </a></p>
<p><a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/rotatingmessage.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/rotatedmessage.png" alt="Rotated message" width="410" height="413" /></a></p>
<pre class="brush: js">var stage = document.querySelector('.stage'),
    message = 'Smashing Magazine '.toUpperCase(),
    plots = message.length;
    increase = Math.PI * 2 / plots,
    angle = -Math.PI,
    turnangle = 0,
    x = 0,
    y = 0,
    plotcache = [];

for( var i = 0; i &#60; plots; i++ ) {
  var p = new Plot( stage );
  p.content( message.substr(i,1) );
  p.setDimensions( 40, 40 );
  plotcache.push( p );
}
function rotate(){
  for( var i = 0; i &#60; plots; i++ ) {
    x = 100 * Math.cos( angle ) + 200;
    y = 100 * Math.sin( angle ) + 200;
    // rotation and rotating the text 90 degrees
    turnangle = Math.atan2( y - 200, x - 200 ) * 180 / Math.PI + 90 + 'deg';
    plotcache[ i ].rotate( turnangle );
    plotcache[ i ].position( x, y );
    angle += increase;
  }
  angle += 0.06;
}

setInterval( rotate, 1000/40 );</pre>
<p>Again, nothing here is fixed. You can make the <a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/growrotatingmessage.html">radius of the circle change constantly</a>, as we did with the bouncing banner message earlier (below is only an excerpt):</p>
<pre class="brush: js">multiplier = 80 * Math.sin( angle );
for( var i = 0; i &#60; plots; i++ ) {
  x = multiplier * Math.cos( angle ) + 200;
  y = multiplier * Math.sin( angle ) + 200;
  turnangle = Math.atan2( y - 200, x - 200 ) * 180 / Math.PI + 90 + 'deg';
  plotcache[ i ].rotate( turnangle );
  plotcache[ i ].position( x, y );
  angle += increase;
}
angle += 0.06;</pre>
<p>And, of course, you can <a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/rotaterotatingmessage.html">move the center of the circle</a>, too:</p>
<pre class="brush: js">rx = 50 * Math.cos( angle ) + 200;
ry = 50 * Math.sin( angle ) + 200;
for( var i = 0; i &#60; plots; i++ ) {
  x = 100 * Math.cos( angle ) + rx;
  y = 100 * Math.sin( angle ) + ry;
  turnangle = Math.atan2( y - ry, x - rx ) * 180 / Math.PI + 90 + 'deg';
  plotcache[ i ].rotate( turnangle );
  plotcache[ i ].position( x, y );
  angle += increase;
}
angle += 0.06;</pre>
<p>For a final tip, how about <a href="http://media.smashingmagazine.com/wp-content/uploads/2011/09/boxedrotatingmessage.html">allowing only a certain range of coordinates</a>?</p>
<pre class="brush: js">function rotate() {
  rx = 70 * Math.cos( angle ) + 200;
  ry = 70 * Math.sin( angle ) + 200;
  for( var i = 0; i &#60; plots; i++ ) {
    x = 100 * Math.cos( angle ) + rx;
    y = 100 * Math.sin( angle ) + ry;
    x = contain( 70, 320, x );
    y = contain( 70, 320, y );
    turnangle = Math.atan2( y - ry, x - rx ) * 180 / Math.PI + 90 + 'deg';
    plotcache[ i ].rotate( turnangle );
    plotcache[ i ].position( x, y );
    angle += increase;
  }
  angle += 0.06;
}
function contain( min, max, value ) {
  return Math.min( max, Math.max( min, value ) );
}</pre>
<h4>Summary</h4>
<p>This was just a quick introduction to using exponentials and sine waves and to plotting things on a circle. Have a go with the code, and play with the numbers. It is amazing how many cool effects you can create with a few changes to the radius or by multiplying the angles. To make it easier for you to do this, below are the examples on JSFiddle to play with:</p>
<ul>
<li><a href="http://jsfiddle.net/codepo8/tgEx6/11/">Sine bouncing message</a></li>
<li><a href="http://jsfiddle.net/codepo8/tgEx6/2/">Double sine bouncing message</a></li>
<li><a href="http://jsfiddle.net/codepo8/tgEx6/4/">Offset issue with plotting</a></li>
<li><a href="http://jsfiddle.net/codepo8/tgEx6/8/">Distributing elements on a circle</a></li>
<li><a href="http://jsfiddle.net/codepo8/tgEx6/9/">Distributing elements on a circle with correct angles</a></li>
<li><a href="http://jsfiddle.net/codepo8/tgEx6/7/">Rotating a circle of boxes</a></li>
<li><a href="http://jsfiddle.net/codepo8/tgEx6/10/">Oscillating rotating message</a></li>
<li><a href="http://jsfiddle.net/codepo8/tgEx6/5/">Rotating message in a circle movement</a></li>
<li><a href="http://jsfiddle.net/codepo8/tgEx6/">Boxed rotated message scroller</a></li>
</ul>
<p><em>(il) (al)</em></p>
<hr />
<p><small>Â© Christian Heilmann for <a href="http://www.smashingmagazine.com">Smashing Magazine</a>, 2011.</small></p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/10/a-quick-look-into-the-math-of-animations-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designers Know Your Code: Web Design Tutorials</title>
		<link>http://blogmyquery.com/index.php/2011/10/designers-know-your-code-web-design-tutorials/</link>
		<comments>http://blogmyquery.com/index.php/2011/10/designers-know-your-code-web-design-tutorials/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 10:00:42 +0000</pubDate>
		<dc:creator>Angie Bowen</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://mgmt.noupe.com/?p=55410</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div>
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=noupe-rss&#38;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=noupe-rss&#38;position=1" border="0" alt="" /></a>&#160;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=noupe-rss&#38;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=noupe-rss&#38;position=2" border="0" alt="" /></a>&#160;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=noupe-rss&#38;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=noupe-rss&#38;position=3" border="0" alt="" /></a>
    </div></td></tr></table>
<a href="http://www.noupe.com/design/designers-know-your-code-web-design-tutorials.html"><img src="http://media.noupe.com//uploads/2011/09/css3nav.jpg" width="550" /></a>

As almost any web designer worth their salt, and a large percentage of web developers will tell you, to be fully considered <strong>a web designer</strong> you have to <strong>have some background in code</strong>. Not to the depth that full on developers must, but it really is unfair to the rest of those working on a website with us if we do not have some knowledge in a handful of key areas. Which is where these <strong>web design tutorials</strong> come in.]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=1" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=2" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=noupe-rss&#038;position=3" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=noupe-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<p>As almost any web designer worth their salt, and a large percentage of web developers will tell you, to be fully considered <strong>a web designer</strong> you have to <strong>have some background in code</strong>. Not to the depth that full on developers must, but it really is unfair to the rest of those working on a website with us if we do not have some knowledge in a handful of key areas. Which is where these <strong>web design tutorials</strong> come in.</p>
<p>In this post we have gathered a handful of useful tutorials from these various areas of code that designers should have their hands in. We have standard <strong>CSS</strong> and <strong>CSS3</strong> tutorials, <strong>HTML5</strong> and also <strong>Javascript</strong> tuts as well. A little something for all three of the main code branches that web designers need to always be improving their grasps on. We hope that you find these web design tutorials helpful in your next or current project!</p>
<h3>CSS Tutorials</h3>
<p><a href="http://net.tutsplus.com/tutorials/html-css-techniques/30-css-best-practices-for-beginners/">30 CSS Best Practices for Beginners</a> &#8211; CSS is a language that is used by nearly every developer at some point. While itâ€™s a language that we sometimes take for granted, it is powerful and has many nuances that can help (or hurt) our designs. Here are thirty of the best CSS practices that will keep you writing solid CSS and avoiding some costly mistakes.</p>
<p><a href="http://net.tutsplus.com/tutorials/html-css-techniques/30-css-best-practices-for-beginners/"><img src="http://media.noupe.com//uploads/2011/09/beginnerscss.jpg" alt="" title="beginnerscss" width="500" height="199" class="alignnone size-full wp-image-55419" /></a></p>
<p><a href="http://net.tutsplus.com/tutorials/html-css-techniques/six-ways-to-improve-your-web-typography/">6 Ways To Improve Your Web Typography</a> &#8211; Typography on the web is anything but simple, and for many, it is a troubling mystery. Today, weâ€™re going to review six ways that web designers and developers can improve the typography of the sites they create.</p>
<p><a href="http://net.tutsplus.com/tutorials/html-css-techniques/six-ways-to-improve-your-web-typography/"><img src="http://media.noupe.com//uploads/2011/09/webtypography.jpg" alt="" title="webtypography" width="550" height="211" class="alignnone size-full wp-image-55417" /></a></p>
<p><a href="http://cssglobe.com/post/6089/3-easy-and-fast-css-techniques-for-faux-image">3 Easy and Fast CSS Techniques for Faux Image Cropping</a> &#8211; This article is a summary of a 3 fast and easy CSS techniques you can use to display only a portion of an image in your content. All techniques explained here actually need only couple of lines of CSS.</p>
<p><a href="http://cssglobe.com/post/6089/3-easy-and-fast-css-techniques-for-faux-image"><img src="http://media.noupe.com//uploads/2011/09/imagecroping.jpg" alt="" title="imagecroping" width="432" height="251" class="alignnone size-full wp-image-55418" /></a></p>
<p><a href="http://www.wittysparks.com/2009/09/21/build-multi-level-multi-column-multi-menus-with-pure-css/">Build Multi-level Multi-column Multi Menus with pure CSS</a> &#8211; works perfectly in most browsers, including IE 6, using absolutely no javascript</p>
<p><a href="http://www.wittysparks.com/2009/09/21/build-multi-level-multi-column-multi-menus-with-pure-css/"><img src="http://media.noupe.com//uploads/2011/09/multilevcolmen.jpg" alt="" title="multilevcolmen" width="550" height="275" class="alignnone size-full wp-image-55415" /></a></p>
<p><a href="http://aext.net/2009/10/css-absolute-positioning-create-a-fancy-link-block/">CSS Absolute Positioning: Create A Fancy Link Block</a> &#8211; some tricks to create a fancy link block that make our links more attractive.</p>
<p><a href="http://aext.net/2009/10/css-absolute-positioning-create-a-fancy-link-block/"><img src="http://media.noupe.com//uploads/2011/09/abposlinkblock.jpg" alt="" title="abposlinkblock" width="500" height="252" class="alignnone size-full wp-image-55414" /></a></p>
<p><a href="http://www.problogdesign.com/wordpress/how-to-create-a-beautiful-dropdown-blogroll-without-javascript/">How to Create a Beautiful Dropdown Blogroll Without JavaScript</a> &#8211; Dropdown menus are a great way of including a long list of links without cluttering up your page. The issue though is that they can be hard to style, but look quite ugly if you donâ€™t. There isnâ€™t a lot of flexibility with HTMLâ€™s select tags.</p>
<p><a href="http://www.problogdesign.com/wordpress/how-to-create-a-beautiful-dropdown-blogroll-without-javascript/"><img src="http://media.noupe.com//uploads/2011/09/dropdownblogroll.jpg" alt="" title="dropdownblogroll" width="550" height="142" class="alignnone size-full wp-image-55416" /></a></p>
<h3>CSS3 Tutorials</h3>
<p><a href="http://tutorialzine.com/2010/06/css3-minimalistic-navigation-menu/">CSS3 Minimalistic Navigation Menu</a> &#8211; a simple CSS3 animated navigation menu, which degrades gracefully in older browsers and is future-proofed to work with the next generation of browsers.</p>
<p><a href="http://tutorialzine.com/2010/06/css3-minimalistic-navigation-menu/"><img src="http://media.noupe.com//uploads/2011/09/css3nav.jpg" alt="" title="css3nav" width="550" height="299" class="alignnone size-full wp-image-55412" /></a></p>
<p><a href="http://creativefan.com/css3-tutorial-create-card-pockets-how-to/">CSS3 Tutorial: Sleek Card Pockets using CSS Only</a> &#8211; learn how to create web card pockets using some great new CSS3 techniques.</p>
<p><a href="http://creativefan.com/css3-tutorial-create-card-pockets-how-to/"><img src="http://media.noupe.com//uploads/2011/09/cardpockets.jpg" alt="" title="cardpockets" width="500" height="306" class="alignnone size-full wp-image-55413" /></a></p>
<p><a href="http://www.mightymeta.co.uk/1075/css3-animated-vignette-buttons/">CSS3 Animated Vignette Buttons</a> &#8211; This tutorial uses a patterned background and places vignette-style .pngs over the top which are animated using transition.</p>
<p><a href="http://www.mightymeta.co.uk/1075/css3-animated-vignette-buttons/"><img src="http://media.noupe.com//uploads/2011/09/vignettebuttons.jpg" alt="" title="vignettebuttons" width="550" height="152" class="alignnone size-full wp-image-55946" /></a></p>
<p><a href="http://www.webstuffshare.com/2010/05/css3-music-player-menu/">CSS3 Music Player Menu</a> &#8211; This tutorial maximizes power of CSS3 to create a CSS Music Player Menu with a Photoshop-like effect.</p>
<p><a href="http://www.webstuffshare.com/2010/05/css3-music-player-menu/"><img src="http://media.noupe.com//uploads/2011/09/css3music.jpg" alt="" title="css3music" width="550" height="227" class="alignnone size-full wp-image-55947" /></a></p>
<p><a href="http://www.marcofolio.net/css/3d_animation_using_pure_css3.html">3D Animation Using Pure CSS3</a> &#8211; This tutorial uses the perspective property to create the 3d effect and transform and transition, to animate it.</p>
<p><a href="http://www.marcofolio.net/css/3d_animation_using_pure_css3.html"><img src="http://media.noupe.com//uploads/2011/09/3danimation.jpg" alt="" title="3danimation" width="550" height="339" class="alignnone size-full wp-image-55948" /></a></p>
<p><a href="http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/create-a-swish-css3-folded-ribbon-in-5-minutes/">Create a Swish CSS3 Folded Ribbon in 5 Minutes</a> &#8211; Take one line of markup, a couple of CSS3 rules (no images), and you can have yourself a swish folded ribbon effect in five minutes.</p>
<p><a href="http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/create-a-swish-css3-folded-ribbon-in-5-minutes/"><img src="http://media.noupe.com//uploads/2011/09/css3ribbon.jpg" alt="" title="css3ribbon" width="550" height="294" class="alignnone size-full wp-image-55964" /></a></p>
<h3>HTML5 Tutorials</h3>
<p><a href="http://designshack.co.uk/articles/html/html5-the-basics-1-of-4">HTML5 : The Basics</a> &#8211; This tutorial introduces HTML5 and its basic features as well as explains the key differences from HTML 4.01 and XHTML 1.0 so you can start preparing yourself and your sites for the transition.</p>
<p><a href="http://designshack.co.uk/articles/html/html5-the-basics-1-of-4"><img src="http://media.noupe.com//uploads/2011/09/html5basics.jpg" alt="" title="html5basics" width="507" height="226" class="alignnone size-full wp-image-55951" /></a></p>
<p><a href="http://24ways.org/2009/have-a-field-day-with-html5-forms">Have A Field Day With HTML5 Forms</a> &#8211; Take a look at how to style a beautiful HTML5 form using some advanced CSS and latest CSS3 techniques.</p>
<p><a href="http://24ways.org/2009/have-a-field-day-with-html5-forms"><img src="http://media.noupe.com//uploads/2011/09/html5forms.jpg" alt="" title="html5forms" width="550" height="340" class="alignnone size-full wp-image-55952" /></a></p>
<p><a href="http://jontangerine.com/log/2008/03/preparing-for-html5-with-semantic-class-names">Preparing for HTML5 with Semantic Class Names</a> &#8211; A brief introduction to the new structural elements in the HTML 5 Working Draft, and how to use semantic class names in HTML 4.01 or XHTML 1.0 markup that correspond to the names of those structural elements.</p>
<p><a href="http://jontangerine.com/log/2008/03/preparing-for-html5-with-semantic-class-names"><img src="http://media.noupe.com//uploads/2011/09/html5semantics.jpg" alt="" title="html5semantics" width="550" height="200" class="alignnone size-full wp-image-55953" /></a></p>
<p><a href="http://html5tutorial.net/tutorials/drag-and-drop.html">Drag and Drop</a> &#8211; This tutorial will teach you how to create a HTML 5 page that uses the new drag and drop feature. </p>
<p><a href="http://html5tutorial.net/tutorials/drag-and-drop.html"><img src="http://media.noupe.com//uploads/2011/09/dragndrop.jpg" alt="" title="dragndrop" width="550" height="215" class="alignnone size-full wp-image-55954" /></a></p>
<p><a href="http://sixrevisions.com/web-development/html5-iphone-app/">How to Make an HTML5 iPhone App</a> &#8211; This tutorial will show you how to create an offline HTML5 iPhone application, specifically, a tetris game.</p>
<p><a href="http://sixrevisions.com/web-development/html5-iphone-app/"><img src="http://media.noupe.com//uploads/2011/09/iphoneapp.jpg" alt="" title="iphoneapp" width="550" height="200" class="alignnone size-full wp-image-55955" /></a></p>
<p><a href="http://thinkvitamin.com/code/html5/create-vector-masks-using-the-html5-canvas/">Create Vector Masks Using the HTML5 Canvas</a> &#8211; This tutorial looks at how to use the canvas tag and clipping to create images that arenâ€™t so rectangular.</p>
<p><a href="http://thinkvitamin.com/code/html5/create-vector-masks-using-the-html5-canvas/"><img src="http://media.noupe.com//uploads/2011/09/html5canvas.jpg" alt="" title="html5canvas" width="550" height="232" class="alignnone size-full wp-image-55956" /></a></p>
<h3>Javascript Tutorials</h3>
<p><a href="http://weebtutorials.com/javaBasicTut.php">Javascript â€“ An easy introduction</a> &#8211; Javascript is used to add interactivity and functionality to a site. It has many uses, from detecting the viewers web browser to validating form input.</p>
<p><a href="http://weebtutorials.com/javaBasicTut.php"><img src="http://media.noupe.com//uploads/2011/09/jsintro.jpg" alt="" title="jsintro" width="550" height="269" class="alignnone size-full wp-image-55957" /></a></p>
<p><a href="http://www.elated.com/articles/nested-arrays-in-javascript/">Nested Arrays in Javascript</a> &#8211; Like most programming languages, JavaScript lets you create arrays inside arrays, known as nested arrays. In a nested array, the elements of one array are themselves arrays.</p>
<p><a href="http://www.elated.com/articles/nested-arrays-in-javascript/"><img src="http://media.noupe.com//uploads/2011/09/nestedarrays.jpg" alt="" title="nestedarrays" width="550" height="240" class="alignnone size-full wp-image-55958" /></a></p>
<p><a href="http://net.tutsplus.com/articles/web-roundups/jquery-for-absolute-beginners-video-series/">jQuery for Absolute Beginners</a> &#8211; Fifteen video tutorials that teach you EXACTLY how to use the jQuery library. Start by downloading the library and eventually work up to creating an AJAX style-switcher.</p>
<p><a href="http://net.tutsplus.com/articles/web-roundups/jquery-for-absolute-beginners-video-series/"><img src="http://media.noupe.com//uploads/2011/09/jquery.jpg" alt="" title="jquery" width="550" height="288" class="alignnone size-full wp-image-55959" /></a></p>
<p><a href="http://agilepartners.com/blog/2005/12/07/iphoto-image-resizing-using-javascript/">iPhoto-like image resizing using Javascript</a> &#8211; This tutorial uses the script.aculo.us slider control to capture input values, then converts those values into something useful.</p>
<p><a href="http://agilepartners.com/blog/2005/12/07/iphoto-image-resizing-using-javascript/"><img src="http://media.noupe.com//uploads/2011/09/photoresizing.jpg" alt="" title="photoresizing" width="550" height="300" class="alignnone size-full wp-image-55960" /></a></p>
<p><a href="http://nice-tutorials.blogspot.com/2011/06/learn-how-to-detect-browser-in.html">Learn How To Detect Browser in Javascript</a> &#8211; In this tutorial you will learn how to detect the browser in javascript so that you can then serve the suitable information. </p>
<p><a href="http://nice-tutorials.blogspot.com/2011/06/learn-how-to-detect-browser-in.html"><img src="http://media.noupe.com//uploads/2011/09/jsbrowser.jpg" alt="" title="jsbrowser" width="550" height="212" class="alignnone size-full wp-image-55962" /></a></p>
<p><a href="http://mistonline.in/wp/words-validation-with-javascript/">Words Validation with Javascript</a> &#8211; This tutorial will explain you how to filter out inappropriate words from being updated or sent from your website.</p>
<p><a href="http://mistonline.in/wp/words-validation-with-javascript/"><img src="http://media.noupe.com//uploads/2011/09/jswordval.jpg" alt="" title="jswordval" width="550" height="227" class="alignnone size-full wp-image-55963" /></a></p>
<p><em>(rb)</em></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Noupe?a=bWJ2EzTAN-Y:kYRbUCnY9no:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Noupe?i=bWJ2EzTAN-Y:kYRbUCnY9no:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Noupe?a=bWJ2EzTAN-Y:kYRbUCnY9no:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Noupe?i=bWJ2EzTAN-Y:kYRbUCnY9no:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Noupe?a=bWJ2EzTAN-Y:kYRbUCnY9no:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Noupe?i=bWJ2EzTAN-Y:kYRbUCnY9no:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Noupe?a=bWJ2EzTAN-Y:kYRbUCnY9no:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/Noupe?d=7Q72WNTAKBA" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/10/designers-know-your-code-web-design-tutorials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Searchable Dynamic Content With AJAX Crawling</title>
		<link>http://blogmyquery.com/index.php/2011/09/searchable-dynamic-content-with-ajax-crawling/</link>
		<comments>http://blogmyquery.com/index.php/2011/09/searchable-dynamic-content-with-ajax-crawling/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 11:47:58 +0000</pubDate>
		<dc:creator>Zack Grossbart</dc:creator>
				<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://mgmt.smashingmagazine.com/?p=115900</guid>
		<description><![CDATA[<table width="650">
  <tr>
    <td width="650">
      <div>
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=1" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=1" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=2" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=2" border="0" alt="" />
        </a>
        &#160;
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=3" target="_blank">
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=3" border="0" alt="" />
        </a>
      </div>
    </td>
  </tr>
</table><p>Google Search likes simple, easy-to-crawl websites. You like dynamic websites that show off your work and that really pop. But search engines canâ€™t run your JavaScript. That cool AJAX routine that loads your content is hurting your SEO. Googleâ€™s robots parse HTML with ease; they can pull apart Word documents, PDFs and even images from the far corners of your website. But as far as theyâ€™re concerned, AJAX content is invisible.</p>

<p><a href="http://coding.smashingmagazine.com/2011/09/27/searchable-dynamic-content-with-ajax-crawling/" title="Searchable Dynamic Content With AJAX Crawling"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/ajax-frontpage.gif" width="509" height="415" /></a></p>

<p>AJAX has revolutionized the Web, but it has also hidden its content. If you have a Twitter account, try viewing the source of your profile page. There are no tweets thereâ€Šâ€”â€Šjust code! Almost everything on a Twitter page is built dynamically through JavaScript, and the crawlers canâ€™t see any of it. Thatâ€™s why Google developed AJAX crawling.</p>]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
        <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=1" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=1" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=2" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=2" border="0" alt="" /><br />
        </a><br />
        &nbsp;<br />
        <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=3" ><br />
          <img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=3" border="0" alt="" /><br />
        </a>
      </div>
</td>
</tr>
</table>
<p>Google Search likes simple, easy-to-crawl websites. You like dynamic websites that show off your work and that really pop. But search engines canâ€™t run your JavaScript. That cool AJAX routine that loads your content is hurting your SEO.</p>
<p>Googleâ€™s robots parse HTML with ease; they can pull apart Word documents, PDFs and even images from the far corners of your website. But as far as theyâ€™re concerned, AJAX content is invisible.</p>
<h3>The Problem With AJAX</h3>
<p>AJAX has revolutionized the Web, but it has also hidden its content. If you have a Twitter account, try viewing the source of your profile page. There are no tweets thereâ€Šâ€”â€Šjust code! Almost everything on a Twitter page is built dynamically through JavaScript, and the crawlers canâ€™t see any of it. Thatâ€™s why Google developed <a href="http://code.google.com/web/ajaxcrawling">AJAX crawling</a>.</p>
<p>Because Google canâ€™t get dynamic content from HTML, you will need to provide it another way. But there are two big problems: Google wonâ€™t run your JavaScript, and it doesnâ€™t trust you.</p>
<p>Google indexes the entire Web, but it doesnâ€™t run JavaScript. Modern websites are little applications that run in the browser, but running those applications as they index is just too slow for Google and everyone else.</p>
<p>The trust problem is trickier. Every website wants to come out first in search results; your website competes with everyone elseâ€™s for the top position. Google canâ€™t just give you an API to return your content because some websites use dirty tricks like <a href="http://en.wikipedia.org/wiki/Cloaking">cloaking</a> to try to rank higher. Search engines canâ€™t trust that youâ€™ll do the right thing.</p>
<p>Google needs a way to let you serve AJAX content to browsers while serving simple HTML to crawlers. In other words, you need the same content in multiple formats.</p>
<h3>Two URLs For The Same Content</h3>
<p>Letâ€™s start with a simple example. Iâ€™m part of an open-source project called Spiffy UI. Itâ€™s a <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> (GWT) framework for REST and rapid development. We wanted to show off our framework, so we made <a href="http://www.spiffyui.org">SpiffyUI.org</a> using GWT.</p>
<p>GWT is a dynamic framework that puts all of our content in JavaScript. Our <code>index.html</code> file looks like this:</p>
<pre class="brush: html">&#60;body&#62;
   &#60;script type="text/javascript" language="javascript"
   src="org.spiffyui.spsample.index.nocache.js"&#62;&#60;/script&#62;
&#60;/body&#62;</pre>
<p>Everything is added to the page with JavaScript, and we control our content with <a href="http://en.wikipedia.org/wiki/Hashtag#Hashtags">hash tags</a> (Iâ€™ll explain why a little later). Every time you move to another page in our application, you get a new hash tag. Click on the â€œCSSâ€� link and youâ€™ll end up here:</p>
<pre class="brush: html">http://www.spiffyui.org#css</pre>
<p>The URL in the address bar will look like this in most browsers:</p>
<pre class="brush: html">http://www.spiffyui.org/?css</pre>
<p>Weâ€™ve fixed it up with HTML5. Iâ€™ll show you how later in this article.</p>
<p>This simple hash works well for our application and makes it bookmarkable, but it isnâ€™t crawlable. Google doesnâ€™t know what a hash tag means or how to get the content from it, but it does provide an alternate method for a website to return content. So, we let Google know that our hash is really JavaScript code instead of just an anchor on the page by adding an exclamation point (a â€œbangâ€�), like this:</p>
<pre class="brush: html">http://www.spiffyui.org#!css</pre>
<p>This hash bang is the secret sauce in the whole AJAX crawling scheme. When Google sees these two characters together, it knows that more content is hidden by JavaScript. It gives us a chance to return the full content by making a second request to a special URL:</p>
<pre class="brush: html">http://www.spiffyui.org?_escaped_fragment_=css</pre>
<p>The new URL has replaced the <code>#!</code> with <code>?_escaped_fragment_=</code>. Using a URL parameter instead of a hash tag is important, because parameters are sent to the server, whereas hash tags are available only to the browser.</p>
<p>That new URL lets us return the same content in HTML format when Googleâ€™s crawler requests it. Confused? Letâ€™s look at how it works, step by step.</p>
<h3>Snippets Of HTML</h3>
<p>The whole page is rendered in JavaScript. We needed to get that content into HTML so that it is accessible to Google. The first step was to separate SpiffyUI.org into snippets of HTML.</p>
<p>Google still thinks of a website as a set of pages, so we needed to serve our content that way. This was pretty easy with our application, because we have a set of pages, and each one is a separate logical section. The first step was to make the pages bookmarkable.</p>
<h4>Bookmarking</h4>
<p>Most of the time, JavaScript just changes something <em>within</em> the page: when you click that button or pop up that panel, the URL of the page does not change. Thatâ€™s fine for simple pages, but when youâ€™re serving content through JavaScript, you want give users unique URLs so that they can bookmark certain areas of your application.</p>
<p>JavaScript applications can change the URL of the current page, so they usually support bookmarking via the addition of hash tags. Hash tags work better than any other URL mechanism because theyâ€™re not sent to the server; theyâ€™re the only part of the URL that can be changed without having to refresh the page.</p>
<p>The hash tag is essentially a value that makes sense in the context of your application. Choose a tag that is logical for the area of your application that it represents, and add it to the hash like this:</p>
<pre class="brush: html">http://www.spiffyui.org#css</pre>
<p>When a user accesses this URL again, we use JavaScript to read the hash tag and send the user to the page that contains the CSS.</p>
<p>You can choose anything you want for your hash tag, but try to keep it readable, because users will be looking at it. We give our hashes tags like <code>css</code>, <code>rest</code> and <code>security</code>.</p>
<p>Because you can name the hash tag anything you want, adding the extra bang for Google is easy. Just slide it between the hash and the tag, like this:</p>
<pre class="brush: html">http://www.spiffyui.org#!css</pre>
<p>You can manage all of your hash tags manually, but most JavaScript history frameworks will do it for you. All of the plug-ins that support HTML4 use hash tags, and many of them have options for making URLs bookmarkable. We use <a href="https://github.com/balupton/history.js">History.js</a> by <a href="http://balupton.com/">Ben Lupton</a>. Itâ€™s easy to use, itâ€™s open source, and it has excellent support for HTML5 history integration. Weâ€™ll talk more about that shortly.</p>
<h4>Serving Up Snippets</h4>
<p>The hash tag makes an application bookmarkable, and the bang makes it crawlable. Now Google can ask for special escaped-fragment URLs like so:</p>
<p><a href="http://coding.smashingmagazine.com/wp-content/uploads/2011/07/CrawlerServerDiagram3.png"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/CrawlerServerDiagram-front-page1.jpg" alt="screenshot" width="500" height="346" /></a></p>
<p>When the crawler accesses our ugly URL, we need to return simple HTML. We canâ€™t handle that in JavaScript because the crawler doesnâ€™t run JavaScript in the crawler. So, it all has to come from the server.</p>
<p>You can implement your server in PHP, Ruby or any other language, as long as it delivers HTML. SpiffyUI.org is a Java application, so we deliver our content with a <a href="http://en.wikipedia.org/wiki/Java_Servlet">Java servlet</a>.</p>
<p>The escaped fragment tells us what to serve, and the servlet gives us a place to serve it from. Now we need the actual content.</p>
<p>Getting the content to serve is tricky. Most applications mix the content in with the code; but we donâ€™t want to parse the readable text out of the JavaScript. Luckily, Spiffy UI has an HTML-templating mechanism. The templates are embedded in the JavaScript but also included on the server. When the escaped fragment looks for the ID <code>css</code>, we just have to serve <code>CSSPanel.html</code>.</p>
<p>The template without any styling looks very plain, but Google just needs the content. Users see our page with all of the styles and dynamic features:</p>
<p><a href="http://coding.smashingmagazine.com/wp-content/uploads/2011/07/css_page_normal.png"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/specific-styles-500.jpg" alt="screenshot" width="500" height="438" /></a></p>
<p>Google gets only the unstyled version:</p>
<p><a href="http://coding.smashingmagazine.com/wp-content/uploads/2011/07/css_page_escaped1.png"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/google-specific-sytles.jpg" alt="screenshot" width="500" height="446" /></a></p>
<p>You can see all of the source code for our <a href="http://spiffyui.googlecode.com/svn/trunk/spiffyui-app/src/main/java/org/spiffyui/spsample/server/SiteMapServlet.java"><code>SiteMapServlet.java</code></a> servlet. This servlet is mostly just a look-up table that takes an ID and serves the associated content from somewhere on our server. Itâ€™s called <code>SiteMapServlet.java</code> because this class also handles the generation of our site map.</p>
<h3>Tying It All Together With A Site Map</h3>
<p><a href="http://www.spiffyui.org/sitemap.xml">Our site map</a> tells the crawler whatâ€™s available in our application. Every website should have a site map; AJAX crawling doesnâ€™t work without one.</p>
<p>Site maps are simple XML documents that list the URLs in an application. They can also include data about the priority and update frequency of the appâ€™s pages. Normal entries for site maps look like this:</p>
<pre class="brush: html">&#60;url&#62;
   &#60;loc&#62;http://www.spiffyui.org/&#60;/loc&#62;
   &#60;lastmod&#62;2011-07-26&#60;/lastmod&#62;
   &#60;changefreq&#62;daily&#60;/changefreq&#62;
   &#60;priority&#62;1.0&#60;/priority&#62;
&#60;/url&#62;</pre>
<p>Our AJAX-crawlable entries look like this:</p>
<pre class="brush: xml">&#60;url&#62;
   &#60;loc&#62;http://www.spiffyui.org/#!css&#60;/loc&#62;
   &#60;lastmod&#62;2011-07-26&#60;/lastmod&#62;
   &#60;changefreq&#62;daily&#60;/changefreq&#62;
   &#60;priority&#62;0.8&#60;/priority&#62;
&#60;/url&#62;</pre>
<p>The hash bang tells Google that this is an escaped fragment, and the rest works like any other page. You can mix and match AJAX URLs and regular URLs, and you can use only one site map for everything.</p>
<p>You could write your site map by hand, but there are tools that will save you a lot of time. The key is to format the site map well and submit it to Google Webmaster Tools.</p>
<h3>Google Webmaster Tools</h3>
<p><a href="https://www.google.com/webmasters/tools">Google Webmaster Tools</a> gives you the chance to tell Google about your website. Log in with your Google ID, or create a new account, and then verify your website.</p>
<p><a href="http://coding.smashingmagazine.com/wp-content/uploads/2011/07/google_wmt_verification.png"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/google.wemaster-central.jpg" alt="screenshot" width="500" height="485" /></a></p>
<p>Once youâ€™ve verified, you can submit your site map and then Google will start indexing your URLs.</p>
<p>And then you wait. This part is maddening. It took about two weeks for SpiffyUI.org to show up properly in Google Search. I posted to the help forums half a dozen times, thinking it was broken.</p>
<p>Thereâ€™s no easy way to make sure everything is working, but there are a few tools to help you see whatâ€™s going on. The best one is <a href="http://www.google.com/support/webmasters/bin/answer.py?hl=en&#38;answer=158587">Fetch as Googlebot</a>, which shows you exactly what Google sees when it crawls your website. You can access it in your dashboard in Google Webmaster Tools under â€œDiagnostics.â€�</p>
<p><a href="http://coding.smashingmagazine.com/wp-content/uploads/2011/07/googlebot_fetch.png"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/webmastertools-2.jpg" alt="screenshot" width="500" height="476" /></a></p>
<p>Enter a hash bang URL from your website, and click â€œFetch.â€� Google will tell you whether the fetch has succeeded and, if it has, will show you the content it sees.</p>
<p><a href="http://coding.smashingmagazine.com/wp-content/uploads/2011/07/googlebot_results.png"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/webastertools-3.jpg" alt="screenshot" width="500" height="494" /></a></p>
<p>If Fetch as Googlebot works as expected, then youâ€™re returning the escaped URLs correctly. But you should check a few more things:</p>
<ul>
<li><a href="http://www.validome.org/google/validate">Validate your site map</a>.</li>
<li>Manually try the URLs in your site map. Make sure to try the hash-bang and escaped versions.</li>
<li>Check the Google result for your website by searching for <code>site:www.yoursite.com</code>.</li>
</ul>
<h3>Making Pretty URLs With HTML5</h3>
<p>Twitter leaves the hash bang visible in its URLs, like this:</p>
<pre class="brush: html">http://twitter.com/#!/ZackGrossbart</pre>
<p>This works well for AJAX crawling, but again, itâ€™s slightly ugly. You can make your URLs prettier by integrating <a href="http://www.w3.org/TR/html5/history.html">HTML5 history</a>.</p>
<p>Spiffy UI uses HTML5 history integration to turn a hash-bang URL like thisâ€¦</p>
<pre class="brush: html">http://www.spiffyui.org#!css</pre>
<p>â€¦ into a pretty URL like this:</p>
<pre class="brush: html">http://www.spiffyui.org?css</pre>
<p>HTML5 history makes it possible to change this URL parameter, because the hash tag is the only part of the URL that you can change in HTML4. If you change anything else, the entire page reloads. HTML5 history changes the entire URL without refreshing the page, and we can make the URL look any way we want.</p>
<p>This nicer URL works in our application, but we still list the hash-bang version on our site map. And when browsers access the hash-bang URL, we change it to the nicer one with a little JavaScript.</p>
<h3>Cloaking</h3>
<p>Earlier, I mentioned cloaking. It is the practice of trying to boost a websiteâ€™s ranking in search results by showing one set of pages to Google and another to regular browsers. Google doesnâ€™t like cloaking and may <a href="http://www.google.com/support/webmasters/bin/answer.py?answer=66355">remove offending websites from its search index</a>.</p>
<p>AJAX-crawling applications always show different results to Google than to regular browsers, but it isnâ€™t cloaking if the HTML snippets contain the same content that the user would see in the browser. The real mystery is how Google can tell whether a website is cloaking or not; crawlers canâ€™t compare content programmatically because they donâ€™t run JavaScript. Itâ€™s all part of Googleâ€™s Googley power.</p>
<p>Regardless of how itâ€™s detected, cloaking is a bad idea. You might not get caught, but if you do, youâ€™ll be removed from the search index.</p>
<h3>Hash Bang Is A Little Ugly, But It Works</h3>
<p>Iâ€™m an engineer, and my first response to this scheme is â€œYuck!â€� It just feels wrong; weâ€™re warping the purpose of URLs and relying on magic strings. But I understand where Google is coming from; the problem is extremely difficult. Search engines need to get useful information from inherently untrustworthy sources: us.</p>
<p>Hash bangs shouldnâ€™t replace every URL on the Web. Some websites have had <a href="http://www.webmonkey.com/2011/02/gawker-learns-the-hard-way-why-hash-bang-urls-are-evil/">serious problems</a> with hash-bang URLs because they rely on JavaScript to serve content. Simple pages donâ€™t need hash bangs, but AJAX pages do. The URLs do look a bit ugly, but you can fix that with HTML5.</p>
<h4>Further Reading</h4>
<p>Weâ€™ve covered a lot in this article. Supporting AJAX crawling means that you need to change your clientâ€™s code and your serverâ€™s code. Here are some links to find out more:</p>
<ul>
<li>â€œ<a href="http://code.google.com/web/ajaxcrawling/">Making AJAX Applications Crawlable</a>,â€� Google Code</li>
<li>â€œ<a href="http://www.w3.org/TR/html5/history.html">Session History and Navigation</a>,â€� HTML5 specification, section 5.4</li>
<li><a href="http://www.sitemaps.org/">sitemaps.org</a></li>
<li><a href="https://www.google.com/webmasters/tools">Google Webmaster Tools</a></li>
<li><a href="https://code.google.com/p/spiffyui/source/checkout">Spiffy UI source code</a>, with a complete example of AJAX crawling.</li>
</ul>
<p><em>Thanks to Kristen Riley for help with some of the images in this article.</em></p>
<p><em>(al)</em></p>
<hr />
<p><small>Â© Zack Grossbart for <a href="http://www.smashingmagazine.com">Smashing Magazine</a>, 2011.</small></p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/09/searchable-dynamic-content-with-ajax-crawling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful Node.js Tools, Tutorials And Resources</title>
		<link>http://blogmyquery.com/index.php/2011/09/useful-node-js-tools-tutorials-and-resources/</link>
		<comments>http://blogmyquery.com/index.php/2011/09/useful-node-js-tools-tutorials-and-resources/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 08:26:56 +0000</pubDate>
		<dc:creator>Luca Degasperi</dc:creator>
				<category><![CDATA[Feeds]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[kranthi]]></category>

		<guid isPermaLink="false">http://mgmt.smashingmagazine.com/?p=114969</guid>
		<description><![CDATA[<table width="650"><tr><td width="650"><div>
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=1" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=1" border="0" alt="" /></a>&#160;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=2" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=2" border="0" alt="" /></a>&#160;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#38;collection=smashing-rss&#38;position=3" target="_blank"><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#38;collection=smashing-rss&#38;position=3" border="0" alt="" /></a>
    </div></td></tr></table>
<p>Created by Ryan Dahl in 2009, <a href="http://nodejs.org/">Node.js</a> is a relatively new technology which has gained a lot of popularity among Web developers recently. However, not everyone knows what it really is. Node.js is essentially a server-side JavaScript environment that uses an asynchronous event-driven model. What this means is simple: itâ€™s an environment which is intended for writing scalable, high performance network applications. It's like Ruby's Event Machine or Python's Twisted, but it takes the event model a bit furtherâ€”it presents the event loop as a language construct instead of as a library.</p>

<p><a href="http://coding.smashingmagazine.com/2011/09/16/useful-node-js-tools-tutorials-and-resources/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/useful-node-js-tools-tutorials-resources.jpg" width="500" height="300" alt="The secrets of Nodeâ€™s success" /></a></p>

<p> And thatâ€™s not all: whatâ€™s really great about Node.js is the thousands of modules available for any purpose, as well as the vibrant community behind this young project. In this round-up, you will find the <strong>most useful resources for Node.js</strong>, from handy tools to detailed tutorials, not to mention in-depth articles and resources on this promising technology. Do you use Node.js already? Let us know in the comments to this post!</p>]]></description>
			<content:encoded><![CDATA[<table width="650">
<tr>
<td width="650">
<div style="width:650px;">
      <img src="http://statisches.auslieferung.commindo-media-ressourcen.de/advertisement.gif" alt="" border="0" /><br />
      <a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=1" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=1" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=2" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=2" border="0" alt="" /></a>&nbsp;<a href="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=target&#038;collection=smashing-rss&#038;position=3" ><img src="http://auslieferung.commindo-media-ressourcen.de/random.php?mode=image&#038;collection=smashing-rss&#038;position=3" border="0" alt="" /></a>
    </div>
</td>
</tr>
</table>
<p>Created by Ryan Dahl in 2009, <a href="http://nodejs.org/">Node.js</a> is a relatively new technology which has gained a lot of popularity among Web developers recently. However, not everyone knows what it really is. Node.js is essentially a server-side JavaScript environment that uses an asynchronous event-driven model. What this means is simple: itâ€™s an environment which is intended for writing scalable, high performance network applications. It&#8217;s like Ruby&#8217;s Event Machine or Python&#8217;s Twisted, but it takes the event model a bit furtherâ€”it presents the event loop as a language construct instead of as a library.</p>
<p>And thatâ€™s not all: whatâ€™s really great about Node.js is the thousands of modules available for any purpose, as well as the vibrant community behind this young project. In this round-up, you will find the <strong>most useful resources for Node.js</strong>, from handy tools to detailed tutorials, not to mention in-depth articles and resources on this promising technology. Do you use Node.js already? Let us know in the comments to this post!</p>
<h3>Useful Node.js Tools</h3>
<p><a href="https://github.com/mape/node-express-boilerplate">Node Express Boilerplate</a><br />
Node Express Boilerplate gives the developer a clean slate, while bundling enough useful features to remove all of those redundant tasks that can derail a project before it even gets started.</p>
<p class="showcase"><a href="https://github.com/mape/node-express-boilerplate"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/035.jpg" width="500" height="300" alt="Node Express Boilerplate" /></a></p>
<p><a href="http://socket.io/">Socket.IO</a><br />
Socket.IO is a cross-browser Web socket that aims to make real-time apps possible in every browser and mobile device, blurring the distinctions between the various transport mechanisms. Itâ€™s care-free real time, in JavaScript.</p>
<p class="showcase"><a href="http://socket.io/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/005.jpg" width="502" height="297" alt="Socket.IO: Cross-browser WebSocket for realtime apps." /></a></p>
<p><a href="http://visionmedia.github.com/masteringnode/">Mastering Node</a><br />
With Mastering Node, you can write high-concurrency Web servers, using the CommonJS module system, Node.jsâ€™s core libraries, third-party modules, high-level Web development and more.</p>
<p class="showcase"><a href="http://visionmedia.github.com/masteringnode/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-007.jpg" width="500" height="300" alt="Mastering Node" /></a></p>
<p><a href="http://logio.org/">Log.io</a><br />
Your infrastructure may have hundreds of log files spread across dozens of machines. To help you monitor deployments and troubleshoot, Log.io lets you instantly see composite streams of log messages in a single user interface.</p>
<p class="showcase"><a href="http://logio.org/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/008.jpg" width="502" height="302" alt="Log.io" /></a></p>
<p><a href="https://github.com/rootslab/formaline">Formaline</a><br />
Formaline is a low-level, full-featured (Node.js) module for handling form requests (HTTP POSTs and PUTs) and for parsing uploaded files quickly. It is also ready to use with, for example, middleware such as Connect.</p>
<p class="showcase"><a href="https://github.com/rootslab/formaline"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-010.jpg" width="500" height="300" alt="Formaline" /></a></p>
<p><a href="http://ldapjs.org/">LDAPjs</a><br />
LDAPjs is a pure-JavaScript, from-scratch framework for implementing LDAP clients and servers in Node.js. It is intended for developers who are used to interacting with HTTP services in Node.js and Express.</p>
<p class="showcase"><a href="http://ldapjs.org/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/041.jpg" width="502" height="302" alt="ldapjs" /></a></p>
<p><a href="https://github.com/isaacs/node-supervisor">Node Supervisor</a><br />
This is a little supervisor script for Node.js. It runs your program and watches for code changes, so you can have hot-code reloading-ish behavior without worrying about memory leaks or having to clean up all of the inter-module references, and without a whole new <code>require</code> system.</p>
<p class="showcase"><a href="https://github.com/isaacs/node-supervisor"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-043.jpg" width="500" height="300" alt="Node Supervisor" /></a></p>
<p><a href="http://jade-lang.com/">Jade &#8211; Template Engine</a><br />Jade is a template engine for Node.js applications. It combines great power and flexibility with a nice and clean syntax.</p>
<p class="showcase"><a href="http://jade-lang.com/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-050.jpg" width="500" height="300" alt="Jade - Template Engine" /></a></p>
<p><a href="http://expressjs.com/">Express</a><br />
This is a Sinatra-inspired Web development framework for Node.js: fast, flexible and sexy.</p>
<p class="showcase"><a href="http://expressjs.com/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-004.jpg" width="500" height="300" alt="Express - Node web framework" /></a></p>
<p><a href="https://github.com/hookio/hook.io">Hook.io</a><br />hook.io creates a distributed node.js EventEmitter that works cross-process / cross-platform / cross-browser. Think of it like a real-time event bus that works anywhere JavaScript is supported.</p>
<p class="showcase"><a href="https://github.com/hookio/hook.io"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-051.jpg" width="500" height="300" alt="Hook.io" /></a></p>
<p><a href="http://npmjs.org/">Node Package Manager</a><br />NPM is a package manager for node. You can use it to install and publish your node programs. It manages dependencies and does other cool stuff.</p>
<p class="showcase"><a href="http://npmjs.org/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-053.jpg" width="500" height="300" alt="Node Package Manager" /></a></p>
<p><a href="https://github.com/soldair/node-qrcode">Node-QRcode</a><br />
Despite being quite young, Node.js already has a huge number of libraries for every possible application. This one is a QR code generator.</p>
<p class="showcase"><a href="https://github.com/soldair/node-qrcode"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-037.jpg" width="500" height="300" alt="Node QRCode Generator" /></a></p>
<p><a href="https://github.com/mixu/nwm">NWM</a><br />
NWM is a dynamic window manager for X that was written at NodeKO 2011. It uses libev to interface with X11, and it allows you to lay out windows in Node.js.</p>
<p class="showcase"><a href="https://github.com/mixu/nwm"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-046.jpg" width="500" height="300" alt="NWM - Node Window Manager" /></a></p>
<p><a href="http://bricksjs.com/index.html">Bricks.js</a><br />
Bricks.js is an advanced modular Web framework built on Node.js. It is highly flexible. Bricks.js can be used as a standalone static Web server, a basic routing framework or a multi-level Apache-like routing system; and it is modular enough to have the capability to completely switch out its routing engine.</p>
<p class="showcase"><a href="http://bricksjs.com/index.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-038.jpg" width="500" height="300" alt="Bricks.js" /></a></p>
<p><a href="https://github.com/joyent/node/wiki/modules#templating">Node.js Modules</a><br />A list of almost all the Node.js most famous modules organized by category. This list definitively is worth a look.</p>
<p class="showcase"><a href="https://github.com/joyent/node/wiki/modules#templating"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-054.jpg" width="500" height="300" alt="Node.js Modules" /></a></p>
<p><a href="http://www.catonmat.net/blog/browserling-open-sources-90-node-modules/">90 open-source Node.js modules</a><br />
Recently, Browserling released over 90 Node.js modules to the open-source community. Some of them are small and strange modules, others might be pretty useful for your next Node.js project.</p>
<p class="showcase"><a href="http://www.catonmat.net/blog/browserling-open-sources-90-node-modules/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/048.jpg" width="502" height="297" alt="90 Opensource Node.js modules" /></a></p>
<p><a href="http://calip.so/">Calipso</a><br />
Calipso is a content management system (CMS) based on the NodeJS server.</p>
<p class="showcase"><a href="http://calip.so/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/001.jpg" width="502" height="312" alt="Calipso - A NodeJS CMS" /></a></p>
<p><a href="http://pdfkit.org/">PDFKit</a><br />
PDFKit is a PDF document-generation library for Node.js that makes it easy to create complex, multi-page, printable documents. It is written in pure CoffeeScript, but you can use the API in plain â€™ol JavaScript if you like. The API embraces chain-ability, and it includes both low-level functions as well as abstractions for higher-level functionality.</p>
<p class="showcase"><a href="http://pdfkit.org/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/002.jpg" width="502" height="301" alt="PDFKit - A PDF Generation Library for Node" /></a></p>
<p><a href="https://github.com/indexzero/forever">Forever</a><br />
A simple CLI tool to ensure that a given script runs continuously (i.e. forever).</p>
<p class="showcase"><a href="https://github.com/indexzero/forever"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-003.jpg" width="500" height="300" alt="Forever - Make Scripts run Forever" /></a></p>
<h3>Introducing Node.js</h3>
<p><a href="http://net.tutsplus.com/tutorials/javascript-ajax/this-time-youll-learn-node-js/">Node.js Step by Step</a><br />
Node.js is an amazing new technology, but unless youâ€™re a JavaScript developer, the process of becoming acquainted with it can quickly become a bit overwhelming. If you want to learn how to use Node.js, this set of articles and screencasts might do the trick.</p>
<p class="showcase"><a href="http://net.tutsplus.com/tutorials/javascript-ajax/this-time-youll-learn-node-js/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-nettuts.jpg" width="502" height="226" alt="Node.js Step by Step" /></a></p>
<p><a href="http://stackoverflow.com/questions/1884724/what-is-node-js">What Is Node.js?</a><br />
Another interesting discussion on StackOverflow about what Node.js is and is not. Recommended for those who are approaching Node.js for the first time.</p>
<p class="showcase"><a href="http://stackoverflow.com/questions/1884724/what-is-node-js"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/026.jpg" width="502" height="316" alt="What is node.js? - Stack Overflow" /></a></p>
<p><a href="http://net.tutsplus.com/tutorials/javascript-ajax/learning-serverside-javascript-with-node-js/">Learning Server-Side JavaScript</a><br />
Node.js is all the buzz at the moment, and it makes creating high-performance, real-time Web applications easy. It allows JavaScript to be used end to end, on both the server and client. This tutorial walks you through from installing Node.js and writing your first â€œHello Worldâ€� program to building a scalable streaming Twitter server.</p>
<p class="showcase"><a href="http://net.tutsplus.com/tutorials/javascript-ajax/learning-serverside-javascript-with-node-js/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-021.jpg" width="500" height="300" alt="Learning Server-Side JavaScript" /></a></p>
<p><a href="http://www.pavingways.com/nodejs-node-is-important-introduction_1618.html">Node.js Is Important: An Introduction</a><br />
â€œOnce in a while, you come across a technology and are blown away by it. You feel that something like this should have been around much earlier and that it will be a significant milestone, not just in your own life as a developer but in general.</p>
<p class="showcase"><a href="http://www.pavingways.com/nodejs-node-is-important-introduction_1618.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-024.jpg" width="500" height="300" alt="Node.js is Important. An Introduction" /></a></p>
<p><a href="http://radar.oreilly.com/2011/06/node-javascript-success.html">The Secrets of Nodeâ€™s Success</a><br />
In the short time since its initial release in late 2009, Node.js has captured the interest of thousands of experienced developers, grown a package manager and a corpus of interesting modules and applications, and even spawned a number of start-ups. What is it about this technology that makes it interesting to developers? And why has it succeeded while other server-side JavaScript implementations linger in obscurity or fail altogether?</p>
<p class="showcase"><a href="http://radar.oreilly.com/2011/06/node-javascript-success.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-023.jpg" width="500" height="300" alt="The secrets of Nodeâ€™s success" /></a></p>
<p><a href="http://shinetech.com/thoughts/thought-articles/139-asynchronous-code-design-with-nodejs">Asynchronous Code Design with Node.js</a><br />The asynchronous event-driven I/O of Node.js is currently evaluated by many enterprises as a high-performance alternative to the traditional synchronous I/O of multi-threaded enterprise application server. The asynchronous nature means that enterprise developers have to learn new programming patterns, and unlearn old ones</p>
<p class="showcase"><a href="http://shinetech.com/thoughts/thought-articles/139-asynchronous-code-design-with-nodejs"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/async.gif" width="502" height="297" alt="Asynchronous Code Design with Node.js" /></a></p>
<p><a href="http://fennb.com/nodejs-a-giant-step-backwards">A Giant Step Backwards?</a><br />
In this article, Fenn Bailey expresses his opinion of Node.js and why he sometimes thinks Node.js is a step backward compared to other solutions.</p>
<p class="showcase"><a href="http://fennb.com/nodejs-a-giant-step-backwards"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/019.jpg" width="502" height="252" alt="A giant step backwards?" /></a></p>
<p><a href="http://blog.ankurgoyal.com/post/6433642218/node-js-is-backwards">Node.js Is Backwards</a><br />
A hot topic in computing is parallel programming in languages such as Erlang. Will JavaScript join the party?</p>
<p class="showcase"><a href="http://blog.ankurgoyal.com/post/6433642218/node-js-is-backwards"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-020.jpg" width="500" height="300" alt="Node.js is backwards" /></a></p>
<h3>Videos And Screencasts On Node.js</h3>
<p><a href="http://joyeur.com/2011/08/11/node-js-meetup-distributed-web-architectures/">Node.js Meetup: Distributed Web Architectures</a><br />
A series of videos from the Node.js Meetup at Joyent headquarters, discussing how to build distributed Web architectures with Node.js.</p>
<p class="showcase"><a href="http://joyeur.com/2011/08/11/node-js-meetup-distributed-web-architectures/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-022.jpg" width="500" height="300" alt="Node.js Meetup: Distributed Web Architectures" /></a></p>
<p><a href="http://www.youtube.com/watch?v=jo_B4LTHi3I">Introduction to Node.js with Ryan Dahl</a><br />In this presentation Ryan Dahl, the man behind Node.js will introduce you to this event-driven I/O framework with a few examples showing Node.js in action.</p>
<p class="showcase"><a href="http://www.youtube.com/watch?v=jo_B4LTHi3I"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-055.jpg" width="500" height="300" alt="Introduction to Node.js with Ryan Dahl" /></a></p>
<p><a href="http://vimeo.com/18077379">SenchaCon 2010: Server-side JavaScript with Node, Connect &#038; Express on Vimeo</a><br />Node.js has unleashed a new wave of interest in server side Javascript. In this session, you&#8217;ll learn how to get productive with node.js by leveraging Connect and Express node middleware.</p>
<p class="showcase"><a href="http://vimeo.com/18077379"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-056.jpg" width="500" height="300" alt="SenchaCon 2010: Server-side JavaScript with Node, Connect &#038; Express on Vimeo" /></a></p>
<h3>Technical Articles And Tutorials On Node.js</h3>
<p><a href="http://blog.nodejitsu.com/http-proxy-intro">Proxying HTTP and Web Sockets in Node</a><br />
This guide is geared to beginners and people who are unfamiliar with reverse HTTP proxying, Web socket proxying, load balancing, virtual host configuration, request forwarding and other Web proxying concepts.</p>
<p class="showcase"><a href="http://blog.nodejitsu.com/http-proxy-intro"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-012.jpg" width="500" height="300" alt="Proxying HTTP and Websockets in Node" /></a></p>
<p><a href="http://stella.laurenzo.org/2011/03/bulletproof-node-js-coding/">Bulletproof Node.js Coding</a><br />
â€œRight around the time that I started the third refactoring/rewrite of the code, I felt like I had gotten a feel for how to write bulletproof code, and I thought it would be worth sharing some of the style and conventions I came to adopt.â€�</p>
<p class="showcase"><a href="http://stella.laurenzo.org/2011/03/bulletproof-node-js-coding/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-016.jpg" width="500" height="300" alt="Bulletproof Node.js Coding" /></a></p>
<p><a href="http://syskall.com/how-to-write-your-own-native-nodejs-extension">How to Write a Native Node.js Extension</a><br />
In this tutorial, you will learn how to write a native Node.js extension the right way, from the very basics to packaging the extension for NPM.</p>
<p class="showcase"><a href="http://syskall.com/how-to-write-your-own-native-nodejs-extension"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-018.jpg" width="500" height="300" alt="How to write a native Node.js extension" /></a></p>
<p><a href="http://dailyjs.com/2010/11/01/node-tutorial/">Letâ€™s Make a Web App: Nodepad</a><br />
This series will walk you through building a Web app with Node.js, covering all of the major areas youâ€™ll face when building your own applications.</p>
<p class="showcase"><a href="http://dailyjs.com/2010/11/01/node-tutorial/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/015.jpg" width="502" height="259" alt="Letâ€™s Make a Web App: Nodepad" /></a></p>
<p><a href="http://wesbos.com/html5-canvas-websockets-nodejs/">HTML5 Canvas Drawing with Web Sockets, Node.JS and Socket.io</a><br />
Web sockets and canvas are two really cool features that are currently being implemented in browsers. This tutorial gives you a quick rundown of how they both work, and youâ€™ll create a real-time drawing canvas that is powered by Node.js and Web sockets.</p>
<p class="showcase"><a href="http://wesbos.com/html5-canvas-websockets-nodejs/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/040.jpg" width="502" height="302" alt="HTML5 Canvas Drawing with WebSockets, Node.JS &#038; Socket.io" /></a></p>
<p><a href="http://smus.com/multiplayer-html5-games-with-node">Developing Multiplayer HTML5 Games with Node.js</a><br />
Inspired by the famous iOS game Osmos, developer Boris Smus has created an alternative version of the game using HTML5 canvas and Node.js. This article explains the main phases of the project.</p>
<p class="showcase"><a href="http://smus.com/multiplayer-html5-games-with-node"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/045.jpg" width="502" height="296" alt="Developing Multiplayer HTML5 Games with Node.js" /></a></p>
<p><a href="http://blog.carbonfive.com/2011/09/01/deploying-node-js-on-amazon-ec2/">Deploying Node.js on Amazon EC2</a><br />
Amazonâ€™s EC2 is a popular choice for cloud applications. This tutorial shows how Node.js can be deployed on an EC2 instance.</p>
<p class="showcase"><a href="http://blog.carbonfive.com/2011/09/01/deploying-node-js-on-amazon-ec2/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/044.jpg" width="502" height="302" alt="Deploying node.js on Amazon EC2" /></a></p>
<p><a href="http://japhr.blogspot.com/2011/08/simple-nodejs-couchdb-calendar.html">A Simple Node.js + CouchDB Calendar</a><br />
In this tutorial by Chris Storm, you will learn how to build a Web calendar with Node.js and CouchDB.</p>
<p class="showcase"><a href="http://japhr.blogspot.com/2011/08/simple-nodejs-couchdb-calendar.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-036.jpg" width="500" height="300" alt="A Simple Node.js + CouchDB Calendar" /></a></p>
<p><a href="http://tomasz.janczuk.org/2011/08/hosting-nodejs-applications-in-iis-on.html">IIS7</a><br />
The IISnode project provides a native IIS 7.x module that enables hosting of Node.js applications on IIS. The project uses the Windows build of node.exe, which has recently seen major improvements.</p>
<p class="showcase"><a href="http://tomasz.janczuk.org/2011/08/hosting-nodejs-applications-in-iis-on.html"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-042.jpg" width="500" height="300" alt="Hosting node.js applications on IIS" /></a></p>
<p><a href="http://cykod.com/blog/post/2011-08-using-nodejs-and-your-phone-to-control-a-browser-game">Node.js + Phone to Control a Browser Game</a><br />
Someone wondered how easily a smart phone â€“ specifically using its gyroscopes and accelerometers â€“ could be used as a controller for a multi-player game on a larger screen. With a bit of Node.js and HTML5 magic, it turned out to be pretty simple.</p>
<p class="showcase"><a href="http://cykod.com/blog/post/2011-08-using-nodejs-and-your-phone-to-control-a-browser-game"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-049.jpg" width="500" height="300" alt="Node.js + Phone to Control a Browser Game" /></a></p>
<p><a href="http://stackoverflow.com/questions/1787716/is-there-a-template-engine-for-node-js">Is There a Template Engine for Node.js?</a><br />
An engaging discussion appeared on StackOverflow about the template engines that are available for Node.js. Really useful arguments came out of this discussion.</p>
<h3>Blogs, Podcasts, Resources On Node.js</h3>
<p><a href="http://howtonode.org/">How to Node</a><br />
How to Node is a community-supported blog created by Tim Caswell. Its purpose is to teach how to do various tasks in Node.js and the fundamental concepts needed to write effective code.</p>
<p class="showcase"><a href="http://howtonode.org/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-029.jpg" width="500" height="300" alt="How To Node" /></a></p>
<p><a href="http://blog.nodejitsu.com/">Nodejitsu</a><br />
A really interesting blog about scaling Node.js apps in the cloud and about the Node.js events in general.</p>
<p class="showcase"><a href="http://blog.nodejitsu.com/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-030.jpg" width="500" height="300" alt="Nodejitsu Blog" /></a></p>
<p><a href="http://nodeup.com/">Node Up</a><br />
A podcast that reviews Node.js, explains its philosophy and goes over many of its popular libraries.</p>
<p class="showcase"><a href="http://nodeup.com/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-031.jpg" width="500" height="300" alt="Node Up: Node.js Podcast" /></a></p>
<p><a href="http://nodetuts.com/">Node Tuts</a><br />
Free screencast tutorials.</p>
<p class="showcase"><a href="http://nodetuts.com/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-032.jpg" width="500" height="300" alt="Node Tuts - Node.js Free screencast tutorials" /></a></p>
<p><a href="http://node.minutewith.com/">Minute With Node.js</a><br />
Node.js is constantly changing and growing with each new version. New libraries and frameworks are coming out daily that allow you to write JavaScript for new and exciting projects that were previously impossible. This is a one-stop shop for news updates on the entire Node.js eco-system, with a heavy slant on hardcore nerdery.</p>
<p class="showcase"><a href="http://node.minutewith.com/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-034.jpg" width="500" height="300" alt="Minute With Node.js" /></a></p>
<p><a href="http://nodeguide.com/">Felixâ€™s Node.js Guide</a><br />
Over the past few months, Felix have given a lot of talks and done a lot of consulting on Node.js. He found himself repeating a lot of things over and over, so he used some of his recent vacation to start this opinionated and unofficial guide to help people getting started in Node.js.</p>
<p class="showcase"><a href="http://nodeguide.com/"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-033.jpg" width="500" height="300" alt="Felixâ€™s Node.js Guide" /></a></p>
<p><a href="http://nodeknockout.com/">Node.js Knockout</a><br />
Node.js Knockout is a 48-hour hackathon for Node.js. Itâ€™s an online virtual competition, with contestants worldwide.</p>
<p class="showcase"><a href="http://nodeknockout.com/"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-047.jpg" width="500" height="300" alt="Node.js Knockout" /></a></p>
<h3>References And Books</h3>
<p><a href="http://www.gosquared.com/liquidicity/archives/1930">Node.JS Help Sheet</a><br />
â€œNode.JS is an evented I/O framework for the V8 JavaScript engine. Itâ€™s ideal for writing scalable network programs, such as Web servers.  Weâ€™ve been working on some exciting things with Node.js, and we felt it was only fair to share our knowledge in the form of an easy-to-read Help Sheet.â€�</p>
<p class="showcase"><a href="http://www.gosquared.com/liquidicity/archives/1930"><img src="http://media.smashingmagazine.com/wp-content/uploads/2011/09/nodejs-009.jpg" width="500" height="300" alt="Node.JS Help Sheet" /></a></p>
<p><a href="http://nodebeginner.org/index.html">The Node Beginner Book</a><br />
The aim of this document is to get you started with developing applications for Node.js. It teaches you everything you need to know about advanced JavaScript along the way. It goes way beyond your typical â€œHello Worldâ€� tutorial.</p>
<p class="showcase"><a href="http://nodebeginner.org/index.html"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/006.jpg" width="502" height="296" alt="The Node Beginner Book" /></a></p>
<p><a href="http://ofps.oreilly.com/titles/9781449398583/index.html">Up and Running With Node.js</a><br />
â€œMany people use the JavaScript programming languages extensively for programming the interfaces of websites. Node.js allows this popular programming language to be applied in many more contexts, in particular on Web servers. There are several notable features about Node.js that make it worthy of interest.â€�</p>
<p class="showcase"><a href="http://ofps.oreilly.com/titles/9781449398583/index.html"><img src="http://coding.smashingmagazine.com/wp-content/uploads/2011/09/011.jpg" width="502" height="311" alt="Up and Running with Node.js" /></a></p>
<h3>Poll: Do You Use Node.js In Your Projects?</h3>
<p>How often have you used Node.js in your projects? Have you found some particular tools or articles useful? Share your experience in the comments to this post. Thank you.</p>
<p><!-- deleted script tag --><br />
<noscript><a href="http://polldaddy.com/poll/5508681/">Have you used Node.js in your projects?</a></noscript></p>
<h3>Related Posts</h3>
<p>You might be interested in the following related posts:</p>
<ul>
<li><a href="http://www.smashingmagazine.com/learning-javascript-essentials-guidelines-tutorials/">Learning JavaScript: Essentials And Tutorials</a>, by Smashing Magazine.</li>
<li><a href="http://www.smashingmagazine.com/back-end-server-administration-php-guidelines/">Back-End and Server Administration Guidelines</a>, by Smashing Magazine.</li>
</ul>
<p><em>(al)</em></p>
<hr />
<p><small>Â© Luca Degasperi for <a href="http://www.smashingmagazine.com">Smashing Magazine</a>, 2011.</small></p>]]></content:encoded>
			<wfw:commentRss>http://blogmyquery.com/index.php/2011/09/useful-node-js-tools-tutorials-and-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

