<?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>catapult-creative.com &#187; jQuery</title>
	<atom:link href="http://www.catapult-creative.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.catapult-creative.com</link>
	<description>worldwide (web) whatnot</description>
	<lastBuildDate>Fri, 17 Jun 2011 00:45:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Moving to jQuery from RJS: Getting Started</title>
		<link>http://www.catapult-creative.com/2009/06/07/rocking-jquery-with-rails/</link>
		<comments>http://www.catapult-creative.com/2009/06/07/rocking-jquery-with-rails/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 18:07:28 +0000</pubDate>
		<dc:creator>Trevor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CodeDunce]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.catapult-creative.com/2009/06/07/rocking-jquery-with-rails/</guid>
		<description><![CDATA[Props to this guy&#8217;s post.  

Some parts are kind of confusing, but it&#8217;s a testatment to how much code he posts that I didn&#8217;t even realize he was French until I sat down to write this post and read it more carefully &#8212; he communicated mostly in code.

He gives a good Rails application.js file [...]]]></description>
			<content:encoded><![CDATA[<p>Props to <a href="http://www.notgeeklycorrect.com/english/2009/05/18/beginners-guide-to-jquery-ruby-on-rails/">this guy&#8217;s post</a>.  </p>

<p>Some parts are kind of confusing, but it&#8217;s a testatment to how much code he posts that I didn&#8217;t even realize he was French until I sat down to write this post and read it more carefully &#8212; he communicated mostly in code.</p>

<p>He gives a good <a href="http://gist.github.com/110410">Rails application.js file</a> for you to start out with &#8212; basically it provides a bunch of handles for things you want to remote w/ <span class="caps">XHR. </span> They use the new-ish <a href="http://docs.jquery.com/Events/unbind#typefn">jQuery method unbind</a> to make sure that regular events on items designated as <span class="caps">AJAX </span>get overriden.  Pretty slick and a good way to think of jQuery&#8217;s usage in an app context.  So far, I hadn&#8217;t really used it for <span class="caps">AJAX </span>beyond a thing I wrote to enable cross-domain MX record validation.</p>

<h3>Example: remote links</h3>

<p>Rails provides the <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001613">link_to_remote</a> helper to let you create links that will trigger a <span class="caps">GET </span>over <span class="caps">XHR. </span> This application.js defines a jQuery function for that and then binds it to a certain class of links &#8212; &#8220;get&#8221;:</p>

<div class="codecolorer-container javascript blackboard" style="overflow:auto;white-space:nowrap;width:620px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace">jQuery.<span class="me1">fn</span>.<span class="me1">getWithAjax</span> <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">unbind</span><span class="br0">&#40;</span><span class="st0">'click'</span><span class="sy0">,</span> <span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; $.<span class="me1">get</span><span class="br0">&#40;</span>$<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&quot;href&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">serialize</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="kw2">null</span><span class="sy0">,</span> <span class="st0">&quot;script&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span><span class="sy0">;</span><br />
&nbsp; <span class="br0">&#125;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>

<p>Which is then set with this:</p>

<div class="codecolorer-container javascript blackboard" style="overflow:auto;white-space:nowrap;width:620px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace">$<span class="br0">&#40;</span><span class="st0">'a.get'</span><span class="br0">&#41;</span>.<span class="me1">getWithAjax</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>

<p>Now any anchor with class &#8220;get&#8221; on it will result in a remote call to the <span class="caps">URL </span>in that anchor&#8217;s href.  Combined with a respond_to block in your controller to handle Javascript and a Javascript template file, you can use links like this to (for instance) load ActiveRecord objects into a page using <span class="caps">AJAX.</span> Instead of &#8220;show.erb.html&#8221; your controller&#8217;s show method is handled by &#8220;show.js.erb&#8221;.  This block in the show method of the controller ensures that it is activated correctly:</p>

<div class="codecolorer-container ruby blackboard" style="overflow:auto;white-space:nowrap;width:620px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="ruby codecolorer" style="font-family:Monaco,Lucida Console,monospace">respond_to <span class="kw1">do</span> <span class="sy0">|</span>format<span class="sy0">|</span><br />
&nbsp; <span class="kw3">format</span>.<span class="me1">html</span><br />
&nbsp; <span class="kw3">format</span>.<span class="me1">js</span> <span class="br0">&#123;</span> render <span class="re3">:layout</span> <span class="sy0">=&gt;</span> <span class="kw2">false</span> <span class="br0">&#125;</span><br />
<span class="kw1">end</span></div></td></tr></tbody></table></div>

<p>Because the call came in over <span class="caps">XHR, </span>the controller sees the format as being JS and responds with the instructions set in the block passed to format.js.  Rendering without layout ensures that nothing but the rendered data plus the template is returned.</p>

<p>Notice that the <span class="caps">AJAX </span>call in the above snippet from application.js uses the &#8220;script&#8221; datatype.  This specifies that the returned data should be evaluated as Javascript, which is what we want, because the returned data includes the jQuery-based instructions we have inside show.js.erb, and those need to get <em>evaluated</em> (not just displayed) in order for the page to look right.</p>

<p>An aside: One thing that this makes me think about a lot is how important visual design is when you&#8217;re developing an application.  Your design has to correspond concretely to a <span class="caps">DOM </span>with all sorts of manipulative handles (ids and classes) and all sorts of custom functions built to do various things to/with them.  You&#8217;d damn well better draw a decent picture of this and give the elements of it some good names that make sense.  In fact, I think a lot of the true work in programming involves drawing pictures (I still model some embarrassingly simple relationships with pencil and paper), but that might just be the way that my brain works.</p>

<p>Anywho, I took the above application.js and used it as the basis for a conversion from <span class="caps">RJS </span>to jQuery in a Rails app I&#8217;m working on.  I&#8217;ll probably end up adding quite a bit to his stuff as I go, but having this file around made starting the transition process a lot easier.</p>

<p>I expect to do some more posts on the conversion as I go, since I haven&#8217;t found a whole lot of stuff yet that&#8217;s oriented toward &#8220;strategies for using jQuery with Rails&#8221; and wasn&#8217;t written in 2007.  <span class="caps">RJS </span>kept me from dealing w/ JS directly as a major component of my app, but those days are over now that I&#8217;m committed to unobtrusive JS via jQuery, and a more thought-out approach will be necessary.</p>]]></content:encoded>
			<wfw:commentRss>http://www.catapult-creative.com/2009/06/07/rocking-jquery-with-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loving JQuery</title>
		<link>http://www.catapult-creative.com/2008/08/15/loving-jquery/</link>
		<comments>http://www.catapult-creative.com/2008/08/15/loving-jquery/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 14:58:00 +0000</pubDate>
		<dc:creator>Trevor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CodeDunce]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">tag:www.catapult-creative.com,2008-08-15:71</guid>
		<description><![CDATA[As someone involved with a decent amount of Rails programming over the past year, most of my work in Javascript frameworks has centered on Prototype and script.aculo.us.  And with good reason &#8212; both are enormously capable and, with Prototype at least, extremely well documented.  They create beautiful effects and nearly painless AJAX, they [...]]]></description>
			<content:encoded><![CDATA[<p>As someone involved with a decent amount of Rails programming over the past year, most of my work in Javascript frameworks has centered on <a href="http://www.prototypejs.org/" title="Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications">Prototype</a> and <a href="http://script.aculo.us/" title="script.aculo.us - web 2.0 javascript">script.aculo.us</a>.  And with good reason &#8212; both are enormously capable and, with Prototype at least, extremely well documented.  They create beautiful effects and nearly painless <span class="caps">AJAX, </span>they integrate really well with Rails, and there&#8217;s a wide community of users you can slot yourself right into.  I&#8217;ve used some other frameworks as well &#8212; made interfaces with <a href="http://extjs.com/" title="Ext - A foundation you can build on">ExtJS</a> and messed around with <a href="http://mochikit.com/" title="MochiKit - A lightweight Javascript library">MochiKit</a> some &#8212; and I&#8217;ve discovered that every one of these things (with the possible exception of MochiKit, which seems to be essentially abandonware at this point) has a specific niche to fill.  </p>

<p>But for the most part, what all these things have in common is that they seem to have been created with web application interface development in mind.  They&#8217;re not all that well suited to the set of one-off needs that crop up with general forms and lead generation tools on your average small site, but a lot of people end up using them for that anyway because they remove some of the tedium from <span class="caps">JS.</span> Numerous blog posts have been written about the phenomenon of people including the entirety of Prototype just to make tiny, &#8220;DHTML&#8221; DOM manipulation a little less painful, which makes no sense.  Just suck it up and use JS for real.  It&#8217;s not that hard.</p>

<p>There are some tasks that fall in between though &#8212; they&#8217;re more than trivial with bare JavaScript, but loading the entirety of a framework like Prototype is kind of like using a chainsaw to trim hedges.  It&#8217;ll work, but it will be heavy and imprecise, and you may find yourself regretting all the extra work later.  You still need a tool though, so what&#8217;s the solution?</p>

<p>A smaller, more task-oriented framework.  This week, I decided that I&#8217;m a fan of <a href="http://jquery.com/" title="jQuery: The Write Less, Do More, JavaScript Library">JQuery</a>.  Here are the two examples from this work week that sold me:</p>

<h4>Cycle</h4>
<p>The <a href="http://plugins.jquery.com/project/cycle" title="Cycle Plugin | jQuery Plugins">Cycle plugin</a> makes it dead simple to create a slideshow effect.</p>
<blockquote>
  <p>It supports pause-on-hover, auto-stop, auto-fit, before/after callbacks, click triggers and many transition effects including fade, shuffle, scroll, turn and zoom. It also allows you to define and run your own custom transitions. In addition, it supports, but does not require, the Metadata Plugin and the Easing Plugin.</p>
</blockquote>
<p>The basic way it works is that you put together a div filled with the objects you want to cycle, usually other divs containing, say, an image and a caption.  Once you&#8217;ve got your structure set up, you call cycle with one line, which it&#8217;s good to place at the bottom of your <span class="caps">HTML </span>so you&#8217;ll know all your pictures have loaded:</p>

<table class="CodeRay"><tr>
  <td title="click to toggle" class="line_numbers">

<pre>1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;</pre>

</td>
  <td class="code">

<pre>  &lt;span class=&quot;ta&quot;&gt;&amp;lt;script&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;text/javascript&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;charset&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    $('#mydiv').cycle();&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;ta&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;</pre>

</td>
</tr></table>

<p>You can add all kinds of options in the call to cycle, but the bare effect itself is pretty pleasing and is frequently exactly what a developer is looking for.</p>

<h4><span class="caps">UI.D</span>atepicker</h4>
<p><a href="http://docs.jquery.com/UI/Datepicker" title="UI/Datepicker - jQuery JavaScript Library"><span class="caps">UI.D</span>atepicker</a> is part of the <a href="http://ui.jquery.com/" title="jQuery UI - Home">JQuery UI library</a>.  You can think of UI as being script.aculo.us to JQuery&#8217;s Prototype &#8212; it&#8217;s built on top of the JQuery core and provides visual effects like fade, appear/disappear, window shade, shrink, grow, etc.  It also contains all the drag/drop-oriented stuff you might need, as well as several other &#8220;widgets&#8221; and interaction pieces.</p>

<p>Datepicker is a widget that provides a calendar.  When a user clicks on a form text field which has been tied to a Datepicker object, a calendar appears.  The user navigates the calendar and chooses a date, which is then inserted into the text field.  Again, the implementation code is short:</p>

<p>You could one-line this at the bottom of your page as well if you wanted (as with cycle above), but using JQuery&#8217;s <strong>$(document).ready()</strong> enables you to ensure that the code won&#8217;t try to execute before the page is loaded, so you can keep code you might use a bunch (like a standard calendar widget) outside your <span class="caps">HTML </span>file in a central spot.</p>

<table class="CodeRay"><tr>
  <td title="click to toggle" class="line_numbers">

<pre>1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;</pre>

</td>
  <td class="code">

<pre>  &lt;span class=&quot;ta&quot;&gt;&amp;lt;script&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;text/javascript&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;charset&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;   $(document).ready(function(){&lt;tt&gt;
&lt;/tt&gt;     $('#date').datepicker({dateFormat:'yy-mm-dd'});&lt;tt&gt;
&lt;/tt&gt;   });&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;ta&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;</pre>

</td>
</tr></table>


<p>One thing I love about the JQuery UI site: you get to <a href="http://ui.jquery.com/download_builder/" title="jQuery UI - Configure your download">build your own download</a> &#8212; i.e., you can select the pieces of code you need by feature and have the file built with <em>just that code</em>.  Among JavaScript frameworks, I believe this may be unique to JQuery, and it makes a serious difference in the file size.</p>

<p>I believe that this attitude &#8212; favoring modular code, giving you only what you need so you don&#8217;t end up with page bloat &#8212; probably drives a lot of JQuery&#8217;s adoption in smaller-need situations like the ones I&#8217;m describing here.  But JQuery is also the native JS framework for both <a href="http://drupal.org/" title="drupal.org | Community plumbing">Drupal</a> and <a href="http://wordpress.org/" title="WordPress &amp;#8250; Blog Tool and Publishing Platform">WordPress</a>.  I haven&#8217;t messed with <a href="http://mootools.net/" title="MooTools - home">MooTools</a> or <a href="http://dojotoolkit.org/" title="Home | The Dojo Toolkit">Dojo</a> yet, but I think of them as being in a similar class to JQuery, and I think JQuery definitely has the momentum to draw in more converts the same way I was: dead-simple use, only-what-you-need philosophy of code distribution, pervasive understanding of the bandwidth challengers front-end web developers face.</p>]]></content:encoded>
			<wfw:commentRss>http://www.catapult-creative.com/2008/08/15/loving-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

