<?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>GravityBlast &#187; prototype</title>
	<atom:link href="http://gravityblast.com/category/prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://gravityblast.com</link>
	<description>...coding blast beat!</description>
	<lastBuildDate>Thu, 08 Apr 2010 08:12:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>2 things I like in prototype 1.6.1</title>
		<link>http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/</link>
		<comments>http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 13:11:02 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=132</guid>
		<description><![CDATA[
The stable version of prototype is  1.6.0.3. I just fiddled around with the edge version (1.6.1_rc2) and I found 2 new features I really like. The first one is the Element#clone method. At last I can easily clone an element,  or make a deep clone of it passing true as first argument:


&#60;div id=&#34;genres&#34;&#62;
 [...]]]></description>
			<content:encoded><![CDATA[<p>
The stable version of <a href="http://www.prototypejs.org/">prototype</a> is  1.6.0.3. I just fiddled around with the edge version (<a href="http://prototypejs.org/assets/2009/3/27/prototype.js">1.6.1_rc2</a>) and I found 2 new features I really like. The first one is the Element#clone method. At last I can easily clone an element,  or make a deep clone of it passing true as first argument:
</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;genres&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;genre&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;genre[]&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>Your favorite genre...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>Death Metal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>Black Metal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>Speed Metal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-genre&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Add<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dom:loaded&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;add-genre&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    event.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> genres <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;genres&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    genres.<span style="color: #660066;">insert</span><span style="color: #009900;">&#40;</span>genres.<span style="color: #660066;">down</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.genre&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Just click the <strong>Add</strong> link to add a new the select tag.</p>
<p>Another cool new feature is the <a href="http://prototypejs.org/2009/2/16/pimp-my-code-1-element-storage">Element Storage</a>. You can store any kind of data inside a element, and retrieve it when you need it.</p>
<p>Here an example:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;items&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-1&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Item 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;save&quot;</span>&gt;</span>Save<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;item-2&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Item 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;save&quot;</span>&gt;</span>Save<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dom:loaded&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;item-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  data.<span style="color: #660066;">url</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://cowboys.from.hell/items/1&quot;</span><span style="color: #339933;">;</span>			
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;items&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">select</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a.save&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">invoke</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;observe&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">target</span>.<span style="color: #660066;">up</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.item&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Just click the first <strong>save</strong> link and an alert will display the url I previously stored inside the first item element.</p>
<p>Given what I&#8217;m seeing I&#8217;m pretty excited about the upcoming version of prototype.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;submitHeadline=2+things+I+like+in+prototype+1.6.1&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=2+things+I+like+in+prototype+1.6.1&amp;url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;T=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;title=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+2+things+I+like+in+prototype+1.6.1+@+http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/&amp;t=2+things+I+like+in+prototype+1.6.1" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/03/31/2-things-i-like-in-prototype-161/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WillPaginate with ajax and unobtrusive js</title>
		<link>http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/</link>
		<comments>http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 16:43:44 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/</guid>
		<description><![CDATA[Every day I use will_paginate plugin to paginate list of records. Today I need to paginate with ajax, and googling I only found a patch for the plugin that adds some code inside the generated links. Thus I decided to write a few lines of javascript to generate the same behaviour:
var Pagination = {  [...]]]></description>
			<content:encoded><![CDATA[<p>Every day I use <a href="http://rock.errtheblog.com/will_paginate" title="will_paginate">will_paginate</a> plugin to paginate list of records. Today I need to paginate with ajax, and googling I only found a patch for the plugin that adds some code inside the generated links. Thus I decided to write a few lines of javascript to generate the same behaviour:</p>
<pre><code>var Pagination = {  

  initLinks: function() {
    $('container').select('div.pagination a').invoke('observe', 'click', Pagination.linkHandler);
  },

  linkHandler: function(event) {
    event.stop();
    new Ajax.Updater('container', event.element().getAttribute('href'),{
      method: 'get',
      onComplete: Pagination.initLinks
    });
  }

}

document.observe('dom:loaded', Pagination.initLinks);
</code></pre>
<p>Obviously the code it&#8217;s not optimized, it&#8217;s just an example, but it works. You only need create a list of records inside a div caled &#8216;container&#8217;, and that div will be update with the content loaded by the ajax request.</p>
<p><strong>[UPDATE] </strong>I like the <a href="http://www.prototypejs.org/" title="PrototypeJS">prototype</a> OO way to write js. So I wote the same thing with a class:</p>
<pre><code>var Pagination = Class.create({ 

  initialize: function() {
    this.options = Object.extend({
      container: 'container'
    }, arguments[0] || {});
    this.initLinks();
  },  

  initLinks: function() {
    $(this.options.container).select('div.pagination a').invoke('observe', 'click', this.linkHandler.bind(this));
  },  

  linkHandler: function(event) {
    event.stop();
    new Ajax.Updater('container', event.element().getAttribute('href'),{
      method: 'get',
      onComplete: this.initLinks.bind(this)
    });
  }

});

document.observe('dom:loaded', function() {
  new Pagination();
});</code></pre>
<p>The latest version is more customizable because the constructor could receive a list of options. For now it&#8217;s only one, you can specify the container that will be updated, but you could add more options like the name of the spinner to show during requests and so on.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;submitHeadline=WillPaginate+with+ajax+and+unobtrusive+js&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;title=WillPaginate+with+ajax+and+unobtrusive+js" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;title=WillPaginate+with+ajax+and+unobtrusive+js" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=WillPaginate+with+ajax+and+unobtrusive+js&amp;url=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;title=WillPaginate+with+ajax+and+unobtrusive+js" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;title=WillPaginate+with+ajax+and+unobtrusive+js" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;T=WillPaginate+with+ajax+and+unobtrusive+js" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;title=WillPaginate+with+ajax+and+unobtrusive+js" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;title=WillPaginate+with+ajax+and+unobtrusive+js" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;title=WillPaginate+with+ajax+and+unobtrusive+js" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+WillPaginate+with+ajax+and+unobtrusive+js+@+http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/&amp;t=WillPaginate+with+ajax+and+unobtrusive+js" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2008/03/25/will_paginate-with-ajax-and-unobtrusive-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
