<?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>scriptNode &#187; events</title>
	<atom:link href="http://scriptnode.com/tag/events/feed/" rel="self" type="application/rss+xml" />
	<link>http://scriptnode.com</link>
	<description>Tips and tricks for web developers.</description>
	<lastBuildDate>Tue, 01 Sep 2009 18:46:41 +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>A Seemingly Snappier User Interface</title>
		<link>http://scriptnode.com/article/a-seemingly-snappier-user-interface/</link>
		<comments>http://scriptnode.com/article/a-seemingly-snappier-user-interface/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 04:55:20 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=263</guid>
		<description><![CDATA[

Say you&#8217;ve got a fancy user interface. You&#8217;re leveraging AJAX well, you&#8217;re making good use of best practices, and you&#8217;ve got fast servers that respond quickly.
But your user actions still aren&#8217;t quite as fast as you&#8217;d like. What else can you do?


If you&#8217;ve done things correctly, you&#8217;ve got a user interface that reacts positively to [...]]]></description>
			<content:encoded><![CDATA[<p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script></p>
<p>
Say you&#8217;ve got a fancy user interface. You&#8217;re leveraging <a href="http://ajaxian.com">AJAX</a> well, you&#8217;re making good use of <a href="http://yuiblog.com/">best practices</a>, and you&#8217;ve got fast servers that <a href="/tag/optimization/">respond quickly</a>.<br />
But your user actions still aren&#8217;t quite as fast as you&#8217;d like. What else can you do?
</p>
<p>
If you&#8217;ve done things correctly, you&#8217;ve got a user interface that reacts positively to successful flows, but will also handle errors gracefully.<br />
Even though you&#8217;re &#8220;doing it right,&#8221; consider restructuring your application: <strong>assume success</strong>. Normally, your server is up and running and operations<br />
will be completely successfully. The edge case (hopefully) is the error case. Assuming this, we can create a slightly faster user interface.
</p>
<p>
Let&#8217;s begin with a basic voting mechanism. You&#8217;ve got a control on your page that lets a user vote on an object, and a small bit of text to represent the state of said control.<br />
It may look something like this:
</p>
<div class="section">
	<button>Vote</button><br />
	<span>You haven&#8217;t voted yet</span>
</div>
<p>
This example is meant to be easy and functional; hopefully <strong>your</strong> controls are prettier.<br />
Regardless, here&#8217;s a common flow for this request and its callback states:
</p>
<ol>
<li>Listen for the <code>click</code> event on the control.</li>
<li>Send the request.</li>
<li>Display a <a href="http://ajaxload.info/">&#8220;loading&#8221; message or a typical spinner image</a>.
<li>If the call comes back successfully, provide &#8220;success&#8221; feedback to the user and update the control.</li>
<li>If the call throws an error, provide an error message.</li>
</ol>
<p>
This flow is <strong>extremely</strong> common in today&#8217;s web. But we want something more immediately responsive, so let&#8217;s restructure the flow:
</p>
<ol>
<li>
		Use <code>onmousedown</code> because it will fire off just slightly sooner than <code>onclick</code> would.<br />
		(This might not suit all user interfaces but in this case it&#8217;s fine, and it wins us a few milliseconds.)
	</li>
<li>Provide &#8220;success&#8221; feedback to the user and update the control.</li>
<li>Send the request.</li>
<li>If the call throws an error, reset the controls and provide an error message.</li>
</ol>
<p>
This structure might seem a little off. Indeed, the error case even &#8220;lies&#8221; to the user for a few milliseconds if the request fails.<br />
But it covers all of its bases; none of the previous flow is omitted.<br />
Keep in mind that <strong>the error case is the edge case</strong>, and a very large majority of the time it&#8217;s fine to assume success at first.
</p>
<p>
Using <a href="http://jquery.com/">jQuery</a>, here&#8217;s what the code might look like:
</p>
<p><textarea class="javascript" cols="10" name="code" rows="10"><br />
// Attach the mousedown event listener<br />
$(&#8217;#snappier-1-btn&#8217;).mousedown(function(e) {</p>
<p>	var el = $(this);</p>
<p>	// Go ahead and assume things went smoothly<br />
	el.attr(&#8217;disabled&#8217;, true);<br />
	el.next().html(&#8217;Voted!&#8217;);</p>
<p>	// Send the XHR<br />
	$.ajax({<br />
		error : function() {</p>
<p>			// Undo the success message and allow the user to repeat<br />
			el.attr(&#8217;disabled&#8217;, false);<br />
			el.next().html(&#8221;You haven&#8217;t voted yet&#8221;);</p>
<p>			// Let the user know what happened<br />
			alert(&#8221;Sorry, an error occurred! Please try again.&#8221;);</p>
<p>		},<br />
		type : &#8216;GET&#8217;,<br />
		url : &#8216;/feed/&#8217;<br />
	});</p>
<p>});<br />
</textarea></p>
<p>
And here&#8217;s this flow working right here on the page:
</p>
<div class="section">
	<button id="snappier-1-btn">Vote</button><br />
	<span id="snappier-1-msg">You haven&#8217;t voted yet</span>
</div>
<p><script type="text/javascript"></p>
<p>// Attach the mousedown event listener
$('#snappier-1-btn').mousedown(function(e) {</p>
<p>	var el = $(this);</p>
<p>	// Go ahead and assume things went smoothly
	el.attr('disabled', true);
	el.next().html('Voted!');</p>
<p>	// Send the XHR
	$.ajax({
		error : function() {</p>
<p>			// Undo the success message and allow the user to repeat
			el.attr('disabled', false);
			el.next().html("You haven't voted yet");</p>
<p>			// Let the user know what happened
			alert("Sorry, an error occurred! Please try again.");</p>
<p>		},
		type : 'GET',
		url : '/feed/'
	});</p>
<p>});</p>
<p></script></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/a-seemingly-snappier-user-interface/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Upcoming Bay Area Events</title>
		<link>http://scriptnode.com/article/san-francisco-javascript-meetup-2/</link>
		<comments>http://scriptnode.com/article/san-francisco-javascript-meetup-2/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 20:00:11 +0000</pubDate>
		<dc:creator>Matt Hackett</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[links]]></category>

		<guid isPermaLink="false">http://scriptnode.com/?p=16</guid>
		<description><![CDATA[San Francisco JavaScript Meetup #3

If you&#8217;re in the bay area, check out The SF JavaScript Meetup #3, Monday, August 18th at 7:00PM. Last time, the infamous Douglas Crockford was there, so it&#8217;s sure to be a hoot! Here are the details:


As always, we will have plenty of awesome JavaScripters attending, a number of great talks [...]]]></description>
			<content:encoded><![CDATA[<h3>San Francisco JavaScript Meetup #3</h3>
<p>
If you&#8217;re in the bay area, check out <a href="http://javascript.meetup.com/4/calendar/8444425/">The SF JavaScript Meetup #3</a>, Monday, August 18th at 7:00PM. Last time, the infamous <a href="http://javascript.crockford.com/">Douglas Crockford</a> was there, so it&#8217;s sure to be a hoot! Here are the details:
</p>
<blockquote><p>
As always, we will have plenty of awesome JavaScripters attending, a number of great talks on cutting-edge scripting concepts, and excellent networking potential. Come and hang out with the best scripters in the Bay Area, learn a lot, eat free food, and have fun.
</p>
</blockquote>
<h3>The agenda</h3>
<ol>
<li>7:00PM &#8211; Event starts and food (&#8230;and lots of it!) will be ready for eating</li>
<li>7:20PM &#8211; A few words from our hosts, sponsors, and us</li>
<li>7:30PM &#8211; An hour of high-quality talks and demos (5&#215;12min)</li>
<li>8:30PM &#8211; Networking, talking, learning, discussing, more questions for speakers, more eating, whatever&#8230;</li>
<li>9:30PM &#8211; Start to wrap things up</li>
</ol>
<h3>The Address</h3>
<address>
580 Market Street, 6th Floor<br/><br />
San Francisco CA, 94104<br/><br />
</address>
<p>
<a href="http://richter.paletteswap.com">I&#8217;ll</a> be there, as will many of my <a href="http://fehrenbacher.com/">fellow</a> <a href="http://boldify.com/">front-end</a> <a href="http://foohack.com/">engineer</a> <a href="http://seldo.com/">buddies</a>.
</p>
<div id="y-map"></div>
<p><br/><!-- fail :( --></p>
<p><script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&amp;appid=DRwW0ojV34EtkDJlqEE75NnShbxh7e5j.5hukcQLXTe.KviHouC0PKs0lVDvo2M-"></script></p>
<p><script type="text/javascript">
(function() {
var map = new YMap(document.getElementById('y-map'));
map.addTypeControl();
map.addZoomLong();
map.addPanControl();
map.setMapType(YAHOO_MAP_REG);
map.drawZoomAndCenter("580 Market Street, 6th Floor, San Francisco CA, 94104", 4);
})();
</script></p>
<h3>Oh, and An Event Apart</h3>
<p>
Also (though I&#8217;m sure you&#8217;ve heard of this one), there&#8217;s <a href="http://aneventapart.com/">An Event Apart</a>: a two-day conference featuring <a href="http://www.ericmeyeroncss.com/">Eric Meyer</a> and <a href="http://www.zeldman.com/">Jeffrey Zeldman</a>, maintained by the good folks who run <a href="http://alistapart.com/">A List Apart</a>. This is another one I&#8217;m attending. Hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptnode.com/article/san-francisco-javascript-meetup-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
