<?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>Higgins for President &#187; dante</title>
	<atom:link href="http://higginsforpresident.net/author/dante/feed/" rel="self" type="application/rss+xml" />
	<link>http://higginsforpresident.net</link>
	<description>Rants, Raves, and Code: the Interwebs and beyond</description>
	<lastBuildDate>Sun, 17 Jan 2010 15:20:49 +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>140 Characters of awesome</title>
		<link>http://higginsforpresident.net/2009/12/140-characters-of-awesome/</link>
		<comments>http://higginsforpresident.net/2009/12/140-characters-of-awesome/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 11:26:05 +0000</pubDate>
		<dc:creator>dante</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[dojo]]></category>

		<guid isPermaLink="false">http://higginsforpresident.net/?p=38</guid>
		<description><![CDATA[A few days ago I tweeted a line of code and decided it was wonderful enough to warrant further explanation. While the code itself may have fit into 140 characters, the examples and use cases go on and on. Because of a few architectural decisions made by Dojo long ago, these 140 characters are powerful [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I <a href="http://twitter.com/phiggins/status/6235308045">tweeted</a> a line of code and decided it was wonderful enough to warrant further explanation. While the code itself may have fit into 140 characters, the examples and use cases go on and on. Because of a few architectural decisions made by Dojo long ago, these 140 characters are powerful and flexible as well as mindlessly simple to use.</p>
<p>One thing a <a href="http://api.dojotoolkit.org/jsdoc/1.3.2/dojo.NodeList">dojo.NodeList</a> does not have by default in Base (dojo.js) is a way to fetch and inject content into a node (or nodes). This isn't necessarily an oversight, there are <a href="http://dojocampus.org/content/2008/03/14/functional-ajax-with-dojo/">several ways</a> this can be accomplished. In fact it is so simple an operation with so many possible edge cases it may even not be <em>worth</em> implementing. Here I present to you my own take on this super simple concept, built by using standard Base (dojo.js) functionality. </p>
<p>The function will be called <code>grab()</code>. It will grab a url, and inject it into some nodes. Here is the first iteration of this idea:</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">extend</span><span style="color: #66cc66;">&#40;</span>dojo.<span style="color: #006600;">NodeList</span>, <span style="color: #66cc66;">&#123;</span>
	grab: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		dojo.<span style="color: #006600;">xhr</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;GET&quot;</span>, <span style="color: #66cc66;">&#123;</span> url:url <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
			.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>response<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">addContent</span><span style="color: #66cc66;">&#40;</span>response, <span style="color: #3366CC;">&quot;only&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>We're simply mixing a new function in <code>dojo.NodeList.prototype</code> via <code>dojo.extend</code>, giving all instances of a NodeList this method. The plugin calls "return this;" to allow further chaining. Ajax operations by default are asynchronous</p>
<p>We work with NodeLists via <code>dojo.query</code>, so to use this code now we simply query the dom and load some content via Ajax:</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">addOnLoad</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	dojo.<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#header&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">grab</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;header.html&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>That is all well and good and works brilliantly until you need to a) load non-html content b) issue an xhrPost instead of get or c) configure the xhr call in any way. No worries, with just a few more bytes we can add all of that functionality piggybacking on the behavior of <code>dojo.Deferred</code> and objects.</p>
<p>First, we'll add support for mixing in extra parameters into the object passed to the XHR call. Currently, we're only passing <code>{ url: url }</code>, giving the Ajax call an endpoint to fetch. <code>dojo.xhr</code> accepts a <strong>lot</strong> of options in this magic object, so allowing a developer/user to mix in their own custom information here is as simple as calling <code>dojo.mixin</code> with an optional parameter. mixin() is safe like this, in that if extraArgs is undefined or null nothing happens. The url:url aspect is still retained, and any args passed as extraArgs are overwritten into the call. </p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">extend</span><span style="color: #66cc66;">&#40;</span>dojo.<span style="color: #006600;">NodeList</span>, <span style="color: #66cc66;">&#123;</span>
	grab: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>url, extraArgs<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		dojo.<span style="color: #006600;">xhr</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;GET&quot;</span>, dojo.<span style="color: #006600;">mixin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span> url:url <span style="color: #66cc66;">&#125;</span>, extraArgs<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>response<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">addContent</span><span style="color: #66cc66;">&#40;</span>response, <span style="color: #3366CC;">&quot;only&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>This now allows us to mix extra items into the Ajax call like timeout, sync, error handlers and so on. Back to the nature of Ajax calls being asynchronous: if we issue a grab() call on some node, the next items in the chain will not apply to the new content until an undetermined point in the future. We can overcome this limitation by passing <code>{ sync:true }</code> to the Ajax call, making the operation synchronous and thus making the following chains not execute until <em>after</em> the transfer is complete.</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">addOnLoad</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	dojo.<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#content&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">grab</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;/article/12345&quot;</span>, <span style="color: #66cc66;">&#123;</span> sync: <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>
		.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;p.title&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">onclick</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">innerHTML</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>If we had omitted the <code>{ sync:true }</code> here, the find() call would be querying the dom of the node with id="content", though the content of <code>/article/12345</code> url would not yet be in the container. We don't <em>have</em> to use synchronous Ajax here, it is just a possibility. For instance, we could have connected the click handler to the #content NodeList and delegated from the bubble, or used plugd's <a href="http://code.google.com/p/plugd/source/browse/trunk/connectlive.js">connectLive</a> plugin to simple connect to "p.title" and delegated that way. </p>
<p>We can use the <code>extraArgs</code> in so many ways it's ridiculous. What if you wanted to know if the loading error'd out for some reason:</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#content&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">grab</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;/foo.html&quot;</span>, <span style="color: #66cc66;">&#123;</span>
	error: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		console.<span style="color: #006600;">warn</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;error fetching foo.html&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Or, more importantly, what if you wanted to load content other than plain HTML. Perhaps you have a JSON object to load in. This is entirely possible because of the way <code>dojo.Deferred</code> works. When we call addCallback() on the Deferred chain in the plugin we're really registering the <em>last</em> chain. Anything we mix in to the Ajax call directly is executed before the final callback which calls this.addContent(). The secret is: the return value from a previous callback is passed to the next callback in the chain. So if we register a <code>load:</code> callback in the extraArgs we are permitted a pre-processing step for whatever content comes in. We simply need to supply an alternate <code>handleAs</code> to tell Ajax to process as JSON, and the <code>load</code> callback to process the JSON and return HTML so <code>addContent</code> works.</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;ul &gt; li&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">grab</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;person.json&quot;</span>, <span style="color: #66cc66;">&#123;</span>
	handleAs:<span style="color: #3366CC;">&quot;json&quot;</span>,
	load: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #009900; font-style: italic;">// again, broken string for a broken wordpress highlight.</span>
		<span style="color: #000066; font-weight: bold;">return</span> dojo.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;&lt;&quot;</span> + <span style="color: #3366CC;">&quot;p&gt;{username} - {age} / {sex}&lt;/&quot;</span> + <span style="color: #3366CC;">&quot;p&gt;&quot;</span>, data<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>The [new in Dojo 1.4] function <code>dojo.replace</code> does simple template substitution. In the above example, data.username is substituted into {username}, and the full HTML is returned to the second callback for this Ajax call, then injected into the appropriate node(s). In version prior to Dojo 1.4 you can use dojo.string.replace to accomplish mostly the same goals (though the templating is done differently, ${username} would need to be substituted). Above will inject a paragraph into each of the matched list items with some data. If our data came back as an array, we could simply make up the list items as well.</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;ul#mainlist&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">grab</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;tweets.json&quot;</span>, <span style="color: #66cc66;">&#123;</span>
	handleAs:<span style="color: #3366CC;">&quot;json&quot;</span>,
	load:<span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> response = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
		dojo.<span style="color: #006600;">forEach</span><span style="color: #66cc66;">&#40;</span>data, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #009900; font-style: italic;">// string intentionally broken up because wordpress highlight breaks it.</span>
			response.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span>dojo.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;&lt;l&quot;</span> + <span style="color: #3366CC;">&quot;i&gt;&lt;&quot;</span> + <span style="color: #3366CC;">&quot;p&gt;{username} - {age}&lt;/&quot;</span> + <span style="color: #3366CC;">&quot;p&gt;&lt;/l&quot;</span> + <span style="color: #3366CC;">&quot;i&gt;&quot;</span>, data<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">return</span> response.<span style="color: #006600;">join</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Here we're building up a string of list-items to be injected into the unordered list with id="mainlist". When the full response is joined and returned, that value is processed by <code>addContent</code> and injected appropriately.</p>
<p>The last little piece of the puzzle is to assume you don't want to issue and xhrGet call. There are several HTTP verbs to use, each with their own purpose: PUT, DELETE, or POST come to mind. With a simple adjustment to the <code>grab</code> function we can allow the developer to optionally overwrite this as well:</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">extend</span><span style="color: #66cc66;">&#40;</span>dojo.<span style="color: #006600;">NodeList</span>, <span style="color: #66cc66;">&#123;</span>
	grab: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>url, extraArgs, method<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		dojo.<span style="color: #006600;">xhr</span><span style="color: #66cc66;">&#40;</span>method || <span style="color: #3366CC;">&quot;GET&quot;</span>, dojo.<span style="color: #006600;">mixin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span> url:url <span style="color: #66cc66;">&#125;</span>, extraArgs<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>response<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">addContent</span><span style="color: #66cc66;">&#40;</span>response, <span style="color: #3366CC;">&quot;only&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Now, if we pass a method parameter the default value of "GET" is ignored. Otherwise the defaults take over. Again utilizing the extraArgs "mixin", we can make an Ajax POST request and send along custom data:</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#login&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">grab</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;/user/login&quot;</span>, <span style="color: #66cc66;">&#123;</span>
	content:<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000066;">name</span>: dojo.<span style="color: #006600;">byId</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;username&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">value</span>,
		pass: dojo.<span style="color: #006600;">byId</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">value</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>, <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>One implementation detail I don't like about <code>grab</code> is the forced emptying of the target node. In the <code>addCallback</code> function where we call <code>addContent</code> with a parameter of "only" we are forcefully emptying out the nodes before injecting the new content. Unfortunately, this is the <em>only</em> behavior we've permitted here. It would be trivial to omit to "only" (and less bytes, too) and require the developer to call <code>empty()</code> manually before injecting new content if that behavior was desired. By default then we'd be adding the content "last", which is the default <code>addContent</code> position. Let's rework the <code>grab</code> function to handle this:</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">extend</span><span style="color: #66cc66;">&#40;</span>dojo.<span style="color: #006600;">NodeList</span>, <span style="color: #66cc66;">&#123;</span>
	grab: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>url, extraArgs, method<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		dojo.<span style="color: #006600;">xhr</span><span style="color: #66cc66;">&#40;</span>method || <span style="color: #3366CC;">&quot;GET&quot;</span>, dojo.<span style="color: #006600;">mixin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span> url:url <span style="color: #66cc66;">&#125;</span>, extraArgs<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>, <span style="color: #3366CC;">&quot;addContent&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>It got even smaller! the "(scope, method)" pattern used in <code>addCallback</code> above is found throughout Dojo, and is super handy. That function "pair" (this.addContent) will be passed whatever value is returned from the Ajax call still, in the first position. The difference is we are not permitted to pass a position (without lamba's in JavaScript). Now, to inject some content into a node <strong>and</strong> empty it we must do that manually:</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#foo&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">empty</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">grab</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;bar.html&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Without the <code>empty()</code>, "bar.html" content would be <em>appended</em> to the node rather than replace the content. I have yet to decide which behavior I like better. Opinions? I'll need to decide that before adding this functionality to Base Dojo proper. It currently lives in <a href="http://code.google.com/p/plugd/">plugd</a>, along with a slew of other new functionality for Dojo 1.4.</p>
<p>One last thing to do to <code>grab</code> function: there is no point in sending off the request if no nodes were found in the query. A simple check on the .length of the NodeList will prevent any unnecessary XHR calls from taking place:</p>
<pre class="javascript">&nbsp;
dojo.<span style="color: #006600;">extend</span><span style="color: #66cc66;">&#40;</span>dojo.<span style="color: #006600;">NodeList</span>, <span style="color: #66cc66;">&#123;</span>
	grab: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>url, extraArgs, method<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">length</span> &amp;&amp; dojo.<span style="color: #006600;">xhr</span><span style="color: #66cc66;">&#40;</span>method || <span style="color: #3366CC;">&quot;GET&quot;</span>, dojo.<span style="color: #006600;">mixin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span> url:url <span style="color: #66cc66;">&#125;</span>, extraArgs<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>, <span style="color: #3366CC;">&quot;addContent&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>And there you have it, 140 characters of awesome. (it may be a bit more with the longhand variables, pre-shrinkage. Also the inclusion of the extend call and so on add a few bytes, but in plugd's base.js these were already there for the other plugins provided, so is moot)</p>
]]></content:encoded>
			<wfw:commentRss>http://higginsforpresident.net/2009/12/140-characters-of-awesome/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Updates from Portland</title>
		<link>http://higginsforpresident.net/2008/07/updates-from-portland/</link>
		<comments>http://higginsforpresident.net/2008/07/updates-from-portland/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 06:11:39 +0000</pubDate>
		<dc:creator>dante</dc:creator>
				<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://higginsforpresident.net/?p=17</guid>
		<description><![CDATA[So it's a little late to be sending out updates of my stay in Portland, OR -- this is more or a 'reflections' of Portland blog writing -- but all valid none the less. It has been an exceptional adventure. 
I landed in Portland mid-afternoon last Sunday to a beautiful sunny day, typical of a [...]]]></description>
			<content:encoded><![CDATA[<p>So it's a little late to be sending out updates of my stay in Portland, OR -- this is more or a 'reflections' of Portland blog writing -- but all valid none the less. It has been an exceptional adventure. </p>
<p>I landed in Portland mid-afternoon last Sunday to a beautiful sunny day, typical of a Portland summer. The weather stayed consistently pleasant for the duration, which is not atypical, but entirely unexpected (and welcome). I love PDX in the summer. I must remind myself what the winters are like, lest I whimsically decide to rent an apartment and move back ...</p>
<p>I attended <a href="http://en.oreilly.com/oscon2008/public/content/home">OSCON</a> last week. I didn't spend much time in actual talks, but had a chance to sit and chat with a number of people I both had and hadn't met prior. Working for a virtual company, it is easy to detach yourself from face to face communications. I can go whole days without actually having to say a spoken word, though I've spent the entirety of it communicating with people from all regions of the world. I got a chance to hang out with some semi-familiar-faces: <a href="http://dylan.io">Dylan Schiemann</a> (my boss, and CEO SitePen, Inc) ended up on the west side, <a href="http://alex.dojotoolkit.org">Alex Russell</a> of Dojo fame, whose company is always welcome (the man has some weird special insight into them interwebs, and it is certainly entertaining to hear him rant), Matthew Russel, author of a relatively new [awesome] Dojo book: "<a href="http://oreilly.com/catalog/9780596516482/">The Difinitive Guide</a>", and several other Dojo-hackers and/or SitePen folk: <a href="http://blog.xdraw.org/">Gavin Dougtie</a> (Google), Jason Cline (SitePen), <a href="http://www.cb1inc.com/">Chris Barber</a> (CB1, Inc), <a href="http://freelock.com">John Locke</a> (Freelock) ... </p>
<p>... And more importantly, the meeting of great new folks: I had the pleasure of briefly meeting an energetic and charming Leslie Hawthorn of <a href="http://code.google.com/soc/2008/">Google Summer-of-Code</a> fame (I'm mentoring this year), a vocal and hilarious Zend Framework user Jason E, <a href="http://simonwillison.net/">Simon Willison</a>, a seemingly all-around great guy, the guys behind <a href="http://www.orbited.org/">Orbited</a>: Michael Carter, Jacob Rus, and Adrian Weisberg (who got an ad-hoc/realtime port of some trivial jQuery code into some Dojo Base functions, which I pulled off even after a long evening of dojo.beers and dinners ... which reminds me: I'd like to finish my port and replace the rest of the code if you'd like), as well as a number of random Dojo-enthusiasts from [unnamed] places I was surprised/unaware was using Dojo in the first place. The DDD:4.5-slash-dojo.dinner() was a great success: Random seemingly star-trek themed bar on East Burnisde provided a wonderful atmosphere to let loose and talk shop (among other things) with a bunch of faces old and new (over buffalo burgers no less). I've missed the beer in Portland.</p>
<p>It really gives you a jolt of pride when someone notices you wearing a Dojo t-shirt and takes the time to come over to talk about it, though it depresses me to see some of the really great applications written using Dojo, only to find out they are stashed away behind corporate firewalls, probably never to be seen or even mentioned publicly. It makes marketing more challenging, but at least <em>I</em> know, and am proud to continue on contributing to this phenomenal <em><a href="http://alex.dojotoolkit.org/?p=668">truly</a></em> Open Source project. </p>
<p>The most interesting talk I attended was <a href="http://stevesouders.com/">Steve Souders</a>' talk about optimizing pages ... it was fun to see at least half of the techniques suggested and investigated are already available in Dojo, and the rest seemed like they could be automated with our build system in one way or another. It seems like a lot of people know nothing about Dojo's tried-and-true package system and the transparency it provides between keeping code modular and optimization, development versus deployment, obfuscation versus human-readble code. All of the things non-Dojo-users do to speed their pages up are included out-of-the-box with Dojo: ShrinkSafe to minimize bytes on the wire by shrinking (safely) variables, removing comments and excessive whitespace, automatic concatenation of "layers" of modules in a very clean and safe manner ... We can even concat "modular CSS files", stripping comments, inline-ing <em>@import</em> calls and so on, anything to limit the overhead of initial page loading. I'm secretly amazed. It gets even better in 1.2, coming in just a bit: stubs loading (another of Steve's tips), <a href="http://www.sitepen.com/blog/2008/06/23/replacing-the-flash-flickr-badge-with-dojo/">post-onLoad</a> safe module loading might just be my new favorite thing since sliced bread.</p>
<p>I attended a django/python meetup, spending a good portion of the evening describing existing Dojo functionality, mostly when people made comments like "wouldn't it be cool is [my framework] did this?" -- "Oh, right Dojo has done that for a while now" ... I didn't hear about <a href="">dojango</a> until the next day, which is unfortunate, it would have been a perfect topic of conversation. I met <a href="http://ejohn.org">John Resig</a> briefly, though didn't talk as much shop as I'd have liked ...</p>
<p>For those of you wondering: No, I never found a shoe store that sells Birkenstocks, though officially retired the old pair after a seven-hour sea-kayak adventure. Don't kayak barefoot, at least the 17-foot sea-kayak variety. Lesson learned. I nearly destroyed my brother-in-law's brand new boat on it's maiden voyage on a river never intended to be run in a seventeen foot fiberglass tube. There was a reason the Mulhallah river wasn't in the "Flatwater guide of Oregon": The water isn't flat. Sea kayaks simply don't have the mobility a "normal" kayak has, and I'll be damned if I didn't run through one of the rapids only to get sucked into an eddy and bunched up against a sunken tree. I was fine for the most part, simply unable to fight the force of the rapids slowly rolling me (boat included) on end, and eventually over. I <em>almost</em> freed myself without damage or incident, but gave up when I heard the distinct noise of cracking fiberglass. Remember, the boat is seventeen feet long, and at the time of me removing the skirt, probably three-quarters submersed in the running water wedged against a tree. I was able to climb out (all the while holding on to said tree with one hand), roll the boat around and swim it downstream, handoff to my [extremely shaken] sister, swim further downstream and collect my own paddle and Nalgene bottle. Not only did I not lose any gear, I was still wearing my hat. Our peaceful, "zen-like" kayak adventure had instantly become exciting, despite the exceptionally painful bruises on both shins, and that ominous feeling of of sinking boat, which actually turned out to be true: I was taking on water until we beached for lunch and surveyed the damage: a small crack, large enough to seep water, and a six-inch scrape through the fiberglass on the underside. Bet you are glad you got that kevlar upgrade, huh, Bill? (Sorry about the boat. At least it's broken in now!). Tenacious tape is some amazing shit. </p>
<p>For the record, sea kayaking isn't my thing. The rapids part was fun, but atypical for this sport. The part the was supposed to be enjoyable was drowned by passing motorboats on the Willamette and an exceptionally hot sun. I, for the first time ever, have a very bad sunburn in the shape of a very nice Type III PFD. I'd rather do whitewater and/or "regular" kayaking. It didn't take long for me to answer my sister when she suggested we do this in Alaska ... Cold and Wet are my two least favorite sensations, especially when combined. </p>
<p>It was great to see all the old <a href="http://quivah.com">QuiVaH</a> folks again (who are seemingly no longer doing shows together). I think every last one of them is married now, most to people I knew, some to people I didn't, and Tae is still out being the talent-asian. RJ is still RJ, Q is still Q, just as fun and funny but with a better job, Haven is doing well for himself, and anxious to jump into some Dojo, which is great news in itself, Tae and Ran are living together near Goose Hollow (I actually ran into Ran [no pun intended] at the Django meet-up: he was dealing poker downstairs the whole evening), and they all really made my trip to PDX "complete" ... </p>
<p>Now I get all day tomorrow to decide if I want to miss my Tuesday-morning-flight and go apartment hunting ... decisions, decisions. Anyone up for dinner? Last chance to eat in this treasure-trove of excellent food offerings ... </p>
]]></content:encoded>
			<wfw:commentRss>http://higginsforpresident.net/2008/07/updates-from-portland/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
